diff --git a/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/security/ShellBasedIdMapping.java b/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/security/ShellBasedIdMapping.java index 27761da9b06..e45ac8cf11d 100644 --- a/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/security/ShellBasedIdMapping.java +++ b/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/security/ShellBasedIdMapping.java @@ -85,7 +85,7 @@ public class ShellBasedIdMapping implements IdMappingServiceProvider { private static final Pattern EMPTY_LINE = Pattern.compile("^\\s*$"); private static final Pattern COMMENT_LINE = Pattern.compile("^\\s*#.*$"); private static final Pattern MAPPING_LINE = - Pattern.compile("^(uid|gid)\\s+(\\d+)\\s+(\\d+)\\s*(#.*)?$"); + Pattern.compile("^(uid|gid)\\s+(\\d+)\\s+(0|-?[1-9]\\d*)\\s*(#.*)?$"); final private long timeout; diff --git a/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/security/TestShellBasedIdMapping.java b/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/security/TestShellBasedIdMapping.java index 3b533d2ced3..e3952475691 100644 --- a/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/security/TestShellBasedIdMapping.java +++ b/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/security/TestShellBasedIdMapping.java @@ -148,8 +148,9 @@ public class TestShellBasedIdMapping { // getUid() incrIdMapping.clearNameMaps(); uidNameMap = refIdMapping.getUidNameMap(); - { - BiMap.Entry me = uidNameMap.entrySet().iterator().next(); + for (BiMap.Entry me : uidNameMap.entrySet()) { + tempStaticMapFile.delete(); + incrIdMapping.clearNameMaps(); Integer id = me.getKey(); String name = me.getValue(); @@ -174,8 +175,9 @@ public class TestShellBasedIdMapping { // getGid() incrIdMapping.clearNameMaps(); gidNameMap = refIdMapping.getGidNameMap(); - { - BiMap.Entry me = gidNameMap.entrySet().iterator().next(); + for (BiMap.Entry me : gidNameMap.entrySet()) { + tempStaticMapFile.delete(); + incrIdMapping.clearNameMaps(); Integer id = me.getKey(); String name = me.getValue(); @@ -189,7 +191,11 @@ public class TestShellBasedIdMapping { Integer rid = id + 10000; String smapStr = "gid " + rid + " " + id; // Sleep a bit to avoid that two changes have the same modification time - try {Thread.sleep(1000);} catch (InterruptedException e) {} + try { + Thread.sleep(100); + } catch (InterruptedException e) { + // Do nothing + } createStaticMapFile(tempStaticMapFile, smapStr); // Now the id found for "name" should be the id specified by