commons-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mben...@apache.org
Subject svn commit: r907374 - in /commons/proper/lang/branches/LANG_2_X/src: main/java/org/apache/commons/lang/builder/HashCodeBuilder.java test/java/org/apache/commons/lang/builder/HashCodeBuilderTest.java
Date Sun, 07 Feb 2010 03:32:05 GMT
Author: mbenson
Date: Sun Feb  7 03:32:04 2010
New Revision: 907374

URL: http://svn.apache.org/viewvc?rev=907374&view=rev
Log:
[LANG-586] merge HashCodeBuilder fix

Modified:
    commons/proper/lang/branches/LANG_2_X/src/main/java/org/apache/commons/lang/builder/HashCodeBuilder.java
    commons/proper/lang/branches/LANG_2_X/src/test/java/org/apache/commons/lang/builder/HashCodeBuilderTest.java

Modified: commons/proper/lang/branches/LANG_2_X/src/main/java/org/apache/commons/lang/builder/HashCodeBuilder.java
URL: http://svn.apache.org/viewvc/commons/proper/lang/branches/LANG_2_X/src/main/java/org/apache/commons/lang/builder/HashCodeBuilder.java?rev=907374&r1=907373&r2=907374&view=diff
==============================================================================
--- commons/proper/lang/branches/LANG_2_X/src/main/java/org/apache/commons/lang/builder/HashCodeBuilder.java
(original)
+++ commons/proper/lang/branches/LANG_2_X/src/main/java/org/apache/commons/lang/builder/HashCodeBuilder.java
Sun Feb  7 03:32:04 2010
@@ -101,13 +101,7 @@
      * 
      * @since 2.3
      */
-    private static final ThreadLocal registry = new ThreadLocal() {
-        protected Object initialValue() {
-            // The HashSet implementation is not synchronized,
-            // which is just what we need here.
-            return new HashSet();
-        }
-    };
+    private static final ThreadLocal REGISTRY = new ThreadLocal();
 
     /*
      * N.B. we cannot store the actual objects in a HashSet, as that would use the very hashCode()
@@ -135,7 +129,7 @@
      * @since 2.3
      */
     static Set getRegistry() {
-        return (Set) registry.get();
+        return (Set) REGISTRY.get();
     }
 
     /**
@@ -150,7 +144,8 @@
      * @since 2.3
      */
     static boolean isRegistered(Object value) {
-        return getRegistry().contains(new IDKey(value));
+        Set registry = getRegistry();
+        return registry != null && registry.contains(new IDKey(value));
     }
 
     /**
@@ -521,6 +516,11 @@
      *            The object to register.
      */
     static void register(Object value) {
+        synchronized (HashCodeBuilder.class) {
+            if (getRegistry() == null) {
+                REGISTRY.set(new HashSet());
+            }
+        }
         getRegistry().add(new IDKey(value));
     }
 
@@ -537,7 +537,15 @@
      * @since 2.3
      */
     static void unregister(Object value) {
-        getRegistry().remove(new IDKey(value));
+        Set registry = getRegistry();
+        if (registry != null) {
+            registry.remove(new IDKey(value));
+            synchronized (HashCodeBuilder.class) {
+                if (registry.isEmpty()) {
+                    REGISTRY.set(null);
+                }
+            }
+        }
     }
 
     /**

Modified: commons/proper/lang/branches/LANG_2_X/src/test/java/org/apache/commons/lang/builder/HashCodeBuilderTest.java
URL: http://svn.apache.org/viewvc/commons/proper/lang/branches/LANG_2_X/src/test/java/org/apache/commons/lang/builder/HashCodeBuilderTest.java?rev=907374&r1=907373&r2=907374&view=diff
==============================================================================
--- commons/proper/lang/branches/LANG_2_X/src/test/java/org/apache/commons/lang/builder/HashCodeBuilderTest.java
(original)
+++ commons/proper/lang/branches/LANG_2_X/src/test/java/org/apache/commons/lang/builder/HashCodeBuilderTest.java
Sun Feb  7 03:32:04 2010
@@ -509,7 +509,9 @@
         // at org.apache.commons.lang.builder.HashCodeBuilder.append(HashCodeBuilder.java:422)
 
         a.hashCode();
+        assertNull(HashCodeBuilder.getRegistry());
         b.hashCode();
+        assertNull(HashCodeBuilder.getRegistry());
     }
 
     /**



Mime
View raw message