diff options
author | beili.zhou <beili.zhou@amdocs.com> | 2017-08-29 18:33:57 -0400 |
---|---|---|
committer | Marcus Williams <marcus.williams@intel.com> | 2017-08-30 16:29:28 +0000 |
commit | a1194798f406efe32cb33510f1a9d58b0b5f9bd9 (patch) | |
tree | 21931fa9ba7e4023dd4d1998525e5529b944d209 /appc-common/src/main/java/org | |
parent | 9a1e7032fae218bd820dc06436a52173fbae7d6e (diff) |
Remove catch throwable and error
Fix the following sonar blocker issue:
- Catch Exception instead of Throwable
- Catch Exception instead of Error
Issue-Id: APPC-175
Change-Id: I16a1018001b067216740ec11e5a97e52d714db69
Signed-off-by: beili.zhou <beili.zhou@amdocs.com>
Diffstat (limited to 'appc-common/src/main/java/org')
-rw-r--r-- | appc-common/src/main/java/org/openecomp/appc/configuration/DefaultConfiguration.java | 136 | ||||
-rw-r--r-- | appc-common/src/main/java/org/openecomp/appc/pool/CachedElement.java | 32 |
2 files changed, 71 insertions, 97 deletions
diff --git a/appc-common/src/main/java/org/openecomp/appc/configuration/DefaultConfiguration.java b/appc-common/src/main/java/org/openecomp/appc/configuration/DefaultConfiguration.java index 9ec7dc09c..96d9be86c 100644 --- a/appc-common/src/main/java/org/openecomp/appc/configuration/DefaultConfiguration.java +++ b/appc-common/src/main/java/org/openecomp/appc/configuration/DefaultConfiguration.java @@ -25,7 +25,6 @@ package org.openecomp.appc.configuration; - import java.io.IOException; import java.io.InputStream; import java.net.URL; @@ -50,8 +49,8 @@ import org.slf4j.LoggerFactory; * This class provides the implementation of the <code>Configuration</code> interface. It is created by the * ConfigurationFactory and initialized with the configuration values for the process. * - * @since Mar 18, 2014 * @version $Id$ + * @since Mar 18, 2014 */ public final class DefaultConfiguration implements Configuration, Cloneable { @@ -66,6 +65,7 @@ public final class DefaultConfiguration implements Configuration, Cloneable { * Construct the configuration object. */ public DefaultConfiguration() { + // do nothing } /** @@ -92,8 +92,7 @@ public final class DefaultConfiguration implements Configuration, Cloneable { * Decrypts an encrypted value, if it is encrypted, and returns the clear text. Performs no operation on the string * if it is not encrypted. * - * @param value - * The value to (optionally) be decrypted + * @param value The value to (optionally) be decrypted * @return The clear text */ @SuppressWarnings("nls") @@ -102,17 +101,16 @@ public final class DefaultConfiguration implements Configuration, Cloneable { if (value.startsWith(EncryptionTool.ENCRYPTED_VALUE_PREFIX)) { try { return EncryptionTool.getInstance().decrypt(value); - } catch (Throwable e) { - String out = ""; + } catch (Exception e) { + StringBuilder out = new StringBuilder(); for (Provider p : Security.getProviders()) { for (Service s : p.getServices()) { String algo = s.getAlgorithm(); - out += - String.format("\n==Found Algorithm [ %s ] in provider [ %s ] and service [ %s ]", algo, - p.getName(), s.getClassName()); + out.append(String.format("\n==Found Algorithm [ %s ] in provider [ %s ] and service [ %s ]", + algo, p.getName(), s.getClassName())); } } - logger.debug(out); + logger.debug(out.toString()); logger.warn(String.format("Could not decrypt the configuration value [%s]", value), e); } } @@ -139,23 +137,20 @@ public final class DefaultConfiguration implements Configuration, Cloneable { @Override public boolean equals(Object obj) { - if( obj == null ) { + if (obj == null) { return false; } - if( this.getClass() != obj.getClass() ) { + if (this.getClass() != obj.getClass()) { return false; } DefaultConfiguration other = (DefaultConfiguration) obj; - if ((this.properties.size() == other.properties.size()) - && (this.properties.entrySet().containsAll(other.properties.entrySet())) - && (other.properties.entrySet().containsAll(this.properties.entrySet()))) { - return true; - } + return (this.properties.size() == other.properties.size()) + && (this.properties.entrySet().containsAll(other.properties.entrySet())) + && (other.properties.entrySet().containsAll(this.properties.entrySet())); - return false; } /** @@ -164,14 +159,13 @@ public final class DefaultConfiguration implements Configuration, Cloneable { * current configuration object, or system properties if undefined. If the value cannot be found, the variable is * removed and an empty string is used to replace the variable. * - * @param template - * The template to be expanded + * @param template The template to be expanded * @return The expanded template where each variable is replaced with its value */ @SuppressWarnings("nls") private String expandVariables(String template) { if (template == null) { - return template; + return null; } // Decrypt the template if needed @@ -201,24 +195,21 @@ public final class DefaultConfiguration implements Configuration, Cloneable { * This method is called to obtain a property expressed as a boolean value (true or false). The standard rules for * Boolean.parseBoolean() are used. * - * @param key - * The property key + * @param key The property key * @return The value of the property expressed as a boolean, or false if it does not exist. */ @SuppressWarnings("nls") @Override public boolean getBooleanProperty(String key) { - return Boolean.valueOf(getProperty(key, "false")).booleanValue(); + return Boolean.valueOf(getProperty(key, "false")); } /** * This method is called to obtain a property expressed as a boolean value (true or false). The standard rules for * Boolean.valueOf(String) are used. * - * @param key - * The property key - * @param defaultValue - * The default value to be returned if the property does not exist + * @param key The property key + * @param defaultValue The default value to be returned if the property does not exist * @return The value of the property expressed as a boolean, or false if it does not exist. * @see org.openecomp.appc.configuration.Configuration#getBooleanProperty(java.lang.String, boolean) */ @@ -233,8 +224,7 @@ public final class DefaultConfiguration implements Configuration, Cloneable { /** * Returns the indicated property value expressed as a floating point double-precision value (double). * - * @param key - * The property to retrieve + * @param key The property to retrieve * @return The value of the property, or 0.0 if not found * @see org.openecomp.appc.configuration.Configuration#getDoubleProperty(java.lang.String) */ @@ -242,7 +232,7 @@ public final class DefaultConfiguration implements Configuration, Cloneable { @Override public double getDoubleProperty(String key) { try { - return Double.valueOf(getProperty(key, "0.0")).doubleValue(); + return Double.valueOf(getProperty(key, "0.0")); } catch (NumberFormatException e) { return 0.0; } @@ -251,10 +241,8 @@ public final class DefaultConfiguration implements Configuration, Cloneable { /** * This method is called to obtain a property as a string value * - * @param key - * The key of the property - * @param defaultValue - * The default value to be returned if the property does not exist + * @param key The key of the property + * @param defaultValue The default value to be returned if the property does not exist * @return The string value, or null if it does not exist. * @see org.openecomp.appc.configuration.Configuration#getDoubleProperty(java.lang.String, double) */ @@ -270,9 +258,8 @@ public final class DefaultConfiguration implements Configuration, Cloneable { * Returns the property indicated expressed as an integer. The standard rules for * {@link Integer#parseInt(String, int)} using a radix of 10 are used. * - * @param key - * The property name to retrieve. - * @returns The value of the property, or 0 if it does not exist or is invalid. + * @param key The property name to retrieve. + * @return The value of the property, or 0 if it does not exist or is invalid. * @see org.openecomp.appc.configuration.Configuration#getIntegerProperty(java.lang.String) */ @SuppressWarnings("nls") @@ -289,10 +276,8 @@ public final class DefaultConfiguration implements Configuration, Cloneable { * Returns the property indicated expressed as an integer. The standard rules for Integer.parseInt(String, int) * using a radix of 10 are used. * - * @param key - * The property name to retrieve. - * @param defaultValue - * The default value to be returned if the property does not exist + * @param key The property name to retrieve. + * @param defaultValue The default value to be returned if the property does not exist * @return The value of the property, or 0 if it does not exist or is invalid. * @see org.openecomp.appc.configuration.Configuration#getIntegerProperty(java.lang.String, int) */ @@ -307,10 +292,9 @@ public final class DefaultConfiguration implements Configuration, Cloneable { /** * Returns the specified property as a long integer value, if it exists, or zero if it does not. * - * @param key - * The key of the property desired. + * @param key The key of the property desired. * @return The value of the property expressed as an integer long value, or zero if the property does not exist or - * is not a valid integer long. + * is not a valid integer long. * @see org.openecomp.appc.configuration.Configuration#getLongProperty(java.lang.String) */ @SuppressWarnings("nls") @@ -327,12 +311,10 @@ public final class DefaultConfiguration implements Configuration, Cloneable { * Returns the specified property as a long integer value, if it exists, or the default value if it does not exist * or is invalid. * - * @param key - * The key of the property desired. - * @param defaultValue - * the value to be returned if the property is not valid or does not exist. + * @param key The key of the property desired. + * @param defaultValue the value to be returned if the property is not valid or does not exist. * @return The value of the property expressed as an integer long value, or the default value if the property does - * not exist or is not a valid integer long. + * not exist or is not a valid integer long. * @see org.openecomp.appc.configuration.Configuration#getLongProperty(java.lang.String, long) */ @Override @@ -359,8 +341,7 @@ public final class DefaultConfiguration implements Configuration, Cloneable { /** * This method is called to obtain a property as a string value * - * @param key - * The key of the property + * @param key The key of the property * @return The string value, or null if it does not exist. */ @Override @@ -375,10 +356,8 @@ public final class DefaultConfiguration implements Configuration, Cloneable { /** * This method is called to obtain a property as a string value * - * @param key - * The key of the property - * @param defaultValue - * The default value to be returned if the property does not exist + * @param key The key of the property + * @param defaultValue The default value to be returned if the property does not exist * @return The string value, or null if it does not exist. * @see org.openecomp.appc.configuration.Configuration#getProperty(java.lang.String, java.lang.String) */ @@ -406,8 +385,7 @@ public final class DefaultConfiguration implements Configuration, Cloneable { /** * Returns true if the named property is defined, false otherwise. * - * @param key - * The key of the property we are interested in + * @param key The key of the property we are interested in * @return True if the property exists. */ @Override @@ -419,9 +397,8 @@ public final class DefaultConfiguration implements Configuration, Cloneable { * Returns an indication of the validity of the boolean property. A boolean property is considered to be valid only * if it has the value "true" or "false" (ignoring case). * - * @param key - * The property to be checked - * @returns True if the value is a boolean constant, or false if it does not exist or is not a correct string + * @param key The property to be checked + * @return True if the value is a boolean constant, or false if it does not exist or is not a correct string * @see org.openecomp.appc.configuration.Configuration#isValidBoolean(java.lang.String) */ @SuppressWarnings("nls") @@ -438,10 +415,9 @@ public final class DefaultConfiguration implements Configuration, Cloneable { /** * Returns an indication if the indicated property represents a valid double-precision floating point number. * - * @param key - * The property to be examined - * @returns True if the property is a valid representation of a double, or false if it does not exist or contains - * illegal characters. + * @param key The property to be examined + * @return True if the property is a valid representation of a double, or false if it does not exist or contains + * illegal characters. * @see org.openecomp.appc.configuration.Configuration#isValidDouble(java.lang.String) */ @Override @@ -461,10 +437,9 @@ public final class DefaultConfiguration implements Configuration, Cloneable { /** * Returns an indication if the property is a valid integer value or not. * - * @param key - * The key of the property to check - * @returns True if the value is a valid integer string, or false if it does not exist or contains illegal - * characters. + * @param key The key of the property to check + * @return True if the value is a valid integer string, or false if it does not exist or contains illegal + * characters. * @see org.openecomp.appc.configuration.Configuration#isValidInteger(java.lang.String) */ @Override @@ -484,10 +459,9 @@ public final class DefaultConfiguration implements Configuration, Cloneable { /** * Determines is the specified property exists and is a valid representation of an integer long value. * - * @param key - * The property to be checked + * @param key The property to be checked * @return True if the property is a valid representation of an integer long value, and false if it either does not - * exist or is not valid. + * exist or is not valid. * @see org.openecomp.appc.configuration.Configuration#isValidLong(java.lang.String) */ @Override @@ -507,8 +481,7 @@ public final class DefaultConfiguration implements Configuration, Cloneable { /** * This method allows an implementation to load configuration properties that may override default values. * - * @param is - * An input stream that contains the properties to be loaded + * @param is An input stream that contains the properties to be loaded */ public void setProperties(InputStream is) { try { @@ -521,9 +494,8 @@ public final class DefaultConfiguration implements Configuration, Cloneable { /** * This method allows an implementation to load configuration properties that may override default values. * - * @param props - * An optional Properties object to be merged into the configuration, replacing any same-named - * properties. + * @param props An optional Properties object to be merged into the configuration, replacing any same-named + * properties. * @see org.openecomp.appc.configuration.Configuration#setProperties(java.util.Properties) */ @Override @@ -537,10 +509,8 @@ public final class DefaultConfiguration implements Configuration, Cloneable { * application to adjust or add to the current configuration. If the property already exists, it is replaced with * the new value. * - * @param key - * The key of the property to be defined - * @param value - * The value of the property to be defined + * @param key The key of the property to be defined + * @param value The value of the property to be defined * @see org.openecomp.appc.configuration.Configuration#setProperty(java.lang.String, java.lang.String) */ @Override @@ -555,7 +525,7 @@ public final class DefaultConfiguration implements Configuration, Cloneable { @Override public String toString() { return String.format("Configuration: %d properties, keys:[%s]", properties.size(), properties.keySet() - .toString()); + .toString()); } /** @@ -566,7 +536,7 @@ public final class DefaultConfiguration implements Configuration, Cloneable { * @return The manifest object from the jar file, or null if the code is not packaged in a jar file. */ @SuppressWarnings({ - "unused", "nls" + "unused", "nls" }) private Manifest getManifest() { ProtectionDomain domain = getClass().getProtectionDomain(); diff --git a/appc-common/src/main/java/org/openecomp/appc/pool/CachedElement.java b/appc-common/src/main/java/org/openecomp/appc/pool/CachedElement.java index e5456114d..d2b3c0a9f 100644 --- a/appc-common/src/main/java/org/openecomp/appc/pool/CachedElement.java +++ b/appc-common/src/main/java/org/openecomp/appc/pool/CachedElement.java @@ -171,23 +171,27 @@ public class CachedElement<T extends Closeable> implements Closeable, Invocation "unchecked", "nls" }) @Override - public Object invoke(Object proxy, Method method, Object[] args) throws Throwable { + public Object invoke(Object proxy, Method method, Object[] args) throws Exception { Object result = null; - if (method.getName().equals("close")) { - if (released.compareAndSet(false, true)) { - if (!pool.isDrained()) { - pool.release((T) proxy); + switch (method.getName()) { + case "close": + if (released.compareAndSet(false, true)) { + if (!pool.isDrained()) { + pool.release((T) proxy); + } } - } - } else if (method.getName().equals("equals")) { - CacheManagement cm = (CacheManagement) proxy; - T other = (T) cm.getWrappedObject(); - result = element.equals(other); - } else if (method.getName().equals("getWrappedObject")) { - return element; - } else { - result = method.invoke(element, args); + break; + case "equals": + CacheManagement cm = (CacheManagement) proxy; + T other = (T) cm.getWrappedObject(); + result = element.equals(other); + break; + case "getWrappedObject": + return element; + default: + result = method.invoke(element, args); + break; } return result; |