From 4f399bb4baf4a7caac871a13336bbed7b0db1b15 Mon Sep 17 00:00:00 2001 From: Uma Maheswara Rao G Date: Tue, 13 May 2014 07:34:32 +0000 Subject: [PATCH] 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/trunk@1594150 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 8d752dd65e..0aa9d1d95d 100644 --- a/hadoop-hdfs-project/hadoop-hdfs/CHANGES.txt +++ b/hadoop-hdfs-project/hadoop-hdfs/CHANGES.txt @@ -455,6 +455,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 a983d4314d..5adb5a6fc2 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 @@ final EnumSet parse(final String str) { 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 42da919ff2..5c93a25dc4 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.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 void testAclPermissionParam() { } } + @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)); + } }