{"record":{"id":"af223bed979f310e","repo":"apache/hadoop","slug":"multiple-opts-varargs-clazz","errorCode":null,"errorMessage":"multiple opts varargs: ${clazz}","messagePattern":"multiple opts varargs: (.+?)","errorType":"exception","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/fs/Options.java","lineNumber":177,"sourceCode":"    }\n\n    \n    /**\n     * Get an option of desired type\n     * @param clazz is the desired class of the opt\n     * @param opts - not null - at least one opt must be passed\n     * @return an opt from one of the opts of type theClass.\n     *   returns null if there isn't any\n     */\n    static <T extends CreateOpts> T getOpt(Class<T> clazz, CreateOpts... opts) {\n      if (opts == null) {\n        throw new IllegalArgumentException(\"Null opt\");\n      }\n      T result = null;\n      for (int i = 0; i < opts.length; ++i) {\n        if (opts[i].getClass() == clazz) {\n          if (result != null) {\n            throw new IllegalArgumentException(\"multiple opts varargs: \" + clazz);\n          }\n\n          @SuppressWarnings(\"unchecked\")\n          T t = (T)opts[i];\n          result = t;\n        }\n      }\n      return result;\n    }\n    /**\n     * set an option\n     * @param newValue  the option to be set\n     * @param opts  - the option is set into this array of opts\n     * @return updated CreateOpts[] == opts + newValue\n     */\n    static <T extends CreateOpts> CreateOpts[] setOpt(final T newValue,\n        final CreateOpts... opts) {\n      final Class<?> clazz = newValue.getClass();","sourceCodeStart":159,"sourceCodeEnd":195,"githubUrl":"https://github.com/apache/hadoop/blob/2add9630210752f88ceb1bb74eb65e37bf41da8e/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/fs/Options.java#L159-L195","documentation":"Options.CreateOpts.getOpt(clazz, opts) scans the varargs for the requested option class and requires at most one match: two entries whose exact class equals clazz throw IllegalArgumentException('multiple opts varargs: <class>').","triggerScenarios":"FileSystem.create(path, CreateOpts.blockSize(a), CreateOpts.blockSize(b)) — the same option type supplied twice in one call; typically from concatenating a defaults array with user-supplied options.","commonSituations":"Option arrays assembled by array concatenation instead of merge; layered wrappers each appending their own blockSize/replication option.","solutions":["Dedupe the array so each option class appears at most once before calling create","Build/merge option arrays with CreateOpts.setOpt instead of concatenation"],"exampleFix":"// before\nfs.create(out, CreateOpts.blockSize(a), CreateOpts.blockSize(b));\n// after\nfs.create(out, CreateOpts.blockSize(b));   // one option per type; merge via setOpt","handlingStrategy":"validation","validationCode":"static CreateOpts[] dedupeByExactClass(CreateOpts... in) {\n  Map<Class<? extends CreateOpts>, CreateOpts> m = new LinkedHashMap<>();\n  for (CreateOpts o : in) m.put(o.getClass(), o);\n  return m.values().toArray(new CreateOpts[0]);\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Supply each option type at most once per create call","Merge option arrays with CreateOpts.setOpt, not concatenation","Dedupe layered wrapper inputs before the final FS call"],"tags":["create-options","duplicate","varargs"],"backgroundTag":"duplicate-create-option","analyzedSha":"2add9630210752f88ceb1bb74eb65e37bf41da8e","analyzedAt":"2026-08-22T19:55:07.957Z","schemaVersion":2},"datasetVersion":"2026-08-22T20:17:22.307Z"}