logging-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From rpo...@apache.org
Subject svn commit: r1476286 - in /logging/log4j/log4j2/trunk: core/src/main/java/org/apache/logging/log4j/core/config/plugins/PluginManager.java src/changes/changes.xml
Date Fri, 26 Apr 2013 16:41:43 GMT
Author: rpopma
Date: Fri Apr 26 16:41:43 2013
New Revision: 1476286

URL: http://svn.apache.org/r1476286
Log:
Fix for Log4j2-217: ensure PluginManager streams are always closed

Modified:
    logging/log4j/log4j2/trunk/core/src/main/java/org/apache/logging/log4j/core/config/plugins/PluginManager.java
    logging/log4j/log4j2/trunk/src/changes/changes.xml

Modified: logging/log4j/log4j2/trunk/core/src/main/java/org/apache/logging/log4j/core/config/plugins/PluginManager.java
URL: http://svn.apache.org/viewvc/logging/log4j/log4j2/trunk/core/src/main/java/org/apache/logging/log4j/core/config/plugins/PluginManager.java?rev=1476286&r1=1476285&r2=1476286&view=diff
==============================================================================
--- logging/log4j/log4j2/trunk/core/src/main/java/org/apache/logging/log4j/core/config/plugins/PluginManager.java
(original)
+++ logging/log4j/log4j2/trunk/core/src/main/java/org/apache/logging/log4j/core/config/plugins/PluginManager.java
Fri Apr 26 16:41:43 2013
@@ -206,12 +206,13 @@ public class PluginManager {
         final ConcurrentMap<String, ConcurrentMap<String, PluginType>> map =
             new ConcurrentHashMap<String, ConcurrentMap<String, PluginType>>();
         while (resources.hasMoreElements()) {
+            DataInputStream dis = null;
             try {
                 final URL url = resources.nextElement();
                 LOGGER.debug("Found Plugin Map at {}", url.toExternalForm());
                 final InputStream is = url.openStream();
                 final BufferedInputStream bis = new BufferedInputStream(is);
-                final DataInputStream dis = new DataInputStream(bis);
+                dis = new DataInputStream(bis);
                 final int count = dis.readInt();
                 for (int j = 0; j < count; ++j) {
                     final String type = dis.readUTF();
@@ -231,10 +232,15 @@ public class PluginManager {
                     }
                     map.putIfAbsent(type, types);
                 }
-                dis.close();
             } catch (final Exception ex) {
                 LOGGER.warn("Unable to preload plugins", ex);
                 return null;
+            } finally {
+                try {
+                    dis.close();
+                } catch (Exception ignored) {
+                    // nothing we can do here...
+                }
             }
         }
         return map.size() == 0 ? null : map;
@@ -242,12 +248,13 @@ public class PluginManager {
 
     private static void encode(final ConcurrentMap<String, ConcurrentMap<String, PluginType>>
map) {
         final String fileName = rootDir + PATH + FILENAME;
+        DataOutputStream dos = null;
         try {
             final File file = new File(rootDir + PATH);
             file.mkdirs();
             final FileOutputStream fos = new FileOutputStream(fileName);
             final BufferedOutputStream bos = new BufferedOutputStream(fos);
-            final DataOutputStream dos = new DataOutputStream(bos);
+            dos = new DataOutputStream(bos);
             dos.writeInt(map.size());
             for (final Map.Entry<String, ConcurrentMap<String, PluginType>> outer
: map.entrySet()) {
                 dos.writeUTF(outer.getKey());
@@ -261,9 +268,14 @@ public class PluginManager {
                     dos.writeBoolean(pt.isDeferChildren());
                 }
             }
-            dos.close();
         } catch (final Exception ex) {
             ex.printStackTrace();
+        } finally {
+            try {
+                dos.close();
+            } catch (Exception ignored) {
+                // nothing we can do here...
+            }
         }
     }
 

Modified: logging/log4j/log4j2/trunk/src/changes/changes.xml
URL: http://svn.apache.org/viewvc/logging/log4j/log4j2/trunk/src/changes/changes.xml?rev=1476286&r1=1476285&r2=1476286&view=diff
==============================================================================
--- logging/log4j/log4j2/trunk/src/changes/changes.xml (original)
+++ logging/log4j/log4j2/trunk/src/changes/changes.xml Fri Apr 26 16:41:43 2013
@@ -23,6 +23,9 @@
 
   <body>
     <release version="2.0-beta6" date="@TBD@" description="Bug fixes and enhancements">
+      <action issue="LOG4J2-217" dev="rpopma" type="fix" due-to="Fabien Sanglard">
+        Ensure PluginManager streams are always closed.
+      </action>
     </release>
     <release version="2.0-beta5" date="2013-04-20" description="Bug fixes and enhancements">
       <action issue="LOG4J2-205" dev="rgoers" type="fix">



Mime
View raw message