diff --git a/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/fs/shell/AclCommands.java b/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/fs/shell/AclCommands.java index 42829bf3e8..51a2255fe2 100644 --- a/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/fs/shell/AclCommands.java +++ b/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/fs/shell/AclCommands.java @@ -192,6 +192,9 @@ protected void processOptions(LinkedList args) throws IOException { boolean oneRemoveOption = cf.getOpt("b") || cf.getOpt("k"); boolean oneModifyOption = cf.getOpt("m") || cf.getOpt("x"); boolean setOption = cf.getOpt("-set"); + boolean hasExpectedOptions = cf.getOpt("b") || cf.getOpt("k") || + cf.getOpt("m") || cf.getOpt("x") || cf.getOpt("-set"); + if ((bothRemoveOptions || bothModifyOptions) || (oneRemoveOption && oneModifyOption) || (setOption && (oneRemoveOption || oneModifyOption))) { @@ -201,8 +204,13 @@ protected void processOptions(LinkedList args) throws IOException { // Only -m, -x and --set expects if (oneModifyOption || setOption) { + if (args.isEmpty()) { + throw new HadoopIllegalArgumentException( + "Missing arguments: "); + } if (args.size() < 2) { - throw new HadoopIllegalArgumentException(" is missing"); + throw new HadoopIllegalArgumentException( + "Missing either or "); } aclEntries = AclEntry.parseAclSpec(args.removeFirst(), !cf.getOpt("x")); } @@ -214,6 +222,10 @@ protected void processOptions(LinkedList args) throws IOException { throw new HadoopIllegalArgumentException("Too many arguments"); } + if (!hasExpectedOptions) { + throw new HadoopIllegalArgumentException( + "Expected one of -b, -k, -m, -x or --set options"); + } // In recursive mode, save a separate list of just the access ACL entries. // Only directories may have a default ACL. When a recursive operation // encounters a file under the specified path, it must pass only the diff --git a/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/fs/shell/TestAclCommands.java b/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/fs/shell/TestAclCommands.java index cb6f560c95..3b9d397773 100644 --- a/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/fs/shell/TestAclCommands.java +++ b/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/fs/shell/TestAclCommands.java @@ -64,6 +64,10 @@ public void testGetfaclValidations() throws Exception { @Test public void testSetfaclValidations() throws Exception { + assertFalse("setfacl should fail without options", + 0 == runCommand(new String[] { "-setfacl", "/" })); + assertFalse("setfacl should fail without options -b, -k, -m, -x or --set", + 0 == runCommand(new String[] { "-setfacl", "-R", "/" })); assertFalse("setfacl should fail without path", 0 == runCommand(new String[] { "-setfacl" })); assertFalse("setfacl should fail without aclSpec",