You are viewing a plain text version of this content. The canonical link for it is here.
Posted to derby-commits@db.apache.org by ka...@apache.org on 2012/06/26 10:11:59 UTC

svn commit: r1353852 - /db/derby/code/trunk/java/engine/org/apache/derby/iapi/util/DoubleProperties.java

Author: kahatlen
Date: Tue Jun 26 08:11:58 2012
New Revision: 1353852

URL: http://svn.apache.org/viewvc?rev=1353852&view=rev
Log:
DERBY-5830: Make DoubleProperties.propertyNames() thread-safe

Don't store the property values in the intermediate Hashtable as they
are not needed. They may be null if the Properties instances are
modified after the recursive calls to Properties.propertyNames(), and
trying to store a null value in a Hashtable results in a
NullPointerException, causing issues such as DERBY-4269.

Modified:
    db/derby/code/trunk/java/engine/org/apache/derby/iapi/util/DoubleProperties.java

Modified: db/derby/code/trunk/java/engine/org/apache/derby/iapi/util/DoubleProperties.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/engine/org/apache/derby/iapi/util/DoubleProperties.java?rev=1353852&r1=1353851&r2=1353852&view=diff
==============================================================================
--- db/derby/code/trunk/java/engine/org/apache/derby/iapi/util/DoubleProperties.java (original)
+++ db/derby/code/trunk/java/engine/org/apache/derby/iapi/util/DoubleProperties.java Tue Jun 26 08:11:58 2012
@@ -21,8 +21,10 @@
 
 package org.apache.derby.iapi.util;
 
-import java.util.Properties;
+import java.util.Collections;
 import java.util.Enumeration;
+import java.util.HashSet;
+import java.util.Properties;
 
 /**
 	A properties object that links two independent
@@ -31,7 +33,7 @@ import java.util.Enumeration;
 	second. But any put() calls are always made directly to
 	the write object.
 
-    Only the put(), keys() and getProperty() methods are supported
+    Only the put(), propertyNames() and getProperty() methods are supported
 	by this class.
 */
 
@@ -60,23 +62,21 @@ public final class DoubleProperties exte
 	}
 
 	public Enumeration propertyNames() {
-
-		Properties p = new Properties();
-
-		if (write != null) {
-
-			for (Enumeration e = write.propertyNames(); e.hasMoreElements(); ) {
-				String key = (String) e.nextElement();
-				p.put(key, write.getProperty(key));
-			}
-		}
-
-		if (read != null) {
-			for (Enumeration e = read.propertyNames(); e.hasMoreElements(); ) {
-				String key = (String) e.nextElement();
-				p.put(key, read.getProperty(key));
-			}
-		}
-		return p.keys();
+        HashSet names = new HashSet();
+        addAllNames(write, names);
+        addAllNames(read, names);
+        return Collections.enumeration(names);
 	}
+
+    /**
+     * Add all property names in the Properties object {@code src} to the
+     * HashSet {@code dest}.
+     */
+    private static void addAllNames(Properties src, HashSet dest) {
+        if (src != null) {
+            for (Enumeration e = src.propertyNames(); e.hasMoreElements(); ) {
+                dest.add(e.nextElement());
+            }
+        }
+    }
 }