logging-log4j-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From carn...@apache.org
Subject svn commit: r475041 - /logging/log4j/trunk/src/java/org/apache/log4j/Category.java
Date Tue, 14 Nov 2006 23:03:40 GMT
Author: carnold
Date: Tue Nov 14 15:03:40 2006
New Revision: 475041

URL: http://svn.apache.org/viewvc?view=rev&rev=475041
Log:
Bug 35748: Use of read/write lock acquistition not necessaryily safe in Category

Modified:
    logging/log4j/trunk/src/java/org/apache/log4j/Category.java

Modified: logging/log4j/trunk/src/java/org/apache/log4j/Category.java
URL: http://svn.apache.org/viewvc/logging/log4j/trunk/src/java/org/apache/log4j/Category.java?view=diff&rev=475041&r1=475040&r2=475041
==============================================================================
--- logging/log4j/trunk/src/java/org/apache/log4j/Category.java (original)
+++ logging/log4j/trunk/src/java/org/apache/log4j/Category.java Tue Nov 14 15:03:40 2006
@@ -161,13 +161,14 @@
   public void addAppender(Appender newAppender) {
     // BEGIN - WRITE LOCK
     lock.getWriteLock();
-
+    try {
     if (aai == null) {
       aai = new AppenderAttachableImpl();
     }
-
     aai.addAppender(newAppender);
+    } finally {
     lock.releaseWriteLock();
+    }
     //	END - WRITE LOCK
 
     repository.fireAddAppenderEvent((Logger) this, newAppender);
@@ -209,17 +210,17 @@
     int writes = 0;
 
     for (Category c = this; c != null; c = c.parent) {
-      try {
   	  	// Protect against simultaneous writes operations such as 
 	   	  // addAppender, removeAppender,...
         c.lock.getReadLock();
-
+    	try {
         if (c.aai != null) {
           writes += c.aai.appendLoopOnAppenders(event);
         }
 	     } finally {
 			   c.lock.releaseReadLock();
 			 }
+	    
        if (!c.additive) {
          break;
        }      
@@ -604,12 +605,15 @@
   public Enumeration getAllAppenders() {
 	  Enumeration result;
   	lock.getReadLock();
+    try {
     if (aai == null) {
       result = NullEnumeration.getInstance();
     } else {
       result = aai.getAllAppenders();
     }
+    } finally {
     lock.releaseReadLock();
+    }
     return result;
   }
 
@@ -625,12 +629,15 @@
   	Appender result;
   	
   	lock.getReadLock();
+  	try {
     if ((aai == null) || (name == null)) {
       result = null;
     } else {	
 	    result = aai.getAppender(name);
     }	  
+  	} finally {
 	  lock.releaseReadLock();
+  	}
 	
     return result;
   }
@@ -941,14 +948,16 @@
   	boolean result;
 
     lock.getReadLock();
-    
+    try {
     if ((appender == null) || (aai == null)) {
       result = false;
     } else {
       result = aai.isAttached(appender);
     }
+    } finally {
+    	lock.releaseReadLock();
+    }
     
-    lock.releaseReadLock();
     return result;
   }
 
@@ -1186,13 +1195,15 @@
    */
   public void removeAllAppenders() {
     lock.getWriteLock();
-    
+    try {
     if (aai != null) {
       aai.removeAllAppenders();
       aai = null;
     }
+    } finally {
     lock.releaseWriteLock();
   }
+  }
 
   /**
    * Remove the appender passed as parameter form the list of appenders.
@@ -1203,14 +1214,16 @@
    */
   public void removeAppender(Appender appender) {
 	  lock.getWriteLock();
-    
+	  try {
     if ((appender == null) || (aai == null)) {
       // Nothing to do
     } else {
   		aai.removeAppender(appender);
     }
+	  } finally {
     lock.releaseWriteLock();
   }
+  }
 
   /**
    * Remove the appender with the name passed as parameter form the list of
@@ -1222,13 +1235,15 @@
    */
   public void removeAppender(String name) {
 	  lock.getWriteLock();
-	  
+	  try {
     if ((name == null) || (aai == null)) {
       // nothing to do
     } else {
       aai.removeAppender(name);
     }
+	  } finally {
     lock.releaseWriteLock();
+  }
   }
 
   /**



---------------------------------------------------------------------
To unsubscribe, e-mail: log4j-dev-unsubscribe@logging.apache.org
For additional commands, e-mail: log4j-dev-help@logging.apache.org


Mime
View raw message