[slf4j-dev] [GIT] SLF4J: Simple Logging Facade for Java branch master updated. v_1.6.3-4-gf5865d3

Gitbot git-noreply at pixie.qos.ch
Mon Oct 31 23:17:29 CET 2011


This is an automated email from the git hooks/post-receive script. It was
generated because a ref change was pushed to the repository containing
the project "SLF4J: Simple Logging Facade for Java".

The branch, master has been updated
       via  f5865d3241e71a58d49a72992a63ad1f7f282b50 (commit)
      from  01d36bb31aba6ee52113120f817be3a44406d918 (commit)

Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.

- Log -----------------------------------------------------------------
http://git.qos.ch/gitweb/?p=slf4j.git;a=commit;h=f5865d3241e71a58d49a72992a63ad1f7f282b50
http://github.com/ceki/slf4j/commit/f5865d3241e71a58d49a72992a63ad1f7f282b50

commit f5865d3241e71a58d49a72992a63ad1f7f282b50
Author: Ceki Gulcu <ceki at qos.ch>
Date:   Mon Oct 31 23:17:02 2011 +0100

    fix bugs 203  and 224, adaptations for maven 3

diff --git a/pom.xml b/pom.xml
index a4dd9ea..326fa16 100644
--- a/pom.xml
+++ b/pom.xml
@@ -216,8 +216,7 @@
         <executions>
           <execution>
             <id>parse-version</id>
-            <goals>
-              <goal>parse-version</goal>
+            <goals>                                                                                    <goal>parse-version</goal>
             </goals>
           </execution>
         </executions>
diff --git a/slf4j-api/src/main/java/org/slf4j/MDC.java b/slf4j-api/src/main/java/org/slf4j/MDC.java
index b0e64e3..ed61b1f 100644
--- a/slf4j-api/src/main/java/org/slf4j/MDC.java
+++ b/slf4j-api/src/main/java/org/slf4j/MDC.java
@@ -26,8 +26,8 @@ package org.slf4j;
 
 import java.util.Map;
 
-import org.slf4j.helpers.BasicMDCAdapter;
 import org.slf4j.helpers.NOPMDCAdapter;
+import org.slf4j.helpers.BasicMDCAdapter;
 import org.slf4j.helpers.Util;
 import org.slf4j.impl.StaticMDCBinder;
 import org.slf4j.spi.MDCAdapter;
@@ -40,9 +40,10 @@ import org.slf4j.spi.MDCAdapter;
  * If the underlying logging system offers MDC functionality, then SLF4J's MDC,
  * i.e. this class, will delegate to the underlying system's MDC. Note that at
  * this time, only two logging systems, namely log4j and logback, offer MDC
- * functionality. If the underlying system does not support MDC, e.g.
- * java.util.logging, then SLF4J will use a {@link BasicMDCAdapter}.
- * 
+ * functionality. For java.util.logging which does not support MDC,
+ * {@link BasicMDCAdapter} will be used. For other systems, i.e slf4j-simple
+ * and slf4j-nop, {@link NOPMDCAdapter} will be used.
+ *
  * <p>
  * Thus, as a SLF4J user, you can take advantage of MDC in the presence of log4j
  * logback, or java.util.logging, but without forcing these systems as
diff --git a/slf4j-api/src/main/java/org/slf4j/helpers/BasicMDCAdapter.java b/slf4j-api/src/main/java/org/slf4j/helpers/BasicMDCAdapter.java
index 6ce7687..56818f1 100644
--- a/slf4j-api/src/main/java/org/slf4j/helpers/BasicMDCAdapter.java
+++ b/slf4j-api/src/main/java/org/slf4j/helpers/BasicMDCAdapter.java
@@ -26,18 +26,16 @@ package org.slf4j.helpers;
 
 import org.slf4j.spi.MDCAdapter;
 
-import java.util.HashMap;
+import java.util.*;
 import java.util.Map;
-import java.util.Set;
 
 /**
  * Basic MDC implementation, which can be used with logging systems that lack
  * out-of-the-box MDC support.
  * 
- * This code is largely based on logback's <a
- * href="http://svn.qos.ch/viewvc/logback/trunk/logback-classic/src/main/java/org/slf4j/impl/LogbackMDCAdapter.java">
- * LogbackMDCAdapter</a>.
- * 
+ * This code was initially inspired by  logback's LogbackMDCAdapter. However,
+ * LogbackMDCAdapter has evolved and is now considerably more sophisticated.
+ *
  * @author Ceki Gulcu
  * @author Maarten Bosteels
  * 
@@ -47,6 +45,19 @@ public class BasicMDCAdapter implements MDCAdapter {
 
   private InheritableThreadLocal inheritableThreadLocal = new InheritableThreadLocal();
 
+  static boolean isJDK14() {
+    try {
+      String javaVersion = System.getProperty("java.version");
+      return javaVersion.startsWith("1.4");
+    } catch(SecurityException se) {
+      // punt and assume JDK 1.5 or later
+      return false;
+    }
+  }
+
+  static boolean IS_JDK14 = isJDK14();
+
+
   /**
    * Put a context value (the <code>val</code> parameter) as identified with
    * the <code>key</code> parameter into the current thread's context map.
@@ -63,9 +74,9 @@ public class BasicMDCAdapter implements MDCAdapter {
     if (key == null) {
       throw new IllegalArgumentException("key cannot be null");
     }
-    HashMap map = (HashMap) inheritableThreadLocal.get();
+    Map map = (Map) inheritableThreadLocal.get();
     if (map == null) {
-      map = new HashMap();
+      map = Collections.synchronizedMap(new HashMap());
       inheritableThreadLocal.set(map);
     }
     map.put(key, val);
@@ -75,9 +86,9 @@ public class BasicMDCAdapter implements MDCAdapter {
    * Get the context identified by the <code>key</code> parameter.
    */
   public String get(String key) {
-    HashMap hashMap = (HashMap) inheritableThreadLocal.get();
-    if ((hashMap != null) && (key != null)) {
-      return (String) hashMap.get(key);
+    Map Map = (Map) inheritableThreadLocal.get();
+    if ((Map != null) && (key != null)) {
+      return (String) Map.get(key);
     } else {
       return null;
     }
@@ -87,7 +98,7 @@ public class BasicMDCAdapter implements MDCAdapter {
    * Remove the the context identified by the <code>key</code> parameter.
    */
   public void remove(String key) {
-    HashMap map = (HashMap) inheritableThreadLocal.get();
+    Map map = (Map) inheritableThreadLocal.get();
     if (map != null) {
       map.remove(key);
     }
@@ -97,12 +108,16 @@ public class BasicMDCAdapter implements MDCAdapter {
    * Clear all entries in the MDC.
    */
   public void clear() {
-    HashMap hashMap = (HashMap) inheritableThreadLocal.get();
-    if (hashMap != null) {
-      hashMap.clear();
+    Map map = (Map) inheritableThreadLocal.get();
+    if (map != null) {
+      map.clear();
       // the InheritableThreadLocal.remove method was introduced in JDK 1.5
-      // Thus, invoking clear() on previous JDK's will fail
-      inheritableThreadLocal.remove();
+      // Thus, invoking clear() on previous JDK 1.4 will fail
+      if(isJDK14()) {
+        inheritableThreadLocal.set(null);
+      }  else {
+        inheritableThreadLocal.remove();
+      }
     }
   }
 
@@ -113,9 +128,9 @@ public class BasicMDCAdapter implements MDCAdapter {
    * @return the keys in the MDC
    */
   public Set getKeys() {
-    HashMap hashMap = (HashMap) inheritableThreadLocal.get();
-    if (hashMap != null) {
-      return hashMap.keySet();
+    Map map = (Map) inheritableThreadLocal.get();
+    if (map != null) {
+      return map.keySet();
     } else {
       return null;
     }
@@ -126,23 +141,21 @@ public class BasicMDCAdapter implements MDCAdapter {
    * 
    */
   public Map getCopyOfContextMap() {
-    HashMap hashMap = (HashMap) inheritableThreadLocal.get();
-    if (hashMap != null) {
-      return new HashMap(hashMap);
+    Map oldMap = (Map) inheritableThreadLocal.get();
+    if (oldMap != null) {
+       Map newMap = Collections.synchronizedMap(new HashMap());
+       synchronized (oldMap) {
+         newMap.putAll(oldMap);
+       }
+       return  newMap;
     } else {
       return null;
     }
   }
 
   public void setContextMap(Map contextMap) {
-    HashMap hashMap = (HashMap) inheritableThreadLocal.get();
-    if (hashMap != null) {
-      hashMap.clear();
-      hashMap.putAll(contextMap);
-    } else {
-      hashMap = new HashMap(contextMap);
-      inheritableThreadLocal.set(hashMap);
-    }
+    Map map = Collections.synchronizedMap(new HashMap(contextMap));
+    inheritableThreadLocal.set(map);
   }
 
 }
diff --git a/slf4j-site/pom.xml b/slf4j-site/pom.xml
index 03fd548..1e8925f 100644
--- a/slf4j-site/pom.xml
+++ b/slf4j-site/pom.xml
@@ -29,11 +29,7 @@
 				<filtering>true</filtering>
 			</resource>
 		</resources>
-	</build>
-
-
-	<reporting>
-		<plugins>
+      <plugins>
 			<plugin>
 				<groupId>org.apache.maven.plugins</groupId>
 				<artifactId>maven-site-plugin</artifactId>
@@ -41,19 +37,7 @@
 					<outputDirectory>${project.parent.basedir}/target/site</outputDirectory>
 				</configuration>
 			</plugin>
-			<plugin>
-				<groupId>org.apache.maven.plugins</groupId>
-				<artifactId>
-					maven-project-info-reports-plugin
-				</artifactId>
-				<reportSets>
-					<reportSet>
-						<reports>
-						</reports>
-					</reportSet>
-				</reportSets>
-			</plugin>
-		</plugins>
-	</reporting>
+      </plugins>
+	</build>
 
 </project>
\ No newline at end of file
diff --git a/slf4j-site/src/site/pages/news.html b/slf4j-site/src/site/pages/news.html
index df12eaa..0b16385 100644
--- a/slf4j-site/src/site/pages/news.html
+++ b/slf4j-site/src/site/pages/news.html
@@ -29,6 +29,19 @@
 
    <hr noshade="noshade" size="1"/>
 
+   <h3>October 31st, 2011 - Release of SLF4J 1.6.4</h3>
+
+   <p>Fixed in thread-safety issues in <code>BasicMDCAdapter</code>
+   fixing <a href="http://bugzilla.slf4j.org/show_bug.cgi?id=203">bug
+   #203</a> and <a
+   href="http://bugzilla.slf4j.org/show_bug.cgi?id=224">bug
+   #224</a>. Note that <code>BasicMDCAdapter</code> is only used with
+   the slf4j-jdk14.jar binding.
+   </p>
+
+   <p><code>BasicMDCAdapter</code> invoked a method introduced in JDK
+   1.5 preventing it from running under JDK 1.4. Interestingly enough,
+   this issue has never been reported by the user community.</p>
 
    <h3>October 17th, 2011 - Release of SLF4J 1.6.3</h3>
 

-----------------------------------------------------------------------

Summary of changes:
 pom.xml                                            |    3 +-
 slf4j-api/src/main/java/org/slf4j/MDC.java         |    9 ++-
 .../java/org/slf4j/helpers/BasicMDCAdapter.java    |   75 ++++++++++++--------
 slf4j-site/pom.xml                                 |   22 +-----
 slf4j-site/src/site/pages/news.html                |   13 ++++
 5 files changed, 66 insertions(+), 56 deletions(-)


hooks/post-receive
-- 
SLF4J: Simple Logging Facade for Java


More information about the slf4j-dev mailing list