{"record":{"id":"4e19a92a192d6351","repo":"apache/hadoop","slug":"duplicate-option-simplename","errorCode":null,"errorMessage":"Duplicate option ${simpleName}","messagePattern":"Duplicate option (.+?)","errorType":"exception","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/fs/Options.java","lineNumber":454,"sourceCode":"    /**\n     * Utility method to extract a HandleOpt from the set provided.\n     * @param c Target class\n     * @param opt List of options\n     * @param <T> Type constraint for exact match\n     * @throws IllegalArgumentException If more than one matching type is found.\n     * @return An option assignable from the specified type or null if either\n     * opt is null or a suitable match is not found.\n     */\n    public static <T extends HandleOpt> Optional<T> getOpt(\n        Class<T> c, HandleOpt... opt) {\n      if (null == opt) {\n        return Optional.empty();\n      }\n      T ret = null;\n      for (HandleOpt o : opt) {\n        if (c.isAssignableFrom(o.getClass())) {\n          if (ret != null) {\n            throw new IllegalArgumentException(\"Duplicate option \"\n                + c.getSimpleName());\n          }\n\n          @SuppressWarnings(\"unchecked\")\n          T tmp = (T) o;\n          ret = tmp;\n        }\n      }\n      return Optional.ofNullable(ret);\n    }\n\n    /**\n     * Option storing standard constraints on data.\n     */\n    public static class Data extends HandleOpt {\n      private final boolean allowChanged;\n      Data(boolean allowChanged) {\n        this.allowChanged = allowChanged;","sourceCodeStart":436,"sourceCodeEnd":472,"githubUrl":"https://github.com/apache/hadoop/blob/2add9630210752f88ceb1bb74eb65e37bf41da8e/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/fs/Options.java#L436-L472","documentation":"HandleOpt.getOpt(Class, HandleOpt...) scans for an option assignable to the requested class and throws IllegalArgumentException('Duplicate option <SimpleName>') on a second match. Used when opening files by handle (FileSystem/FileContext open with handle options); note it uses isAssignableFrom, so two subclassed options of the same category also collide.","triggerScenarios":"Passing two handle options assignable to the same base class in one open call — e.g. HandleOpt.dataLocality() plus another HandleOpt.ReadOpt subclass (both count as read options).","commonSituations":"Wrapper APIs stacking their own handle option on top of user-supplied ones; copying option examples into a call that already has a category covered.","solutions":["Pass exactly one option per category (one read-consistency opt, one write opt)","Dedupe by assignable category before invoking open(path, opts...)"],"exampleFix":"// before\nfs.open(p, HandleOpt.dataLocality(), customReadOpt);\n// after\nfs.open(p, HandleOpt.dataLocality());   // keep exactly one option per category","handlingStrategy":"validation","validationCode":"int readOpts = 0;\nfor (HandleOpt o : opts) {\n  if (HandleOpt.ReadOpt.class.isAssignableFrom(o.getClass())) readOpts++;\n}\nif (readOpts > 1) throw new IllegalArgumentException(\"duplicate read handle option\");","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Pass exactly one handle option per category (read/write)","Do not stack wrapper handle options on top of user-supplied ones","Remember subclasses collide too: matching uses isAssignableFrom"],"tags":["handle-options","duplicate","open-options"],"backgroundTag":"duplicate-handle-option","analyzedSha":"2add9630210752f88ceb1bb74eb65e37bf41da8e","analyzedAt":"2026-08-22T19:55:07.957Z","schemaVersion":2},"datasetVersion":"2026-08-23T01:17:44.959Z"}