{"record":{"id":"206b35c96341da2e","repo":"apache/hadoop","slug":"invalid-empty-argument-206b35","errorCode":null,"errorMessage":"Invalid empty argument","messagePattern":"Invalid empty argument","errorType":"validation","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/fs/shell/find/Perm.java","lineNumber":71,"sourceCode":"\n  @Override\n  public void prepare() throws IOException {\n    parseArgument(getArgument(1));\n  }\n\n  /**\n   * Parse an argument string to build the permission mask.\n   *\n   * @param argument String to be parsed\n   * @throws IllegalArgumentException if the argument is invalid\n   */\n  private void parseArgument(String argument) throws IllegalArgumentException {\n    String arg = argument;\n    if (arg == null) {\n      throw new IllegalArgumentException(\"Invalid null argument\");\n    }\n    if (arg.isEmpty()) {\n      throw new IllegalArgumentException(\"Invalid empty argument\");\n    }\n    if (arg.startsWith(\"-\")) {\n      mask = true;\n      arg = arg.substring(1);\n    }\n    if (Character.isDigit(arg.charAt(0))) {\n      // the argument is a numeric mode\n      permission = new FsPermission(arg).toShort();\n    } else {\n      // the argument is a symbolic mode\n      for (String part : arg.split(\",\")) {\n        int shift;\n        Operator operator = null;\n        int value = 0;\n        int position = 0;\n        switch (part.charAt(position++)) {\n        case 'u':\n          shift = 6;","sourceCodeStart":53,"sourceCodeEnd":89,"githubUrl":"https://github.com/apache/hadoop/blob/2add9630210752f88ceb1bb74eb65e37bf41da8e/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/fs/shell/find/Perm.java#L53-L89","documentation":"Perm implements the '-perm' expression of 'hadoop fs find'. parseArgument() builds a permission mask from exactly one argument; it first rejects null, then rejects an empty string because no mode can be derived from it. The IllegalArgumentException is raised while the expression is prepared, before any path is traversed.","triggerScenarios":"Running 'hadoop fs find <path> -perm \"\"' (an explicitly empty quoted argument), or calling Perm.addArguments()/setArguments() programmatically with an empty string. In scripts: 'find ... -perm $MODE' where MODE is unset or empty.","commonSituations":"Shell scripts forwarding an unset environment variable; wrapper code that splits an options string and feeds empty tokens; users assuming '-perm' with no value means 'any permissions'.","solutions":["Pass a valid mode after -perm: numeric octal ('-perm 644') or symbolic ('-perm u=rw')","Default empty shell variables: hadoop fs find / -perm \"${MODE:-644}\"","When using the Find API programmatically, assert the argument is non-empty before addArguments()"],"exampleFix":"# before\nhadoop fs find /data -perm \"$PERM\"   # PERM unset -> Invalid empty argument\n\n# after\nhadoop fs find /data -perm \"${PERM:-644}\"","handlingStrategy":"validation","validationCode":"static boolean hasPermArgument(String arg) {\n  return arg != null && !arg.isEmpty();\n}\n// use before building the find command:\nif (!hasPermArgument(mode)) throw new IllegalArgumentException(\"-perm needs a mode\");","typeGuard":null,"tryCatchPattern":"Around Find's prepare()/execution, catch IllegalArgumentException: the -perm parser signals null, empty and malformed modes with IAE (not IOException). Wrap and rethrow with the full command line for context.","preventionTips":["Quote every -perm argument in shell scripts","Default empty variables: ${PERM:-644}","Reject empty user input before assembling the find command"],"tags":["hadoop","fs-shell","find","permissions","argument-validation"],"backgroundTag":"invalid-command-argument","analyzedSha":"2add9630210752f88ceb1bb74eb65e37bf41da8e","analyzedAt":"2026-08-22T19:55:07.957Z","schemaVersion":2},"datasetVersion":"2026-08-22T20:17:22.307Z"}