diff --git a/config/pmd.xml b/config/pmd.xml
index 5cfeaf2..65fe3ec 100644
--- a/config/pmd.xml
+++ b/config/pmd.xml
@@ -5,22 +5,27 @@
xsi:schemaLocation="http://pmd.sourceforge.net/ruleset/2.0.0 https://pmd.sourceforge.io/ruleset_2_0_0.xsd">
Erik's Ruleset
-
+
-
+
-
+
+
+
+
+
-
-
+
@@ -41,7 +46,7 @@
-
+
@@ -84,7 +89,7 @@
-
+
@@ -108,6 +113,8 @@
+
+
@@ -117,7 +124,11 @@
-
+
+
+
+
+
@@ -150,7 +161,7 @@
-
+
@@ -162,7 +173,7 @@
-
+
@@ -240,7 +251,7 @@
-
+
diff --git a/src/main/java/net/thauvin/erik/mobibot/Mobibot.java b/src/main/java/net/thauvin/erik/mobibot/Mobibot.java
index 8c57234..a9a3d7a 100644
--- a/src/main/java/net/thauvin/erik/mobibot/Mobibot.java
+++ b/src/main/java/net/thauvin/erik/mobibot/Mobibot.java
@@ -710,11 +710,10 @@ public class Mobibot extends PircBot {
}
}
- final StringBuilder info = new StringBuilder(28).append("Uptime: ");
+ final StringBuilder info = new StringBuilder(28);
- info.append(Utils.uptime(ManagementFactory.getRuntimeMXBean().getUptime()));
-
- info.append("[Entries: ").append(entries.size());
+ info.append("Uptime: ").append(Utils.uptime(ManagementFactory.getRuntimeMXBean().getUptime())).append(
+ " [Entries: ").append(entries.size());
if (tell.isEnabled() && isOp(sender)) {
info.append(", Messages: ").append(tell.size());
@@ -769,7 +768,7 @@ public class Mobibot extends PircBot {
*/
@SuppressFBWarnings(
{"INFORMATION_EXPOSURE_THROUGH_AN_ERROR_MESSAGE", "DM_DEFAULT_ENCODING", "IOI_USE_OF_FILE_STREAM_CONSTRUCTORS"})
- @SuppressWarnings({"PMD.SystemPrintln", "PMD.AvoidFileStream"})
+ @SuppressWarnings({"PMD.SystemPrintln", "PMD.AvoidFileStream", "PMD.CloseResource"})
public static void main(final String[] args) {
// Setup the command line options
final Options options = new Options();
diff --git a/src/main/java/net/thauvin/erik/mobibot/Pinboard.java b/src/main/java/net/thauvin/erik/mobibot/Pinboard.java
index 175fdc4..b9f538d 100644
--- a/src/main/java/net/thauvin/erik/mobibot/Pinboard.java
+++ b/src/main/java/net/thauvin/erik/mobibot/Pinboard.java
@@ -45,7 +45,7 @@ import java.util.logging.Level;
import java.util.logging.Logger;
/**
- * The class to handle posts to pinbard.in.
+ * The class to handle posts to pinboard.in.
*
* @author Erik C. Thauvin
* @created 2017-05-17
@@ -81,14 +81,14 @@ class Pinboard {
* @param entry The entry to add.
*/
final void addPost(final EntryLink entry) {
- final SwingWorker worker = new SwingWorker() {
+ final SwingWorker worker = new SwingWorker<>() {
@Override
protected Boolean doInBackground() {
return pinboard.addPin(entry.getLink(),
- entry.getTitle(),
- postedBy(entry),
- entry.getPinboardTags(),
- formatDate(entry.getDate()));
+ entry.getTitle(),
+ postedBy(entry),
+ entry.getPinboardTags(),
+ formatDate(entry.getDate()));
}
};
@@ -103,7 +103,7 @@ class Pinboard {
final void deletePost(final EntryLink entry) {
final String link = entry.getLink();
- final SwingWorker worker = new SwingWorker() {
+ final SwingWorker worker = new SwingWorker<>() {
@Override
protected Boolean doInBackground() {
return pinboard.deletePin(link);
@@ -140,25 +140,25 @@ class Pinboard {
* @param entry The entry to add.
*/
final void updatePost(final String oldUrl, final EntryLink entry) {
- final SwingWorker worker = new SwingWorker() {
+ final SwingWorker worker = new SwingWorker<>() {
@Override
protected Boolean doInBackground() {
if (!oldUrl.equals(entry.getLink())) {
pinboard.deletePin(oldUrl);
return pinboard.addPin(entry.getLink(),
- entry.getTitle(),
- postedBy(entry),
- entry.getPinboardTags(),
- formatDate(entry.getDate()));
+ entry.getTitle(),
+ postedBy(entry),
+ entry.getPinboardTags(),
+ formatDate(entry.getDate()));
} else {
return pinboard.addPin(entry.getLink(),
- entry.getTitle(),
- postedBy(entry),
- entry.getPinboardTags(),
- formatDate(entry.getDate()),
- true,
- true);
+ entry.getTitle(),
+ postedBy(entry),
+ entry.getPinboardTags(),
+ formatDate(entry.getDate()),
+ true,
+ true);
}
}
};
diff --git a/src/main/java/net/thauvin/erik/mobibot/TwitterOAuth.java b/src/main/java/net/thauvin/erik/mobibot/TwitterOAuth.java
index 05b64d7..dc2f984 100644
--- a/src/main/java/net/thauvin/erik/mobibot/TwitterOAuth.java
+++ b/src/main/java/net/thauvin/erik/mobibot/TwitterOAuth.java
@@ -34,6 +34,8 @@ public final class TwitterOAuth {
* Twitter OAuth Client Registration.
*
* @param args The consumerKey and consumerSecret should be passed as arguments.
+ * @throws TwitterException If an error occurs.
+ * @throws IOException If an IO error occurs.
*/
@SuppressFBWarnings({"DM_DEFAULT_ENCODING", "IMC_IMMATURE_CLASS_PRINTSTACKTRACE"})
@SuppressWarnings({"PMD.AvoidPrintStackTrace", "PMD.SystemPrintln"})
@@ -43,29 +45,29 @@ public final class TwitterOAuth {
twitter.setOAuthConsumer(args[0], args[1]);
final RequestToken requestToken = twitter.getOAuthRequestToken();
AccessToken accessToken = null;
- final BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
- while (null == accessToken) {
- System.out.println("Open the following URL and grant access to your account:");
- System.out.println(requestToken.getAuthorizationURL());
- System.out.print("Enter the PIN (if available) or just hit enter.[PIN]:");
- final String pin = br.readLine();
- try {
- if (pin != null && pin.length() > 0) {
- accessToken = twitter.getOAuthAccessToken(requestToken, pin);
- } else {
- accessToken = twitter.getOAuthAccessToken();
- }
+ try (final BufferedReader br = new BufferedReader(new InputStreamReader(System.in))) {
+ while (null == accessToken) {
+ System.out.println("Open the following URL and grant access to your account:");
+ System.out.println(requestToken.getAuthorizationURL());
+ System.out.print("Enter the PIN (if available) or just hit enter.[PIN]:");
+ final String pin = br.readLine();
+ try {
+ if (pin != null && pin.length() > 0) {
+ accessToken = twitter.getOAuthAccessToken(requestToken, pin);
+ } else {
+ accessToken = twitter.getOAuthAccessToken();
+ }
- System.out.println(
- "Please add the following to the bot's property file:" + "\n\n" + "twitter-consumerKey="
+ System.out.println(
+ "Please add the following to the bot's property file:" + "\n\n" + "twitter-consumerKey="
+ args[0] + '\n' + "twitter-consumerSecret=" + args[1] + '\n' + "twitter-token="
- + accessToken.getToken() + '\n' + "twitter-tokenSecret=" + accessToken
- .getTokenSecret());
- } catch (TwitterException te) {
- if (401 == te.getStatusCode()) {
- System.out.println("Unable to get the access token.");
- } else {
- te.printStackTrace();
+ + accessToken.getToken() + '\n' + "twitter-tokenSecret=" + accessToken.getTokenSecret());
+ } catch (TwitterException te) {
+ if (401 == te.getStatusCode()) {
+ System.out.println("Unable to get the access token.");
+ } else {
+ te.printStackTrace();
+ }
}
}
}
diff --git a/src/main/java/net/thauvin/erik/mobibot/entries/EntryComment.java b/src/main/java/net/thauvin/erik/mobibot/entries/EntryComment.java
index 1dcf4eb..cc0b244 100644
--- a/src/main/java/net/thauvin/erik/mobibot/entries/EntryComment.java
+++ b/src/main/java/net/thauvin/erik/mobibot/entries/EntryComment.java
@@ -42,6 +42,7 @@ import java.time.LocalDateTime;
* @created Jan 31, 2004
* @since 1.0
*/
+@SuppressWarnings({"PMD.DataClass"})
public class EntryComment implements Serializable {
// The serial version UID.
static final long serialVersionUID = 1L;
diff --git a/src/main/java/net/thauvin/erik/mobibot/modules/Joke.java b/src/main/java/net/thauvin/erik/mobibot/modules/Joke.java
index b1b826a..4c4c1ad 100644
--- a/src/main/java/net/thauvin/erik/mobibot/modules/Joke.java
+++ b/src/main/java/net/thauvin/erik/mobibot/modules/Joke.java
@@ -87,7 +87,6 @@ public final class Joke extends ThreadedModule {
final JSONObject json = new JSONObject(sb.toString());
- //noinspection RegExpRedundantEscape
return new PublicMessage(
json.getJSONObject("value").get("joke").toString().replace("\\'", "'")
.replace("\\\"", "\""));
diff --git a/src/main/java/net/thauvin/erik/mobibot/modules/StockQuote.java b/src/main/java/net/thauvin/erik/mobibot/modules/StockQuote.java
index 0b0fc79..d9cc1c6 100644
--- a/src/main/java/net/thauvin/erik/mobibot/modules/StockQuote.java
+++ b/src/main/java/net/thauvin/erik/mobibot/modules/StockQuote.java
@@ -132,6 +132,7 @@ public final class StockQuote extends ThreadedModule {
* @return The {@link Message} array containing the stock quote.
* @throws ModuleException If an errors occurs.
*/
+ @SuppressWarnings({"PMD.CloseResource"})
static List getQuote(final String symbol, final String apiKey) throws ModuleException {
if (StringUtils.isBlank(apiKey)) {
throw new ModuleException(StringUtils.capitalize(STOCK_CMD) + " is disabled. The API key is missing.");
diff --git a/src/main/java/net/thauvin/erik/mobibot/msg/Message.java b/src/main/java/net/thauvin/erik/mobibot/msg/Message.java
index 290d3c9..9ee7af2 100644
--- a/src/main/java/net/thauvin/erik/mobibot/msg/Message.java
+++ b/src/main/java/net/thauvin/erik/mobibot/msg/Message.java
@@ -63,6 +63,7 @@ public class Message {
* @param isError The error flag.
* @param isPrivate The Private message
*/
+ @SuppressWarnings("unused")
public Message(final String message, final boolean isNotice, final boolean isError, final boolean isPrivate) {
msg = message;
this.isNotice = isNotice;
@@ -80,6 +81,7 @@ public class Message {
* @param isPrivate The Private message
* @param color The color.
*/
+ @SuppressWarnings("unused")
public Message(final String message,
final boolean isNotice,
final boolean isError,
@@ -178,6 +180,7 @@ public class Message {
*
* @param isPrivate The private flag.
*/
+ @SuppressWarnings("unused")
public void setPrivate(final boolean isPrivate) {
this.isPrivate = isPrivate;
}
diff --git a/src/test/java/net/thauvin/erik/mobibot/modules/Weather2Test.java b/src/test/java/net/thauvin/erik/mobibot/modules/Weather2Test.java
index bfc80eb..f39c459 100644
--- a/src/test/java/net/thauvin/erik/mobibot/modules/Weather2Test.java
+++ b/src/test/java/net/thauvin/erik/mobibot/modules/Weather2Test.java
@@ -59,7 +59,7 @@ public class Weather2Test extends LocalProperties {
messages = Weather2.getWeather("London, UK", LocalProperties.getProperty(Weather2.OWM_API_KEY_PROP));
assertThat(messages.get(0).getMessage()).as("is UK").contains("London").contains("UK");
- assertThat(messages.get(messages.size() - 1).getMessage()).as("is City Code").endsWith("4298960");
+ assertThat(messages.get(messages.size() - 1).getMessage()).as("is City Code").endsWith("4517009");
assertThatThrownBy(
() -> Weather2.getWeather("Montpellier, FR", LocalProperties.getProperty(Weather2.OWM_API_KEY_PROP))).as(