[infinispan-commits] Infinispan SVN: r770 - trunk/core/src/main/java/org/infinispan/marshall/jboss.

infinispan-commits at lists.jboss.org infinispan-commits at lists.jboss.org
Thu Sep 3 05:41:32 EDT 2009


Author: mircea.markus
Date: 2009-09-03 05:41:32 -0400 (Thu, 03 Sep 2009)
New Revision: 770

Modified:
   trunk/core/src/main/java/org/infinispan/marshall/jboss/ConstantObjectTable.java
Log:
findbugs:
 Exception is caught when Exception is not thrown
This method uses a try-catch block that catches Exception objects, but Exception is not thrown within the try block, and RuntimeException is not explicitly caught. It is a common bug pattern to say try { ... } catch (Exception e) { something } as a shorthand for catching a number of types of exception each of whose catch blocks is identical, but this construct also accidentally catches RuntimeException as well, masking potential bugs.

Modified: trunk/core/src/main/java/org/infinispan/marshall/jboss/ConstantObjectTable.java
===================================================================
--- trunk/core/src/main/java/org/infinispan/marshall/jboss/ConstantObjectTable.java	2009-09-03 09:28:00 UTC (rev 769)
+++ trunk/core/src/main/java/org/infinispan/marshall/jboss/ConstantObjectTable.java	2009-09-03 09:41:32 UTC (rev 770)
@@ -181,11 +181,15 @@
    public void start(RemoteCommandFactory cmdFactory, org.infinispan.marshall.Marshaller ispnMarshaller) {
       HashSet<Integer> ids = new HashSet<Integer>();
 
-      try {
          for (Map.Entry<String, String> entry : JDK_EXTERNALIZERS.entrySet()) {
             try {
                Class clazz = Util.loadClass(entry.getKey());
-               Externalizer ext = (Externalizer) Util.getInstance(entry.getValue());
+               Externalizer ext = null;
+               try {
+                  ext = (Externalizer) Util.getInstance(entry.getValue());
+               } catch (Exception e) {
+                  throw new CacheException("Could not instantiate entry: " + entry,e);
+               }
                Marshallable marshallable = ReflectionUtil.getAnnotation(ext.getClass(), Marshallable.class);
                int id = marshallable.id();
                ids.add(id);
@@ -204,7 +208,12 @@
                Marshallable marshallable = ReflectionUtil.getAnnotation(clazz, Marshallable.class);
                if (marshallable != null && !marshallable.externalizer().equals(Externalizer.class)) {
                   int id = marshallable.id();
-                  Externalizer ext = Util.getInstance(marshallable.externalizer());
+                  Externalizer ext = null;
+                  try {
+                     ext = Util.getInstance(marshallable.externalizer());
+                  } catch (Exception e) {
+                     throw new CacheException("Could not instantiate the externalizer: " + marshallable.externalizer(), e);
+                  }
                   if (!ids.add(id))
                      throw new CacheException("Duplicate id found! id=" + id + " in " + ext.getClass().getName() + " is shared by another marshallable class.");
                   if (ext instanceof ReplicableCommandExternalizer) {
@@ -223,9 +232,6 @@
                   log.debug("Unable to load class (ignore if class belonging to a module not in use): {0}", e.getMessage());
             }
          }
-      } catch (Exception e) {
-         throw new CacheException("Unable to instantiate Externalizer class", e);
-      }
    }
 
    public void stop() {



More information about the infinispan-commits mailing list