{"record":{"id":"8db2340d8dc6c171","repo":"apache/hadoop","slug":"flag-does-not-specify-any-options","errorCode":null,"errorMessage":"${flag} does not specify any options","messagePattern":"(.+?) does not specify any options","errorType":"exception","errorClass":"HadoopIllegalArgumentException","httpStatus":null,"severity":"error","filePath":"hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/fs/CreateFlag.java","lineNumber":151,"sourceCode":"\n  private final short mode;\n\n  private CreateFlag(short mode) {\n    this.mode = mode;\n  }\n\n  short getMode() {\n    return mode;\n  }\n  \n  /**\n   * Validate the CreateFlag and throw exception if it is invalid\n   * @param flag set of CreateFlag\n   * @throws HadoopIllegalArgumentException if the CreateFlag is invalid\n   */\n  public static void validate(EnumSet<CreateFlag> flag) {\n    if (flag == null || flag.isEmpty()) {\n      throw new HadoopIllegalArgumentException(flag\n          + \" does not specify any options\");\n    }\n    final boolean append = flag.contains(APPEND);\n    final boolean overwrite = flag.contains(OVERWRITE);\n    \n    // Both append and overwrite is an error\n    if (append && overwrite) {\n      throw new HadoopIllegalArgumentException(\n          flag + \"Both append and overwrite options cannot be enabled.\");\n    }\n  }\n  \n  /**\n   * Validate the CreateFlag for create operation\n   * @param path Object representing the path; usually String or {@link Path}\n   * @param pathExists pass true if the path exists in the file system\n   * @param flag set of CreateFlag\n   * @throws IOException on error","sourceCodeStart":133,"sourceCodeEnd":169,"githubUrl":"https://github.com/apache/hadoop/blob/2add9630210752f88ceb1bb74eb65e37bf41da8e/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/fs/CreateFlag.java#L133-L169","documentation":"CreateFlag.validate(EnumSet<CreateFlag>) rejects a null or empty flag set with HadoopIllegalArgumentException. Every create/append path (FileSystem.create with EnumSet, FileContext.create, builder APIs, HarFileSystem, FilterFs.createInternal) funnels through this validation, because with no flags the filesystem cannot know whether you intend create, overwrite, or append.","triggerScenarios":"Passing EnumSet.noneOf(CreateFlag.class) (or a set that ended up empty after conditional adds like flags.add(x) inside a skipped if) to fs.create(f, perms, flags, ...) / fc.create(f, EnumSet<CreateFlag>, ...) or calling CreateFlag.validate directly with an empty set.","commonSituations":"Flag sets built dynamically: EnumSet<CreateFlag> flags = EnumSet.noneOf(...); if (overwrite) flags.add(OVERWRITE); ... and the branch conditions are all false, leaving it empty; refactoring removes the flag.add(CREATE) call; test helpers constructing flags from a config value that is unset.","solutions":["Always seed the set with the primary intent: EnumSet.of(CreateFlag.CREATE) for new files, or EnumSet.of(CreateFlag.CREATE, CreateFlag.OVERWRITE) to clobber.","Build flags in one place from booleans and assert non-empty before the fs call: Preconditions.checkArgument(!flags.isEmpty()).","Call CreateFlag.validate(flags) yourself before touching the filesystem to get the failure at the construction site rather than deep in the fs stack."],"exampleFix":"// before\nEnumSet<CreateFlag> flags = EnumSet.noneOf(CreateFlag.class);\nif (overwrite) flags.add(CreateFlag.OVERWRITE);\nfs.create(path, perms, flags, 4096, (short)1, 1<<26, null); // empty when overwrite=false\n\n// after\nEnumSet<CreateFlag> flags = overwrite\n    ? EnumSet.of(CreateFlag.CREATE, CreateFlag.OVERWRITE)\n    : EnumSet.of(CreateFlag.CREATE);\nfs.create(path, perms, flags, 4096, (short)1, 1<<26, null);","handlingStrategy":"validation","validationCode":"if (flags == null || flags.isEmpty()) {\n  throw new IllegalArgumentException(\"write mode required: CREATE and/or OVERWRITE/APPEND\");\n}","typeGuard":"static EnumSet<CreateFlag> normalizedFlags(boolean overwrite) {\n  return overwrite ? EnumSet.of(CreateFlag.CREATE, CreateFlag.OVERWRITE)\n                   : EnumSet.of(CreateFlag.CREATE);\n}","tryCatchPattern":"try {\n  fs.create(path, perms, flags, buf, rep, block, null);\n} catch (HadoopIllegalArgumentException e) { // '... does not specify any options'\n  // rebuild flags with an explicit primary intent and retry\n}","preventionTips":["Build flag sets with EnumSet.of(...) seeded from the primary intent instead of accumulating conditionally.","Assert !flags.isEmpty() at the construction site.","Pre-validate with CreateFlag.validate(flags) to fail close to the bug."],"tags":["hadoop","filesystem","create-flag","validation","argument-error"],"backgroundTag":"invalid-create-flag","analyzedSha":"2add9630210752f88ceb1bb74eb65e37bf41da8e","analyzedAt":"2026-08-22T19:55:07.957Z","schemaVersion":2},"datasetVersion":"2026-08-22T20:17:22.307Z"}