geronimo-scm mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jsis...@apache.org
Subject svn commit: r407433 - in /geronimo/branches/1.1/modules/system/src: java/org/apache/geronimo/system/configuration/ java/org/apache/geronimo/system/main/ java/org/apache/geronimo/system/util/ test/org/apache/geronimo/system/rmi/
Date Thu, 18 May 2006 02:10:59 GMT
Author: jsisson
Date: Wed May 17 19:10:58 2006
New Revision: 407433

URL: http://svn.apache.org/viewvc?rev=407433&view=rev
Log:
GERONIMO-2035 [system] ensure input and output streams are closed in finally blocks

Modified:
    geronimo/branches/1.1/modules/system/src/java/org/apache/geronimo/system/configuration/ConfigurationStoreUtil.java
    geronimo/branches/1.1/modules/system/src/java/org/apache/geronimo/system/configuration/LocalAttributeManager.java
    geronimo/branches/1.1/modules/system/src/java/org/apache/geronimo/system/main/CommandLine.java
    geronimo/branches/1.1/modules/system/src/java/org/apache/geronimo/system/main/Daemon.java
    geronimo/branches/1.1/modules/system/src/java/org/apache/geronimo/system/util/PluginRepositoryExporter.java
    geronimo/branches/1.1/modules/system/src/test/org/apache/geronimo/system/rmi/RMIClassLoaderSpiImplTest.java

Modified: geronimo/branches/1.1/modules/system/src/java/org/apache/geronimo/system/configuration/ConfigurationStoreUtil.java
URL: http://svn.apache.org/viewvc/geronimo/branches/1.1/modules/system/src/java/org/apache/geronimo/system/configuration/ConfigurationStoreUtil.java?rev=407433&r1=407432&r2=407433&view=diff
==============================================================================
--- geronimo/branches/1.1/modules/system/src/java/org/apache/geronimo/system/configuration/ConfigurationStoreUtil.java
(original)
+++ geronimo/branches/1.1/modules/system/src/java/org/apache/geronimo/system/configuration/ConfigurationStoreUtil.java
Wed May 17 19:10:58 2006
@@ -134,9 +134,11 @@
     }
 
     private static String calculateChecksum(File file, String algorithm) throws NoSuchAlgorithmException,
IOException {
-        InputStream stream = new FileInputStream(file);
 
+        InputStream stream = null;
         try {
+            stream = new FileInputStream(file);
+            
             MessageDigest digester = MessageDigest.getInstance(algorithm);
             digester.reset();
 
@@ -151,7 +153,8 @@
             return actualChecksum;
         } finally {
             try {
-                stream.close();
+                if (stream != null)
+                    stream.close();
             } catch (IOException ignored) {
             }
         }

Modified: geronimo/branches/1.1/modules/system/src/java/org/apache/geronimo/system/configuration/LocalAttributeManager.java
URL: http://svn.apache.org/viewvc/geronimo/branches/1.1/modules/system/src/java/org/apache/geronimo/system/configuration/LocalAttributeManager.java?rev=407433&r1=407432&r2=407433&view=diff
==============================================================================
--- geronimo/branches/1.1/modules/system/src/java/org/apache/geronimo/system/configuration/LocalAttributeManager.java
(original)
+++ geronimo/branches/1.1/modules/system/src/java/org/apache/geronimo/system/configuration/LocalAttributeManager.java
Wed May 17 19:10:58 2006
@@ -331,7 +331,8 @@
         if (!attributeFile.exists()) {
             return;
         }
-        InputSource in = new InputSource(new FileInputStream(attributeFile));
+        FileInputStream fis = new FileInputStream(attributeFile);
+        InputSource in = new InputSource(fis);
         DocumentBuilderFactory dfactory = DocumentBuilderFactory.newInstance();
         try {
             Document doc = dfactory.newDocumentBuilder().parse(in);
@@ -343,6 +344,9 @@
             log.error("Unable to read saved manageable attributes", e);
         } catch (InvalidGBeanException e) {
             log.error("Unable to read saved manageable attributes", e);
+        } finally {
+            if (fis != null)
+                fis.close();
         }
     }
 

Modified: geronimo/branches/1.1/modules/system/src/java/org/apache/geronimo/system/main/CommandLine.java
URL: http://svn.apache.org/viewvc/geronimo/branches/1.1/modules/system/src/java/org/apache/geronimo/system/main/CommandLine.java?rev=407433&r1=407432&r2=407433&view=diff
==============================================================================
--- geronimo/branches/1.1/modules/system/src/java/org/apache/geronimo/system/main/CommandLine.java
(original)
+++ geronimo/branches/1.1/modules/system/src/java/org/apache/geronimo/system/main/CommandLine.java
Wed May 17 19:10:58 2006
@@ -17,6 +17,7 @@
 
 package org.apache.geronimo.system.main;
 
+import java.io.IOException;
 import java.io.InputStream;
 import java.util.Iterator;
 import java.util.List;
@@ -115,14 +116,22 @@
     protected void startKernel() throws Exception {
         ClassLoader classLoader = CommandLine.class.getClassLoader();
         InputStream in = classLoader.getResourceAsStream("META-INF/config.ser");
-
-        // boot the kernel
-        kernel = KernelFactory.newInstance().createKernel("geronimo");
-        kernel.boot();
-
-        // load the configuration
-        configurationName = ConfigurationUtil.loadBootstrapConfiguration(kernel, in, classLoader);
-
+        try {
+            // boot the kernel
+            kernel = KernelFactory.newInstance().createKernel("geronimo");
+            kernel.boot();
+    
+            // load the configuration
+            configurationName = ConfigurationUtil.loadBootstrapConfiguration(kernel, in,
classLoader);
+        } finally {
+            if (in != null) {
+                try {
+                    in.close();
+                } catch (IOException ignored) {
+                    // ignored
+                }
+            }
+        }
     }
 
     protected void startKernel(Artifact moduleId) throws Exception {

Modified: geronimo/branches/1.1/modules/system/src/java/org/apache/geronimo/system/main/Daemon.java
URL: http://svn.apache.org/viewvc/geronimo/branches/1.1/modules/system/src/java/org/apache/geronimo/system/main/Daemon.java?rev=407433&r1=407432&r2=407433&view=diff
==============================================================================
--- geronimo/branches/1.1/modules/system/src/java/org/apache/geronimo/system/main/Daemon.java
(original)
+++ geronimo/branches/1.1/modules/system/src/java/org/apache/geronimo/system/main/Daemon.java
Wed May 17 19:10:58 2006
@@ -249,8 +249,18 @@
 
             // load this configuration
             InputStream in = classLoader.getResourceAsStream("META-INF/config.ser");
-            ConfigurationUtil.loadBootstrapConfiguration(kernel, in, classLoader);
-
+            try {
+                ConfigurationUtil.loadBootstrapConfiguration(kernel, in, classLoader);
+            } finally {
+                if (in != null) {
+                    try {
+                        in.close();
+                    } catch (IOException ignored) {
+                        // ignored
+                    }
+                }
+            }
+            
             monitor.systemStarted(kernel);
 
             AbstractNameQuery query = new AbstractNameQuery(PersistentConfigurationList.class.getName());

Modified: geronimo/branches/1.1/modules/system/src/java/org/apache/geronimo/system/util/PluginRepositoryExporter.java
URL: http://svn.apache.org/viewvc/geronimo/branches/1.1/modules/system/src/java/org/apache/geronimo/system/util/PluginRepositoryExporter.java?rev=407433&r1=407432&r2=407433&view=diff
==============================================================================
--- geronimo/branches/1.1/modules/system/src/java/org/apache/geronimo/system/util/PluginRepositoryExporter.java
(original)
+++ geronimo/branches/1.1/modules/system/src/java/org/apache/geronimo/system/util/PluginRepositoryExporter.java
Wed May 17 19:10:58 2006
@@ -17,6 +17,7 @@
 
 import java.io.File;
 import java.io.FileWriter;
+import java.io.InputStream;
 import java.io.IOException;
 import java.net.URI;
 import java.util.Collection;
@@ -98,7 +99,20 @@
         destRepo = new Maven2Repository(outFile);
         destRepo.setTypeHandler("car", new CopyArtifactTypeHandler());
         Properties props = new Properties();
-        props.load(PluginRepositoryExporter.class.getResourceAsStream("/META-INF/product-versions.properties"));
+        InputStream is = PluginRepositoryExporter.class.getResourceAsStream("/META-INF/product-versions.properties");
+        if(is == null) {
+            throw new IOException("Unable to locate /META-INF/product-versions.properties");
+        }        
+        try {
+            props.load(is);
+        } finally {
+            try {
+                is.close();
+            } catch (IOException ignored) {
+                // ignored
+            }
+        }
+        
         targetVersions = new HashMap();
         for (Iterator it = props.keySet().iterator(); it.hasNext();) {
             String product = (String) it.next();

Modified: geronimo/branches/1.1/modules/system/src/test/org/apache/geronimo/system/rmi/RMIClassLoaderSpiImplTest.java
URL: http://svn.apache.org/viewvc/geronimo/branches/1.1/modules/system/src/test/org/apache/geronimo/system/rmi/RMIClassLoaderSpiImplTest.java?rev=407433&r1=407432&r2=407433&view=diff
==============================================================================
--- geronimo/branches/1.1/modules/system/src/test/org/apache/geronimo/system/rmi/RMIClassLoaderSpiImplTest.java
(original)
+++ geronimo/branches/1.1/modules/system/src/test/org/apache/geronimo/system/rmi/RMIClassLoaderSpiImplTest.java
Wed May 17 19:10:58 2006
@@ -95,18 +95,29 @@
             }
             String resourceName = name.replace('.', '/') + ".class";
             InputStream in = delegate.getResourceAsStream(resourceName);
-            byte[] buffer = new byte[1024];
-            ByteArrayOutputStream out = new ByteArrayOutputStream();
-            int read = 0;
             try {
-                while (0 < (read = in.read(buffer))) {
-                    out.write(buffer, 0, read);
+                byte[] buffer = new byte[1024];
+                ByteArrayOutputStream out = new ByteArrayOutputStream();
+                int read = 0;
+                try {
+                    while (0 < (read = in.read(buffer))) {
+                        out.write(buffer, 0, read);
+                    }
+                } catch (IOException e) {
+                    fail();
+                    return null;
+                }
+                return defineClass(name, out.toByteArray(), 0, out.size());
+            } finally {
+                if (in != null)
+                {
+                    try {
+                        in.close();
+                    } catch (IOException ignored) {
+                        // ignored
+                    }
                 }
-            } catch (IOException e) {
-                fail();
-                return null;
             }
-            return defineClass(name, out.toByteArray(), 0, out.size());
         }  
         
         public URL[] getClassLoaderServerURLs() {



Mime
View raw message