logging-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From rpo...@apache.org
Subject svn commit: r1482897 - /logging/log4j/log4j2/trunk/core/src/main/java/org/apache/logging/log4j/core/appender/OutputStreamManager.java
Date Wed, 15 May 2013 15:25:23 GMT
Author: rpopma
Date: Wed May 15 15:25:23 2013
New Revision: 1482897

URL: http://svn.apache.org/r1482897
Log:
fixed potential concurrency issue with volatile field access (LOG4J2-254)

Modified:
    logging/log4j/log4j2/trunk/core/src/main/java/org/apache/logging/log4j/core/appender/OutputStreamManager.java

Modified: logging/log4j/log4j2/trunk/core/src/main/java/org/apache/logging/log4j/core/appender/OutputStreamManager.java
URL: http://svn.apache.org/viewvc/logging/log4j/log4j2/trunk/core/src/main/java/org/apache/logging/log4j/core/appender/OutputStreamManager.java?rev=1482897&r1=1482896&r2=1482897&view=diff
==============================================================================
--- logging/log4j/log4j2/trunk/core/src/main/java/org/apache/logging/log4j/core/appender/OutputStreamManager.java
(original)
+++ logging/log4j/log4j2/trunk/core/src/main/java/org/apache/logging/log4j/core/appender/OutputStreamManager.java
Wed May 15 15:25:23 2013
@@ -89,10 +89,10 @@ public class OutputStreamManager extends
     }
 
     protected void setOutputStream(final OutputStream os) {
-        this.os = os;
         if (header != null) {
             try {
-                this.os.write(header, 0, header.length);
+                os.write(header, 0, header.length);
+                this.os = os; // only update field if os.write() succeeded
             } catch (final IOException ioe) {
                 LOGGER.error("Unable to write header", ioe);
             }
@@ -128,11 +128,12 @@ public class OutputStreamManager extends
     }
 
     protected void close() {
-        if (os == System.out || os == System.err) {
+        OutputStream stream = os; // access volatile field only once per method
+        if (stream == System.out || stream == System.err) {
             return;
         }
         try {
-            os.close();
+            stream.close();
         } catch (final IOException ex) {
             LOGGER.error("Unable to close stream " + getName() + ". " + ex);
         }



Mime
View raw message