spotbugs cleanups.

This commit is contained in:
Erik C. Thauvin 2019-04-20 05:20:42 -07:00
parent e5398d73ec
commit 7ff30c1ce8
16 changed files with 53 additions and 29 deletions

View file

@ -12,13 +12,19 @@
<Or>
<Bug pattern="PATH_TRAVERSAL_IN"/>
<Bug pattern="PATH_TRAVERSAL_OUT"/>
</Or>
<Confidence value="2"/>
</Match>
<Match>
<Class name="net.thauvin.erik.mobibot.Mobibot"/>
<Method name="main"/>
<Bug pattern="PATH_TRAVERSAL_OUT"/>
<Confidence value="1"/>
<Or>
<Class name="net.thauvin.erik.mobibot.Mobibot"/>
<Class name="net.thauvin.erik.mobibot.Pinboard"/>
<Class name="net.thauvin.erik.mobibot.FeedReader"/>
<Class name="net.thauvin.erik.mobibot.tell.Tell"/>
<Package name="net.thauvin.erik.mobibot.modules.*"/>
<Package name="net.thauvin.erik.mobibot.entries.*"/>
</Or>
<Bug pattern="FCCD_FIND_CLASS_CIRCULAR_DEPENDENCY"/>
</Match>
</FindBugsFilter>

View file

@ -33,7 +33,6 @@
package net.thauvin.erik.mobibot;
import com.rometools.rome.feed.synd.SyndEntry;
import com.rometools.rome.feed.synd.SyndEntryImpl;
import com.rometools.rome.feed.synd.SyndFeed;
import com.rometools.rome.io.SyndFeedInput;
import com.rometools.rome.io.XmlReader;
@ -87,10 +86,10 @@ class FeedReader implements Runnable {
final SyndFeed feed = input.build(new XmlReader(new URL(url)));
SyndEntry item;
final List items = feed.getEntries();
final List<SyndEntry> items = feed.getEntries();
for (int i = 0; (i < items.size()) && (i < MAX_ITEMS); i++) {
item = (SyndEntryImpl) items.get(i);
item = items.get(i);
bot.send(sender, item.getTitle());
bot.send(sender, TAB_INDENT + Utils.green(item.getLink()));
}

View file

@ -33,7 +33,7 @@ public final class TwitterOAuth {
*
* @param args The consumerKey and consumerSecret should be passed as arguments.
*/
@SuppressFBWarnings(value = "DM_DEFAULT_ENCODING")
@SuppressFBWarnings({"DM_DEFAULT_ENCODING", "IMC_IMMATURE_CLASS_PRINTSTACKTRACE"})
public static void main(final String[] args)
throws Exception {
if (args.length == 2) {

View file

@ -95,9 +95,9 @@ public final class Utils {
* @return The colorized string.
*/
static String colorize(final String s, final String color) {
if (!Utils.isValidString(color) || color.equals(Colors.NORMAL)) {
if (!Utils.isValidString(color) || Colors.NORMAL.equals(color)) {
return s;
} else if (color.equals(Colors.BOLD) || color.equals(Colors.REVERSE)) {
} else if (Colors.BOLD.equals(color) || Colors.REVERSE.equals(color)) {
return color + s + color;
}
@ -247,14 +247,12 @@ public final class Utils {
* @return The unescaped string.
*/
public static String unescapeXml(final String str) {
String s = str.replaceAll("&amp;", "&");
s = s.replaceAll("&lt;", "<");
s = s.replaceAll("&gt;", ">");
s = s.replaceAll("&quot;", "\"");
s = s.replaceAll("&apos;", "'");
s = s.replaceAll("&#39;", "'");
return s;
return str.replaceAll("&amp;", "&")
.replaceAll("&lt;", "<")
.replaceAll("&gt;", ">")
.replaceAll("&quot;", "\"")
.replaceAll("&apos;", "'")
.replaceAll("&#39;", "'");
}
/**

View file

@ -32,6 +32,7 @@
package net.thauvin.erik.mobibot.entries;
import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
import net.thauvin.erik.mobibot.Commands;
import net.thauvin.erik.mobibot.Constants;
import net.thauvin.erik.mobibot.Utils;
@ -84,6 +85,7 @@ public final class EntriesUtils {
* @param isView Set to true to display the number of comments.
* @return The entry's link.
*/
@SuppressFBWarnings(value = "CE_CLASS_ENVY", justification = "Yes, it does.")
public static String buildLink(final int index, final EntryLink entry, final boolean isView) {
final StringBuilder buff = new StringBuilder(Commands.LINK_CMD + (index + 1) + ": ");

View file

@ -34,6 +34,7 @@ package net.thauvin.erik.mobibot.entries;
import com.rometools.rome.feed.synd.SyndCategory;
import com.rometools.rome.feed.synd.SyndCategoryImpl;
import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
import java.io.Serializable;
import java.util.Calendar;
@ -291,6 +292,7 @@ public class EntryLink implements Serializable {
*
* @param tags The space-delimited tags.
*/
@SuppressFBWarnings(value = "STT_STRING_PARSING_A_FIELD")
public final void setTags(final String tags) {
if (tags != null) {
final String[] parts = tags.replaceAll(", ", " ").replaceAll(",", " ").split(" ");
@ -310,7 +312,7 @@ public class EntryLink implements Serializable {
if (mod == '-') {
// Don't remove the channel tag, if any.
if (!tag.getName().equals(channel.substring(1))) {
if (!channel.substring(1).equals(tag.getName())) {
this.tags.remove(tag);
}
} else if (mod == '+') {
@ -334,7 +336,7 @@ public class EntryLink implements Serializable {
*
* @param tags The tags.
*/
private void setTags(final List<SyndCategory> tags) {
final void setTags(final List<SyndCategory> tags) {
this.tags.addAll(tags);
}

View file

@ -130,7 +130,7 @@ public final class CurrencyConverter extends ThreadedModule {
final String[] cmds = query.split(" ");
if (cmds.length == 4) {
if (cmds[3].equals(cmds[1]) || cmds[0].equals("0")) {
if (cmds[3].equals(cmds[1]) || "0".equals(cmds[0])) {
return new ErrorMessage("You're kidding, right?");
} else {
try {
@ -153,7 +153,7 @@ public final class CurrencyConverter extends ThreadedModule {
"The supported currencies are: " + EXCHANGE_RATES.keySet().toString(), e);
}
}
} else if (query.equals(CURRENCY_RATES_KEYWORD)) {
} else if (CURRENCY_RATES_KEYWORD.equals(query)) {
final StringBuilder buff = new StringBuilder('[' + pubDate + "]: ");

View file

@ -107,7 +107,7 @@ public final class Joke extends ThreadedModule {
/**
* Returns a random joke from <a href="http://www.icndb.com/">The Internet Chuck Norris Database</a>.
*/
void run(final Mobibot bot, final String sender, String arg) {
void run(final Mobibot bot, final String sender, final String arg) {
try {
bot.send(Utils.cyan(randomJoke().getMessage()));
} catch (ModuleException e) {

View file

@ -178,7 +178,7 @@ public class Message {
*
* @param isPrivate The private flag.
*/
public void setPrivate(boolean isPrivate) {
public void setPrivate(final boolean isPrivate) {
this.isPrivate = isPrivate;
}
}

View file

@ -32,6 +32,7 @@
package net.thauvin.erik.mobibot.tell;
import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
import net.thauvin.erik.mobibot.Commands;
import net.thauvin.erik.mobibot.Mobibot;
import net.thauvin.erik.mobibot.Utils;
@ -100,7 +101,8 @@ public class Tell {
*
* @return <code>true</code> if the queue was cleaned.
*/
private boolean clean() {
@SuppressWarnings("WeakerAccess")
final boolean clean() {
if (bot.getLogger().isDebugEnabled()) {
bot.getLogger().debug("Cleaning the messages.");
}
@ -138,12 +140,13 @@ public class Tell {
* @param sender The sender's nick.
* @param cmds The commands string.
*/
@SuppressFBWarnings(value = "CC_CYCLOMATIC_COMPLEXITY", justification = "Working on it.")
public void response(final String sender, final String cmds) {
final String arrow = " --> ";
if (!Utils.isValidString(cmds)) {
helpResponse(sender);
} else if (cmds.startsWith(Commands.VIEW_CMD)) {
if (bot.isOp(sender) && cmds.equals(Commands.VIEW_CMD + ' ' + TELL_ALL_KEYWORD)) {
if (bot.isOp(sender) && (Commands.VIEW_CMD + ' ' + TELL_ALL_KEYWORD).equals(cmds)) {
if (!messages.isEmpty()) {
for (final TellMessage message : messages) {
bot.send(sender, Utils.bold(message.getSender()) + arrow + Utils.bold(message.getRecipient())
@ -201,7 +204,7 @@ public class Tell {
final String id = split[1];
boolean deleted = false;
if (id.equalsIgnoreCase(TELL_ALL_KEYWORD)) {
if (TELL_ALL_KEYWORD.equalsIgnoreCase(id)) {
for (final TellMessage message : messages) {
if (message.getSender().equalsIgnoreCase(sender) && message.isReceived()) {
messages.remove(message);
@ -272,7 +275,8 @@ public class Tell {
/**
* Saves the messages queue.
*/
private void save() {
@SuppressWarnings("WeakerAccess")
final void save() {
TellMessagesMgr.save(serializedObject, messages, bot.getLogger());
}

View file

@ -84,7 +84,7 @@ public class EntryLinkTest {
final List<SyndCategory> tags = entryLink.getTags();
int i = 0;
for (SyndCategory tag : tags) {
for (final SyndCategory tag : tags) {
assertThat(tag.getName()).as("tag.getName(" + i + ')').isEqualTo("tag" + (i + 1));
i++;
}

View file

@ -32,6 +32,8 @@
package net.thauvin.erik.mobibot.modules;
import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
import static org.assertj.core.api.Assertions.assertThat;
/**
@ -41,7 +43,9 @@ import static org.assertj.core.api.Assertions.assertThat;
* @created 2019-04-07
* @since 1.0
*/
final class AbstractModuleTest {
@SuppressFBWarnings("CE_CLASS_ENVY")
static void testAbstractModule(final AbstractModule module) {
final String name = module.getClass().getName();

View file

@ -32,6 +32,7 @@
package net.thauvin.erik.mobibot.modules;
import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
import net.thauvin.erik.mobibot.msg.Message;
import org.testng.annotations.Test;
@ -52,6 +53,7 @@ public class GoogleSearchTest extends LocalProperties {
AbstractModuleTest.testAbstractModule(new GoogleSearch());
}
@SuppressFBWarnings("LEST_LOST_EXCEPTION_STACK_TRACE")
@Test
public void testSearchGoogle() throws ModuleException {
final String apiKey = LocalProperties.getProperty(GoogleSearch.GOOGLE_API_KEY_PROP);

View file

@ -32,6 +32,7 @@
package net.thauvin.erik.mobibot.modules;
import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
import net.thauvin.erik.mobibot.msg.Message;
import org.testng.annotations.Test;
@ -46,7 +47,9 @@ import static org.assertj.core.api.Assertions.assertThat;
* @created 2019-04-07
* @since 1.0
*/
public class StockQuoteTest extends LocalProperties {
@SuppressFBWarnings("LEST_LOST_EXCEPTION_STACK_TRACE")
@Test
public void testGetQuote() throws ModuleException {
final String apiKey = LocalProperties.getProperty(StockQuote.ALPHAVANTAGE_API_KEY_PROP);

View file

@ -32,6 +32,7 @@
package net.thauvin.erik.mobibot.modules;
import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
import net.thauvin.erik.mobibot.Constants;
import org.testng.annotations.Test;
@ -48,6 +49,7 @@ import static org.assertj.core.api.Assertions.assertThat;
* @since 1.0
*/
public class TwitterTest {
@SuppressFBWarnings("MDM")
private String getCi() {
if ("true".equals(System.getenv("CIRCLECI"))) {
return "CircleCI";

View file

@ -32,6 +32,7 @@
package net.thauvin.erik.mobibot.modules;
import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
import net.thauvin.erik.mobibot.msg.Message;
import org.testng.annotations.Test;
@ -47,6 +48,7 @@ import static org.assertj.core.api.Assertions.assertThat;
* @since 1.0
*/
public class Weather2Test extends LocalProperties {
@SuppressFBWarnings("PRMC_POSSIBLY_REDUNDANT_METHOD_CALLS")
@Test
public void testWeather() throws ModuleException {
ArrayList<Message> messages = Weather2.getWeather("98204",