Return-Path: X-Original-To: apmail-db-derby-commits-archive@www.apache.org Delivered-To: apmail-db-derby-commits-archive@www.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id C55E89BF7 for ; Tue, 26 Jun 2012 08:12:22 +0000 (UTC) Received: (qmail 60794 invoked by uid 500); 26 Jun 2012 08:12:22 -0000 Delivered-To: apmail-db-derby-commits-archive@db.apache.org Received: (qmail 60694 invoked by uid 500); 26 Jun 2012 08:12:21 -0000 Mailing-List: contact derby-commits-help@db.apache.org; run by ezmlm Precedence: bulk list-help: list-unsubscribe: List-Post: Reply-To: "Derby Development" List-Id: Delivered-To: mailing list derby-commits@db.apache.org Received: (qmail 60673 invoked by uid 99); 26 Jun 2012 08:12:20 -0000 Received: from athena.apache.org (HELO athena.apache.org) (140.211.11.136) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 26 Jun 2012 08:12:20 +0000 X-ASF-Spam-Status: No, hits=-2000.0 required=5.0 tests=ALL_TRUSTED X-Spam-Check-By: apache.org Received: from [140.211.11.4] (HELO eris.apache.org) (140.211.11.4) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 26 Jun 2012 08:12:19 +0000 Received: from eris.apache.org (localhost [127.0.0.1]) by eris.apache.org (Postfix) with ESMTP id 9659E2388978; Tue, 26 Jun 2012 08:11:59 +0000 (UTC) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r1353852 - /db/derby/code/trunk/java/engine/org/apache/derby/iapi/util/DoubleProperties.java Date: Tue, 26 Jun 2012 08:11:59 -0000 To: derby-commits@db.apache.org From: kahatlen@apache.org X-Mailer: svnmailer-1.0.8-patched Message-Id: <20120626081159.9659E2388978@eris.apache.org> X-Virus-Checked: Checked by ClamAV on apache.org 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()); + } + } + } }