Repository: qpid-jms Updated Branches: refs/heads/master 12ca77c42 -> 51da0e5ac
Fix some issues found with findbugs Project: http://git-wip-us.apache.org/repos/asf/qpid-jms/repo Commit: http://git-wip-us.apache.org/repos/asf/qpid-jms/commit/90490f12 Tree: http://git-wip-us.apache.org/repos/asf/qpid-jms/tree/90490f12 Diff: http://git-wip-us.apache.org/repos/asf/qpid-jms/diff/90490f12 Branch: refs/heads/master Commit: 90490f12e0c84c52428ee55c2d99543c00702926 Parents: 12ca77c Author: Timothy Bish <[email protected]> Authored: Thu Oct 2 11:48:11 2014 -0400 Committer: Timothy Bish <[email protected]> Committed: Thu Oct 2 11:48:11 2014 -0400 ---------------------------------------------------------------------- .../org/apache/qpid/jms/util/FactoryFinder.java | 38 ++++++++++---------- 1 file changed, 18 insertions(+), 20 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/qpid-jms/blob/90490f12/qpid-jms-client/src/main/java/org/apache/qpid/jms/util/FactoryFinder.java ---------------------------------------------------------------------- diff --git a/qpid-jms-client/src/main/java/org/apache/qpid/jms/util/FactoryFinder.java b/qpid-jms-client/src/main/java/org/apache/qpid/jms/util/FactoryFinder.java index 8060027..baf9c27 100644 --- a/qpid-jms-client/src/main/java/org/apache/qpid/jms/util/FactoryFinder.java +++ b/qpid-jms-client/src/main/java/org/apache/qpid/jms/util/FactoryFinder.java @@ -113,14 +113,17 @@ public class FactoryFinder<T extends Object> { public T newInstance(String key) throws IllegalAccessException, InstantiationException, IOException, ClassNotFoundException, ClassCastException { T factory = cachedFactories.get(key); if (factory == null) { - Object found = objectFactory.create(path + key); - if (found != null && factoryType.isInstance(found)) { - factory = factoryType.cast(found); - cachedFactories.put(key, factory); + if (found != null) { + if (factoryType.isInstance(found)) { + factory = factoryType.cast(found); + cachedFactories.putIfAbsent(key, factory); + } else { + throw new ClassCastException("Cannot cast " + found.getClass().getName() + + " to " + factoryType.getName()); + } } else { - throw new ClassCastException("Cannot cast " + found.getClass().getName() + - " to " + factoryType.getName()); + throw new ClassNotFoundException("Could not locate factory for class: " + key); } } @@ -142,27 +145,29 @@ public class FactoryFinder<T extends Object> { /** * The default implementation of Object factory which works well in stand-alone applications. */ - @SuppressWarnings("rawtypes") protected static class StandaloneObjectFactory implements ObjectFactory { - final ConcurrentHashMap<String, Class> classMap = new ConcurrentHashMap<String, Class>(); + final ConcurrentHashMap<String, Class<?>> classMap = new ConcurrentHashMap<String, Class<?>>(); @Override public Object create(final String path) throws InstantiationException, IllegalAccessException, ClassNotFoundException, IOException { - Class clazz = classMap.get(path); + Class<?> clazz = classMap.get(path); if (clazz == null) { clazz = loadClass(loadProperties(path)); - classMap.put(path, clazz); + Class<?> previous = classMap.putIfAbsent(path, clazz); + if (previous != null) { + clazz = previous; + } } return clazz.newInstance(); } - static public Class loadClass(Properties properties) throws ClassNotFoundException, IOException { + static public Class<?> loadClass(Properties properties) throws ClassNotFoundException, IOException { String className = properties.getProperty("class"); if (className == null) { throw new IOException("Expected property is missing: class"); } - Class clazz = null; + Class<?> clazz = null; ClassLoader loader = Thread.currentThread().getContextClassLoader(); if (loader != null) { try { @@ -192,17 +197,10 @@ public class FactoryFinder<T extends Object> { } // lets load the file - BufferedInputStream reader = null; - try { - reader = new BufferedInputStream(in); + try (BufferedInputStream reader = new BufferedInputStream(in)) { Properties properties = new Properties(); properties.load(reader); return properties; - } finally { - try { - reader.close(); - } catch (Exception e) { - } } } } --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
