From 31f727e38c6e99943b1f4bfdb467a603b19c535e Mon Sep 17 00:00:00 2001 From: shayaantx Date: Tue, 16 Feb 2021 17:36:10 -0500 Subject: [PATCH] Fix NPE's trying to cache profiles & when there are no blacklisted paths --- src/main/java/com/botdarr/Config.java | 9 ++++++--- src/main/java/com/botdarr/api/AddStrategy.java | 4 ++-- src/main/java/com/botdarr/api/CacheProfileStrategy.java | 8 ++++++++ src/main/java/com/botdarr/commands/CommandProcessor.java | 2 +- .../java/com/botdarr/connections/ConnectionHelper.java | 2 +- src/main/resources/version.txt | 2 +- 6 files changed, 19 insertions(+), 8 deletions(-) diff --git a/src/main/java/com/botdarr/Config.java b/src/main/java/com/botdarr/Config.java index 3f3246a..2a7c72e 100644 --- a/src/main/java/com/botdarr/Config.java +++ b/src/main/java/com/botdarr/Config.java @@ -116,10 +116,13 @@ public static ChatClientType getChatClientType() { public static List getExistingItemBlacklistPaths() { String paths = getProperty(Constants.EXISTING_ITEMS_PATHS_BLACKLIST); - if (paths != null && paths.contains(",")) { - return Arrays.asList(paths.split(",")); + if (paths != null) { + if (paths.contains(",")) { + return Arrays.asList(paths.split(",")); + } + return new ArrayList() {{add(paths);}}; } - return new ArrayList() {{add(paths);}}; + return new ArrayList<>(); } public static final class Constants { diff --git a/src/main/java/com/botdarr/api/AddStrategy.java b/src/main/java/com/botdarr/api/AddStrategy.java index 2ac5ce0..ce563a2 100644 --- a/src/main/java/com/botdarr/api/AddStrategy.java +++ b/src/main/java/com/botdarr/api/AddStrategy.java @@ -44,7 +44,7 @@ public ChatClientResponse addWithSearchId(String searchText, String id) { } } return chatClientResponseBuilder.createErrorMessage("Could not find " + contentDisplayName + " with search text=" + searchText + " and id=" + id); - } catch (Exception e) { + } catch (Throwable e) { LOGGER.error("Error trying to add " + contentDisplayName, e); return chatClientResponseBuilder.createErrorMessage("Error adding content, e=" + e.getMessage()); } @@ -80,7 +80,7 @@ public List addWithSearchTitle(String searchText) { return Arrays.asList(chatClientResponseBuilder.createInfoMessage("No new " + contentDisplayName + "s found, check existing " + contentDisplayName + "s")); } return restOfItems; - } catch (Exception e) { + } catch (Throwable e) { LOGGER.error("Error trying to add " + contentDisplayName, e); return Arrays.asList(chatClientResponseBuilder.createErrorMessage("Error trying to add " + contentDisplayName + ", for search text=" + searchText + ", e=" + e.getMessage())); } diff --git a/src/main/java/com/botdarr/api/CacheProfileStrategy.java b/src/main/java/com/botdarr/api/CacheProfileStrategy.java index 8ce7134..f023362 100644 --- a/src/main/java/com/botdarr/api/CacheProfileStrategy.java +++ b/src/main/java/com/botdarr/api/CacheProfileStrategy.java @@ -1,5 +1,8 @@ package com.botdarr.api; +import org.apache.logging.log4j.LogManager; +import org.apache.logging.log4j.Logger; + import java.util.ArrayList; import java.util.List; @@ -11,10 +14,15 @@ public abstract class CacheProfileStrategy, X> { public void cacheData() { List profilesAddUpdated = new ArrayList<>(); List profiles = getProfiles(); + if (profiles == null) { + LOGGER.warn("Did not find any profiles available for caching, class=" + this.getClass().toString()); + return; + } for (Z profile : profiles) { addProfile(profile); profilesAddUpdated.add(profile.getKey()); } deleteFromCache(profilesAddUpdated); } + private static final Logger LOGGER = LogManager.getLogger(); } diff --git a/src/main/java/com/botdarr/commands/CommandProcessor.java b/src/main/java/com/botdarr/commands/CommandProcessor.java index 75cd3c2..f112aef 100644 --- a/src/main/java/com/botdarr/commands/CommandProcessor.java +++ b/src/main/java/com/botdarr/commands/CommandProcessor.java @@ -40,7 +40,7 @@ public CommandResponse processMess return new CommandResponse(chatClientResponseBuilder.createErrorMessage("Invalid command - type " + commandPrefix + "help for command usage")); } - } catch (Exception e) { + } catch (Throwable e) { LOGGER.error("Error trying to execute command " + strippedMessage, e); return new CommandResponse(chatClientResponseBuilder.createErrorMessage("Error trying to parse command " + strippedMessage + ", error=" + e.getMessage())); } diff --git a/src/main/java/com/botdarr/connections/ConnectionHelper.java b/src/main/java/com/botdarr/connections/ConnectionHelper.java index 38bdd8d..25d70fc 100644 --- a/src/main/java/com/botdarr/connections/ConnectionHelper.java +++ b/src/main/java/com/botdarr/connections/ConnectionHelper.java @@ -84,7 +84,7 @@ public List onFailure(int statusCode, String reason) { @Override public List onException(Exception e) { - return Arrays.asList(chatClientResponseBuilder.createErrorMessage("Requested failed with exception, e=" + e.getMessage())); + return Arrays.asList(chatClientResponseBuilder.createErrorMessage("Requested failed with exception, e=" + e.getMessage() + ",class=" + e.getClass())); } private ChatClientResponseBuilder chatClientResponseBuilder; } diff --git a/src/main/resources/version.txt b/src/main/resources/version.txt index 76e9e61..220d8e0 100644 --- a/src/main/resources/version.txt +++ b/src/main/resources/version.txt @@ -1 +1 @@ -5.1.4 +5.1.5