geronimo-scm mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jsis...@apache.org
Subject svn commit: r407422 - in /geronimo/branches/1.1/applications: console-core/src/java/org/apache/geronimo/console/core/security/ console-core/src/java/org/apache/geronimo/console/core/system/serverinfo/ console-standard/src/java/org/apache/geronimo/conso...
Date Thu, 18 May 2006 01:03:09 GMT
Author: jsisson
Date: Wed May 17 18:03:08 2006
New Revision: 407422

URL: http://svn.apache.org/viewvc?rev=407422&view=rev
Log:
GERONIMO-2032 - [console] Some input and output streams are not closed in finally blocks

Modified:
    geronimo/branches/1.1/applications/console-core/src/java/org/apache/geronimo/console/core/security/PropertiesLoginModuleManager.java
    geronimo/branches/1.1/applications/console-core/src/java/org/apache/geronimo/console/core/system/serverinfo/ServerConstants.java
    geronimo/branches/1.1/applications/console-standard/src/java/org/apache/geronimo/console/jmsmanager/wizard/JMSProviderData.java
    geronimo/branches/1.1/applications/console-standard/src/java/org/apache/geronimo/console/securitymanager/realm/MasterLoginModuleInfo.java

Modified: geronimo/branches/1.1/applications/console-core/src/java/org/apache/geronimo/console/core/security/PropertiesLoginModuleManager.java
URL: http://svn.apache.org/viewvc/geronimo/branches/1.1/applications/console-core/src/java/org/apache/geronimo/console/core/security/PropertiesLoginModuleManager.java?rev=407422&r1=407421&r2=407422&view=diff
==============================================================================
--- geronimo/branches/1.1/applications/console-core/src/java/org/apache/geronimo/console/core/security/PropertiesLoginModuleManager.java
(original)
+++ geronimo/branches/1.1/applications/console-core/src/java/org/apache/geronimo/console/core/security/PropertiesLoginModuleManager.java
Wed May 17 18:03:08 2006
@@ -19,6 +19,7 @@
 
 import java.io.File;
 import java.io.FileOutputStream;
+import java.io.InputStream;
 import java.io.IOException;
 import java.io.OutputStream;
 import java.net.URL;
@@ -58,42 +59,78 @@
 
     private void refreshUsers() {
         users.clear();
+        InputStream in = null;
         try {
-            users.load(serverInfo.resolve(getUsersURI()).toURL().openStream());
+            in = serverInfo.resolve(getUsersURI()).toURL().openStream();
+            users.load(in);
         } catch (Exception e) {
             throw new GeronimoSecurityException(e);
+        } finally {
+            if (in != null) {
+                try {
+                    in.close();
+                } catch (IOException ignored) {
+                    // ignored
+                }
+            }
         }
     }
 
     private void refreshGroups() throws GeronimoSecurityException {
         groups.clear();
+        InputStream in = null;
         try {
-            groups
-                    .load(serverInfo.resolve(getGroupsURI()).toURL()
-                            .openStream());
+            in = serverInfo.resolve(getGroupsURI()).toURL().openStream();
+            groups.load(in);
         } catch (Exception e) {
             throw new GeronimoSecurityException(e);
+        } finally {
+            if (in != null) {
+                try {
+                    in.close();
+                } catch (IOException ignored) {
+                    // ignored
+                }
+            }
         }
     }
 
     public String[] getUsers() throws GeronimoSecurityException {
         users.clear();
+        InputStream in = null;
         try {
-            users.load(serverInfo.resolve(getUsersURI()).toURL().openStream());
+            in = serverInfo.resolve(getUsersURI()).toURL().openStream();
+            users.load(in);
         } catch (Exception e) {
             throw new GeronimoSecurityException(e);
+        } finally {
+            if (in != null) {
+                try {
+                    in.close();
+                } catch (IOException ignored) {
+                    // ignored
+                }
+            }
         }
         return (String[]) users.keySet().toArray(new String[0]);
     }
 
     public String[] getGroups() throws GeronimoSecurityException {
         groups.clear();
+        InputStream in = null;
         try {
-            groups
-                    .load(serverInfo.resolve(getGroupsURI()).toURL()
-                            .openStream());
+            in = serverInfo.resolve(getGroupsURI()).toURL().openStream();
+            groups.load(in);
         } catch (Exception e) {
             throw new GeronimoSecurityException(e);
+        } finally {
+            if (in != null) {
+                try {
+                    in.close();
+                } catch (IOException ignored) {
+                    // ignored
+                }
+            }
         }
         return (String[]) groups.keySet().toArray(new String[0]);
     }
@@ -226,23 +263,28 @@
     }
 
     private void store(Properties props, URL url) throws Exception {
-        OutputStream out;
+        OutputStream out = null;
         try {
-            URLConnection con = url.openConnection();
-            con.setDoOutput(true);
-            out = con.getOutputStream();
-        } catch (Exception e) {
-            if ("file".equalsIgnoreCase(url.getProtocol()) && e instanceof UnknownServiceException)
{
-                out = new FileOutputStream(new File(url.getFile()));
-            } else {
-                throw e;
+            try {
+                URLConnection con = url.openConnection();
+                con.setDoOutput(true);
+                out = con.getOutputStream();
+            } catch (Exception e) {
+                if ("file".equalsIgnoreCase(url.getProtocol()) && e instanceof UnknownServiceException)
{
+                    out = new FileOutputStream(new File(url.getFile()));
+                } else {
+                    throw e;
+                }
+            }
+            props.store(out, null);
+        } finally {
+            if (out != null) {
+                try {
+                    out.close();
+                } catch (IOException ignored) {
+                    // ignored
+                }
             }
-        }
-        props.store(out, null);
-        try {
-            out.close();
-        } catch (IOException ie) {
-            // Ignore
         }
     }
 

Modified: geronimo/branches/1.1/applications/console-core/src/java/org/apache/geronimo/console/core/system/serverinfo/ServerConstants.java
URL: http://svn.apache.org/viewvc/geronimo/branches/1.1/applications/console-core/src/java/org/apache/geronimo/console/core/system/serverinfo/ServerConstants.java?rev=407422&r1=407421&r2=407422&view=diff
==============================================================================
--- geronimo/branches/1.1/applications/console-core/src/java/org/apache/geronimo/console/core/system/serverinfo/ServerConstants.java
(original)
+++ geronimo/branches/1.1/applications/console-core/src/java/org/apache/geronimo/console/core/system/serverinfo/ServerConstants.java
Wed May 17 18:03:08 2006
@@ -17,6 +17,7 @@
 
 package org.apache.geronimo.console.core.system.serverinfo;
 
+import java.io.InputStream;
 import java.util.Properties;
 
 public class ServerConstants {
@@ -91,12 +92,26 @@
      */
     static {
         Properties versionInfo = new Properties();
+        InputStream in = ServerConstants.class.getClassLoader()
+            .getResourceAsStream(PROPERTIES_FILE);
+        if(in == null) {
+            throw new ExceptionInInitializerError(new Exception(
+                    "Unable to locate geronimo-version.properties"));
+        }
+
         try {
-            versionInfo.load(ServerConstants.class.getClassLoader()
-                    .getResourceAsStream(PROPERTIES_FILE));
+            versionInfo.load(in);
         } catch (java.io.IOException e) {
             throw new ExceptionInInitializerError(new Exception(
                     "Could not load geronimo-version.properties", e));
+        } finally {
+            if (in != null) {
+                try {
+                    in.close();
+                } catch (java.io.IOException ignored) {
+                    // ignore
+                }
+            }
         }
         VERSION = versionInfo.getProperty("version");
         if (VERSION == null || VERSION.length() == 0) {

Modified: geronimo/branches/1.1/applications/console-standard/src/java/org/apache/geronimo/console/jmsmanager/wizard/JMSProviderData.java
URL: http://svn.apache.org/viewvc/geronimo/branches/1.1/applications/console-standard/src/java/org/apache/geronimo/console/jmsmanager/wizard/JMSProviderData.java?rev=407422&r1=407421&r2=407422&view=diff
==============================================================================
--- geronimo/branches/1.1/applications/console-standard/src/java/org/apache/geronimo/console/jmsmanager/wizard/JMSProviderData.java
(original)
+++ geronimo/branches/1.1/applications/console-standard/src/java/org/apache/geronimo/console/jmsmanager/wizard/JMSProviderData.java
Wed May 17 18:03:08 2006
@@ -353,9 +353,15 @@
         Properties props = new Properties();
         try {
             props.load(in);
-            in.close();
         } catch (IOException e) {
             log.error("Unable to read JMS provider properties file", e);
+        } finally {
+            // load could fail, ensure stream is closed.
+            try {
+                in.close();
+            } catch (IOException ignore) {
+                // ignore
+            }
         }
         Set set = new HashSet();
         // Find the names of the provider entries

Modified: geronimo/branches/1.1/applications/console-standard/src/java/org/apache/geronimo/console/securitymanager/realm/MasterLoginModuleInfo.java
URL: http://svn.apache.org/viewvc/geronimo/branches/1.1/applications/console-standard/src/java/org/apache/geronimo/console/securitymanager/realm/MasterLoginModuleInfo.java?rev=407422&r1=407421&r2=407422&view=diff
==============================================================================
--- geronimo/branches/1.1/applications/console-standard/src/java/org/apache/geronimo/console/securitymanager/realm/MasterLoginModuleInfo.java
(original)
+++ geronimo/branches/1.1/applications/console-standard/src/java/org/apache/geronimo/console/securitymanager/realm/MasterLoginModuleInfo.java
Wed May 17 18:03:08 2006
@@ -100,9 +100,14 @@
         Properties props = new Properties();
         try {
             props.load(in);
-            in.close();
         } catch (IOException e) {
             log.error("Unable to read login module properties file", e);
+        } finally {
+            try {
+                in.close();
+            } catch (java.io.IOException ignored) {
+                // ignore
+            }
         }
         for (Iterator it = props.keySet().iterator(); it.hasNext();) {
             String key = (String) it.next();



Mime
View raw message