You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@abdera.apache.org by ro...@apache.org on 2006/08/22 02:14:06 UTC

svn commit: r433438 - /incubator/abdera/java/trunk/core/src/main/java/org/apache/abdera/util/ServiceUtil.java

Author: rooneg
Date: Mon Aug 21 17:14:05 2006
New Revision: 433438

URL: http://svn.apache.org/viewvc?rev=433438&view=rev
Log:
Fix some obscure problems noticed by FindBugs and IDEA.

* core/src/main/java/org/apache/abdera/util/ServiceUtil.java
  Import java.io.IOException.
  (locate, checkConfigProperties): Explicitly note that we're doing
   nothing in the catch blocks so IDEA will shut up.
  (checkMetaInfServices, _loadimpls): Close our input streams in the
   case of an exception, so we don't accidentally leak file handles.
   Also explicitly note that the empty catch blocks are desired.

Modified:
    incubator/abdera/java/trunk/core/src/main/java/org/apache/abdera/util/ServiceUtil.java

Modified: incubator/abdera/java/trunk/core/src/main/java/org/apache/abdera/util/ServiceUtil.java
URL: http://svn.apache.org/viewvc/incubator/abdera/java/trunk/core/src/main/java/org/apache/abdera/util/ServiceUtil.java?rev=433438&r1=433437&r2=433438&view=diff
==============================================================================
--- incubator/abdera/java/trunk/core/src/main/java/org/apache/abdera/util/ServiceUtil.java (original)
+++ incubator/abdera/java/trunk/core/src/main/java/org/apache/abdera/util/ServiceUtil.java Mon Aug 21 17:14:05 2006
@@ -20,6 +20,7 @@
 import java.io.BufferedReader;
 import java.io.InputStream;
 import java.io.InputStreamReader;
+import java.io.IOException;
 import java.net.URL;
 import java.util.ArrayList;
 import java.util.Enumeration;
@@ -76,7 +77,9 @@
     if (object == null && _default != null) {
       try {
         object = getClassLoader().loadClass(_default).newInstance();
-      } catch (Exception e) {}
+      } catch (Exception e) {
+        // Nothing
+      }
     }
     return object;
   }
@@ -92,7 +95,9 @@
     if (s != null) {
       try {
         object = getClassLoader().loadClass(s).newInstance();
-      } catch (Exception e) {}
+      } catch (Exception e) {
+        // Nothing
+      }
     } 
     return object;
   }
@@ -101,17 +106,28 @@
     Object object = null;
     String sid = "META-INF/services/" + id;
     ClassLoader loader = getClassLoader();
+    BufferedReader buf = null;
     try {
       InputStream is = loader.getResourceAsStream(sid);
       if (is != null) {
-        BufferedReader buf = new BufferedReader(new InputStreamReader(is));
+        buf = new BufferedReader(new InputStreamReader(is));
         String line = buf.readLine();
         if (line != null) {
           String s = line.split("#",2)[0].trim();
           object = loader.loadClass(s).newInstance();
         }
       }
-    } catch (Exception e) {}
+    } catch (Exception e) {
+      // Nothing
+    } finally {
+      if (buf != null) {
+        try {
+          buf.close();
+        } catch (IOException ioe) {
+          // Nothing
+        }
+      }
+    }
     return object;
   }
 
@@ -127,20 +143,18 @@
   
   @SuppressWarnings("unchecked")
   public static <T>List<T> _loadimpls(String sid) {
-    List<T> impls = null;
-    impls = new ArrayList<T>();
+    List<T> impls = new ArrayList<T>();
     ClassLoader loader = getClassLoader();
     try {
       Enumeration e = loader.getResources(sid);
       for (;e.hasMoreElements();) {
+        BufferedReader buf = null;
         try {
           URL url = (URL) e.nextElement();
           InputStream is = url.openStream();
           if (is != null) {
-            BufferedReader buf = 
-              new BufferedReader(
-                new InputStreamReader(is));
-            String line = null;
+            buf = new BufferedReader(new InputStreamReader(is));
+            String line;
             while ((line = buf.readLine()) != null) {
               String s = line.split("#",2)[0].trim();
               if (!"".equals(s)) { 
@@ -149,9 +163,21 @@
               }
             }
           }
-        } catch (Exception ex) {}
+        } catch (Exception ex) {
+          // Nothing
+        } finally {
+          if (buf != null) {
+            try {
+              buf.close();
+            } catch (IOException ioe) {
+              // Nothing
+            }
+          }
+        }
       }
-    } catch (Exception e) {}
+    } catch (Exception e) {
+      // Nothing
+    }
     
     return impls;
   }