From 72763dbee98088bd160b8643c64ca8d971de0bfd Mon Sep 17 00:00:00 2001 From: Uma Maheswara Rao G Date: Tue, 13 May 2014 07:36:22 +0000 Subject: [PATCH] Merge. HDFS-6367. EnumSetParam$Domain#parse fails for parameter containing more than one enum. Contributed by Yi Liu. git-svn-id: https://svn.apache.org/repos/asf/hadoop/common/branches/branch-2@1594151 13f79535-47bb-0310-9956-ffa450edef68 --- hadoop-hdfs-project/hadoop-hdfs/CHANGES.txt | 3 +++ .../hadoop/hdfs/web/resources/EnumSetParam.java | 4 ++-- .../apache/hadoop/hdfs/web/resources/TestParam.java | 11 +++++++++++ 3 files changed, 16 insertions(+), 2 deletions(-) diff --git a/hadoop-hdfs-project/hadoop-hdfs/CHANGES.txt b/hadoop-hdfs-project/hadoop-hdfs/CHANGES.txt index 6adcc808301..10a3fad6e02 100644 --- a/hadoop-hdfs-project/hadoop-hdfs/CHANGES.txt +++ b/hadoop-hdfs-project/hadoop-hdfs/CHANGES.txt @@ -203,6 +203,9 @@ Release 2.5.0 - UNRELEASED HDFS-5522. Datanode disk error check may be incorrectly skipped. (Rushabh S Shah via kihwal) + HDFS-6367. EnumSetParam$Domain#parse fails for parameter containing more than one enum. + (Yi Liu via umamahesh) + Release 2.4.1 - UNRELEASED INCOMPATIBLE CHANGES diff --git a/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/web/resources/EnumSetParam.java b/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/web/resources/EnumSetParam.java index a983d4314dd..5adb5a6fc2f 100644 --- a/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/web/resources/EnumSetParam.java +++ b/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/web/resources/EnumSetParam.java @@ -79,8 +79,8 @@ abstract class EnumSetParam> extends Param, EnumSet final EnumSet set = EnumSet.noneOf(enumClass); if (!str.isEmpty()) { for(int i, j = 0; j >= 0; ) { - i = j; - j = str.indexOf(',', i+1); + i = j > 0 ? j + 1 : 0; + j = str.indexOf(',', i); final String sub = j >= 0? str.substring(i, j): str.substring(i); set.add(Enum.valueOf(enumClass, sub.trim().toUpperCase())); } diff --git a/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/web/resources/TestParam.java b/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/web/resources/TestParam.java index 42da919ff2e..5c93a25dc44 100644 --- a/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/web/resources/TestParam.java +++ b/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/web/resources/TestParam.java @@ -21,12 +21,14 @@ import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertNull; import java.util.Arrays; +import java.util.EnumSet; import java.util.List; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.apache.hadoop.conf.Configuration; import org.apache.hadoop.fs.CommonConfigurationKeysPublic; +import org.apache.hadoop.fs.Options; import org.apache.hadoop.fs.Path; import org.apache.hadoop.fs.permission.AclEntry; import org.apache.hadoop.fs.permission.FsPermission; @@ -346,4 +348,13 @@ public class TestParam { } } + @Test + public void testRenameOptionSetParam() { + final RenameOptionSetParam p = new RenameOptionSetParam( + Options.Rename.OVERWRITE, Options.Rename.NONE); + final RenameOptionSetParam p1 = new RenameOptionSetParam( + p.getValueString()); + Assert.assertEquals(p1.getValue(), EnumSet.of( + Options.Rename.OVERWRITE, Options.Rename.NONE)); + } }