Return-Path: X-Original-To: apmail-hadoop-common-commits-archive@www.apache.org Delivered-To: apmail-hadoop-common-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 DB0366080 for ; Wed, 18 May 2011 18:31:48 +0000 (UTC) Received: (qmail 47956 invoked by uid 500); 18 May 2011 18:31:48 -0000 Delivered-To: apmail-hadoop-common-commits-archive@hadoop.apache.org Received: (qmail 47930 invoked by uid 500); 18 May 2011 18:31:48 -0000 Mailing-List: contact common-commits-help@hadoop.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: common-dev@hadoop.apache.org Delivered-To: mailing list common-commits@hadoop.apache.org Received: (qmail 47923 invoked by uid 99); 18 May 2011 18:31:48 -0000 Received: from athena.apache.org (HELO athena.apache.org) (140.211.11.136) by apache.org (qpsmtpd/0.29) with ESMTP; Wed, 18 May 2011 18:31:48 +0000 X-ASF-Spam-Status: No, hits=-1998.0 required=5.0 tests=ALL_TRUSTED,FB_GET_MEDS 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; Wed, 18 May 2011 18:31:47 +0000 Received: by eris.apache.org (Postfix, from userid 65534) id 86B7523889BF; Wed, 18 May 2011 18:31:27 +0000 (UTC) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r1124370 - in /hadoop/common/branches/branch-0.22: CHANGES.txt src/java/org/apache/hadoop/conf/Configuration.java src/java/org/apache/hadoop/util/StringUtils.java src/test/core/org/apache/hadoop/conf/TestConfiguration.java Date: Wed, 18 May 2011 18:31:27 -0000 To: common-commits@hadoop.apache.org From: todd@apache.org X-Mailer: svnmailer-1.0.8 Message-Id: <20110518183127.86B7523889BF@eris.apache.org> Author: todd Date: Wed May 18 18:31:27 2011 New Revision: 1124370 URL: http://svn.apache.org/viewvc?rev=1124370&view=rev Log: HADOOP-7300. Configuration methods that return collections are inconsistent about mutability. Contributed by Todd Lipcon. Modified: hadoop/common/branches/branch-0.22/CHANGES.txt hadoop/common/branches/branch-0.22/src/java/org/apache/hadoop/conf/Configuration.java hadoop/common/branches/branch-0.22/src/java/org/apache/hadoop/util/StringUtils.java hadoop/common/branches/branch-0.22/src/test/core/org/apache/hadoop/conf/TestConfiguration.java Modified: hadoop/common/branches/branch-0.22/CHANGES.txt URL: http://svn.apache.org/viewvc/hadoop/common/branches/branch-0.22/CHANGES.txt?rev=1124370&r1=1124369&r2=1124370&view=diff ============================================================================== --- hadoop/common/branches/branch-0.22/CHANGES.txt (original) +++ hadoop/common/branches/branch-0.22/CHANGES.txt Wed May 18 18:31:27 2011 @@ -474,6 +474,9 @@ Release 0.22.0 - Unreleased HADOOP-7296. The FsPermission(FsPermission) constructor does not use the sticky bit. (Siddharth Seth via tomwhite) + HADOOP-7300. Configuration methods that return collections are inconsistent + about mutability. (todd) + Release 0.21.1 - Unreleased IMPROVEMENTS Modified: hadoop/common/branches/branch-0.22/src/java/org/apache/hadoop/conf/Configuration.java URL: http://svn.apache.org/viewvc/hadoop/common/branches/branch-0.22/src/java/org/apache/hadoop/conf/Configuration.java?rev=1124370&r1=1124369&r2=1124370&view=diff ============================================================================== --- hadoop/common/branches/branch-0.22/src/java/org/apache/hadoop/conf/Configuration.java (original) +++ hadoop/common/branches/branch-0.22/src/java/org/apache/hadoop/conf/Configuration.java Wed May 18 18:31:27 2011 @@ -1023,7 +1023,7 @@ public class Configuration implements It public Collection getTrimmedStringCollection(String name) { String valueString = get(name); if (null == valueString) { - Collection empty = Collections.emptyList(); + Collection empty = new ArrayList(); return empty; } return StringUtils.getTrimmedStringCollection(valueString); Modified: hadoop/common/branches/branch-0.22/src/java/org/apache/hadoop/util/StringUtils.java URL: http://svn.apache.org/viewvc/hadoop/common/branches/branch-0.22/src/java/org/apache/hadoop/util/StringUtils.java?rev=1124370&r1=1124369&r2=1124370&view=diff ============================================================================== --- hadoop/common/branches/branch-0.22/src/java/org/apache/hadoop/util/StringUtils.java (original) +++ hadoop/common/branches/branch-0.22/src/java/org/apache/hadoop/util/StringUtils.java Wed May 18 18:31:27 2011 @@ -329,7 +329,8 @@ public class StringUtils { * @return a Collection of String values */ public static Collection getTrimmedStringCollection(String str){ - return Arrays.asList(getTrimmedStrings(str)); + return new ArrayList( + Arrays.asList(getTrimmedStrings(str))); } /** Modified: hadoop/common/branches/branch-0.22/src/test/core/org/apache/hadoop/conf/TestConfiguration.java URL: http://svn.apache.org/viewvc/hadoop/common/branches/branch-0.22/src/test/core/org/apache/hadoop/conf/TestConfiguration.java?rev=1124370&r1=1124369&r2=1124370&view=diff ============================================================================== --- hadoop/common/branches/branch-0.22/src/test/core/org/apache/hadoop/conf/TestConfiguration.java (original) +++ hadoop/common/branches/branch-0.22/src/test/core/org/apache/hadoop/conf/TestConfiguration.java Wed May 18 18:31:27 2011 @@ -24,6 +24,7 @@ import java.io.FileWriter; import java.io.IOException; import java.io.StringWriter; import java.util.ArrayList; +import java.util.Collection; import java.util.HashMap; import java.util.Map; import java.util.Random; @@ -448,6 +449,40 @@ public class TestConfiguration extends T assertArrayEquals(expectedNames, extractClassNames(classes1)); assertArrayEquals(expectedNames, extractClassNames(classes2)); } + + public void testGetStringCollection() throws IOException { + Configuration c = new Configuration(); + c.set("x", " a, b\n,\nc "); + Collection strs = c.getTrimmedStringCollection("x"); + assertEquals(3, strs.size()); + assertArrayEquals(new String[]{ "a", "b", "c" }, + strs.toArray(new String[0])); + + // Check that the result is mutable + strs.add("z"); + + // Make sure same is true for missing config + strs = c.getStringCollection("does-not-exist"); + assertEquals(0, strs.size()); + strs.add("z"); + } + + public void testGetTrimmedStringCollection() throws IOException { + Configuration c = new Configuration(); + c.set("x", "a, b, c"); + Collection strs = c.getStringCollection("x"); + assertEquals(3, strs.size()); + assertArrayEquals(new String[]{ "a", " b", " c" }, + strs.toArray(new String[0])); + + // Check that the result is mutable + strs.add("z"); + + // Make sure same is true for missing config + strs = c.getStringCollection("does-not-exist"); + assertEquals(0, strs.size()); + strs.add("z"); + } private static String[] extractClassNames(Class[] classes) { String[] classNames = new String[classes.length];