Spotbugs JDK 8 cleanups.

This commit is contained in:
Erik C. Thauvin 2019-04-20 06:24:53 -07:00
parent bae9c82ba8
commit 59626b1d94
6 changed files with 27 additions and 15 deletions

View file

@ -27,4 +27,10 @@
</Or> </Or>
<Bug pattern="FCCD_FIND_CLASS_CIRCULAR_DEPENDENCY"/> <Bug pattern="FCCD_FIND_CLASS_CIRCULAR_DEPENDENCY"/>
</Match> </Match>
<Match>
<Class name="net.thauvin.erik.mobibot.Mobibot"/>
<Method name="main"/>
<Bug pattern="PATH_TRAVERSAL_OUT"/>
<Confidence value="1"/>
</Match>
</FindBugsFilter> </FindBugsFilter>

View file

@ -241,7 +241,7 @@ public class Mobibot extends PircBot {
today = EntriesMgr.loadEntries(logsDir + EntriesMgr.CURRENT_XML, ircChannel, entries); today = EntriesMgr.loadEntries(logsDir + EntriesMgr.CURRENT_XML, ircChannel, entries);
if (logger.isDebugEnabled()) { if (logger.isDebugEnabled()) {
logger.debug("Last feed: " + today); logger.debug("Last feed: {}", today);
} }
if (!Utils.today().equals(today)) { if (!Utils.today().equals(today)) {
@ -831,7 +831,7 @@ public class Mobibot extends PircBot {
} }
} }
send(sender, "The following nicks are ignored: " + ignoredNicks.toString()); send(sender, "The following nicks are ignored: " + ignoredNicks);
} }
} }
@ -971,7 +971,7 @@ public class Mobibot extends PircBot {
final String hostname, final String hostname,
final String message) { final String message) {
if (logger.isDebugEnabled()) { if (logger.isDebugEnabled()) {
logger.debug(">>> " + sender + ": " + message); logger.debug(">>> {} : {}", sender, message);
} }
boolean isCommand = false; boolean isCommand = false;
@ -1276,7 +1276,7 @@ public class Mobibot extends PircBot {
final String hostname, final String hostname,
final String message) { final String message) {
if (logger.isDebugEnabled()) { if (logger.isDebugEnabled()) {
logger.debug(">>> " + sender + ": " + message); logger.debug(">>> {} : {}", sender, message);
} }
final String[] cmds = message.split(" ", 2); final String[] cmds = message.split(" ", 2);
@ -1443,13 +1443,13 @@ public class Mobibot extends PircBot {
if (Utils.isValidString(message) && Utils.isValidString(sender)) { if (Utils.isValidString(message) && Utils.isValidString(sender)) {
if (isPrivate) { if (isPrivate) {
if (logger.isDebugEnabled()) { if (logger.isDebugEnabled()) {
logger.debug("Sending message to " + sender + ": " + message); logger.debug("Sending message to {} : {}", sender, message);
} }
sendMessage(sender, message); sendMessage(sender, message);
} else { } else {
if (logger.isDebugEnabled()) { if (logger.isDebugEnabled()) {
logger.debug("Sending notice to " + sender + ": " + message); logger.debug("Sending notice to {} : {}", sender, message);
} }
sendNotice(sender, message); sendNotice(sender, message);

View file

@ -189,7 +189,7 @@ public final class EntriesMgr {
* @param history The history array. * @param history The history array.
* @param isDayBackup Set the true if the daily backup file should also be created. * @param isDayBackup Set the true if the daily backup file should also be created.
*/ */
@SuppressFBWarnings(value = "CE_CLASS_ENVY", justification = "Yes, it does.") @SuppressFBWarnings(value = {"CE_CLASS_ENVY", "CC_CYCLOMATIC_COMPLEXITY"}, justification = "Yes, it does.")
public static void saveEntries(final Mobibot bot, public static void saveEntries(final Mobibot bot,
final List<EntryLink> entries, final List<EntryLink> entries,
final List<String> history, final List<String> history,
@ -221,9 +221,15 @@ public final class EntriesMgr {
for (int i = (entries.size() - 1); i >= 0; --i) { for (int i = (entries.size() - 1); i >= 0; --i) {
entry = entries.get(i); entry = entries.get(i);
buff = new StringBuilder( buff = new StringBuilder()
"Posted by <b>" + entry.getNick() + "</b> on <a href=\"irc://" + bot.getIrcServer() + '/' .append("Posted by <b>")
+ entry.getChannel() + "\"><b>" + entry.getChannel() + "</b></a>"); .append(entry.getNick())
.append("</b> on <a href=\"irc://")
.append(bot.getIrcServer()).append('/')
.append(entry.getChannel())
.append("\"><b>")
.append(entry.getChannel())
.append("</b></a>");
if (entry.getCommentsCount() > 0) { if (entry.getCommentsCount() > 0) {
buff.append(" <br/><br/>"); buff.append(" <br/><br/>");

View file

@ -87,7 +87,7 @@ public final class EntriesUtils {
*/ */
@SuppressFBWarnings(value = "CE_CLASS_ENVY", justification = "Yes, it does.") @SuppressFBWarnings(value = "CE_CLASS_ENVY", justification = "Yes, it does.")
public static String buildLink(final int index, final EntryLink entry, final boolean isView) { public static String buildLink(final int index, final EntryLink entry, final boolean isView) {
final StringBuilder buff = new StringBuilder(Commands.LINK_CMD + (index + 1) + ": "); final StringBuilder buff = new StringBuilder().append(Commands.LINK_CMD).append(index + 1).append(": ");
buff.append('[').append(entry.getNick()).append(']'); buff.append('[').append(entry.getNick()).append(']');

View file

@ -150,12 +150,12 @@ public final class CurrencyConverter extends ThreadedModule {
+ cmds[3].toUpperCase()); + cmds[3].toUpperCase());
} catch (Exception e) { } catch (Exception e) {
throw new ModuleException("convertCurrency(" + query + ')', throw new ModuleException("convertCurrency(" + query + ')',
"The supported currencies are: " + EXCHANGE_RATES.keySet().toString(), e); "The supported currencies are: " + EXCHANGE_RATES.keySet(), e);
} }
} }
} else if (CURRENCY_RATES_KEYWORD.equals(query)) { } else if (CURRENCY_RATES_KEYWORD.equals(query)) {
final StringBuilder buff = new StringBuilder('[' + pubDate + "]: "); final StringBuilder buff = new StringBuilder().append('[').append(pubDate).append("]: ");
int i = 0; int i = 0;
for (final Map.Entry<String, String> rate : EXCHANGE_RATES.entrySet()) { for (final Map.Entry<String, String> rate : EXCHANGE_RATES.entrySet()) {
@ -169,7 +169,7 @@ public final class CurrencyConverter extends ThreadedModule {
return new NoticeMessage(buff.toString()); return new NoticeMessage(buff.toString());
} }
} }
return new ErrorMessage("The supported currencies are: " + EXCHANGE_RATES.keySet().toString()); return new ErrorMessage("The supported currencies are: " + EXCHANGE_RATES.keySet());
} }
/** /**

View file

@ -194,7 +194,7 @@ public final class WorldTime extends AbstractModule {
+ tz.substring(tz.indexOf('/') + 1).replace('_', ' '); + tz.substring(tz.indexOf('/') + 1).replace('_', ' ');
} }
} else { } else {
return new ErrorMessage("The supported countries/zones are: " + COUNTRIES_MAP.keySet().toString()); return new ErrorMessage("The supported countries/zones are: " + COUNTRIES_MAP.keySet());
} }
return new PublicMessage(response); return new PublicMessage(response);