hadoop-common-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From t...@apache.org
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 GMT
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<String> getTrimmedStringCollection(String name) {
     String valueString = get(name);
     if (null == valueString) {
-      Collection<String> empty = Collections.emptyList();
+      Collection<String> empty = new ArrayList<String>();
       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 <code>Collection</code> of <code>String</code> values
    */
   public static Collection<String> getTrimmedStringCollection(String str){
-    return Arrays.asList(getTrimmedStrings(str));
+    return new ArrayList<String>(
+      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<String> 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<String> 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];



Mime
View raw message