From 274ac339ad00a658381dba60c725a64ec1a8cca0 Mon Sep 17 00:00:00 2001 From: Anthony Whitford Date: Thu, 8 Oct 2015 00:39:57 -0700 Subject: [PATCH 1/2] Corrected a few bugs in Settings. --- .../owasp/dependencycheck/utils/Settings.java | 29 +++---------------- 1 file changed, 4 insertions(+), 25 deletions(-) diff --git a/dependency-check-utils/src/main/java/org/owasp/dependencycheck/utils/Settings.java b/dependency-check-utils/src/main/java/org/owasp/dependencycheck/utils/Settings.java index 56e7033c0..e560ff9c5 100644 --- a/dependency-check-utils/src/main/java/org/owasp/dependencycheck/utils/Settings.java +++ b/dependency-check-utils/src/main/java/org/owasp/dependencycheck/utils/Settings.java @@ -460,12 +460,7 @@ public final class Settings { * @param value the value for the property */ public static void setBoolean(String key, boolean value) { - if (value) { - localSettings.get().props.setProperty(key, Boolean.TRUE.toString()); - } else { - localSettings.get().props.setProperty(key, Boolean.FALSE.toString()); - } - LOGGER.debug("Setting: {}='{}'", key, value); + setString(key, Boolean.toString(value)); } /** @@ -708,7 +703,7 @@ public final class Settings { try { value = Long.parseLong(Settings.getString(key)); } catch (NumberFormatException ex) { - throw new InvalidSettingException("Could not convert property '" + key + "' to an int.", ex); + throw new InvalidSettingException("Could not convert property '" + key + "' to a long.", ex); } return value; } @@ -723,13 +718,7 @@ public final class Settings { * @throws InvalidSettingException is thrown if there is an error retrieving the setting */ public static boolean getBoolean(String key) throws InvalidSettingException { - boolean value; - try { - value = Boolean.parseBoolean(Settings.getString(key)); - } catch (NumberFormatException ex) { - throw new InvalidSettingException("Could not convert property '" + key + "' to an int.", ex); - } - return value; + return Boolean.parseBoolean(Settings.getString(key)); } /** @@ -743,17 +732,7 @@ public final class Settings { * @throws InvalidSettingException is thrown if there is an error retrieving the setting */ public static boolean getBoolean(String key, boolean defaultValue) throws InvalidSettingException { - boolean value; - try { - final String strValue = Settings.getString(key); - if (strValue == null) { - return defaultValue; - } - value = Boolean.parseBoolean(strValue); - } catch (NumberFormatException ex) { - throw new InvalidSettingException("Could not convert property '" + key + "' to an int.", ex); - } - return value; + return Boolean.parseBoolean(Settings.getString(key, Boolean.toString(defaultValue))); } /** From f2a2a91682c93113f6c4c742d0109fb1ee6eecb8 Mon Sep 17 00:00:00 2001 From: Anthony Whitford Date: Thu, 8 Oct 2015 00:56:38 -0700 Subject: [PATCH 2/2] Slight simplification to standard getInt and getLong. --- .../java/org/owasp/dependencycheck/utils/Settings.java | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/dependency-check-utils/src/main/java/org/owasp/dependencycheck/utils/Settings.java b/dependency-check-utils/src/main/java/org/owasp/dependencycheck/utils/Settings.java index e560ff9c5..6e600d9db 100644 --- a/dependency-check-utils/src/main/java/org/owasp/dependencycheck/utils/Settings.java +++ b/dependency-check-utils/src/main/java/org/owasp/dependencycheck/utils/Settings.java @@ -659,13 +659,11 @@ public final class Settings { * @throws InvalidSettingException is thrown if there is an error retrieving the setting */ public static int getInt(String key) throws InvalidSettingException { - int value; try { - value = Integer.parseInt(Settings.getString(key)); + return Integer.parseInt(Settings.getString(key)); } catch (NumberFormatException ex) { throw new InvalidSettingException("Could not convert property '" + key + "' to an int.", ex); } - return value; } /** @@ -699,13 +697,11 @@ public final class Settings { * @throws InvalidSettingException is thrown if there is an error retrieving the setting */ public static long getLong(String key) throws InvalidSettingException { - long value; try { - value = Long.parseLong(Settings.getString(key)); + return Long.parseLong(Settings.getString(key)); } catch (NumberFormatException ex) { throw new InvalidSettingException("Could not convert property '" + key + "' to a long.", ex); } - return value; } /**