apache/hadoop · error · IllegalArgumentException

multiple opts varargs: ${clazz}

Error message

multiple opts varargs: ${clazz}

What it means

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>').

Source

Thrown at hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/fs/Options.java:177

    }

    
    /**
     * Get an option of desired type
     * @param clazz is the desired class of the opt
     * @param opts - not null - at least one opt must be passed
     * @return an opt from one of the opts of type theClass.
     *   returns null if there isn't any
     */
    static <T extends CreateOpts> T getOpt(Class<T> clazz, CreateOpts... opts) {
      if (opts == null) {
        throw new IllegalArgumentException("Null opt");
      }
      T result = null;
      for (int i = 0; i < opts.length; ++i) {
        if (opts[i].getClass() == clazz) {
          if (result != null) {
            throw new IllegalArgumentException("multiple opts varargs: " + clazz);
          }

          @SuppressWarnings("unchecked")
          T t = (T)opts[i];
          result = t;
        }
      }
      return result;
    }
    /**
     * set an option
     * @param newValue  the option to be set
     * @param opts  - the option is set into this array of opts
     * @return updated CreateOpts[] == opts + newValue
     */
    static <T extends CreateOpts> CreateOpts[] setOpt(final T newValue,
        final CreateOpts... opts) {
      final Class<?> clazz = newValue.getClass();

View on GitHub (pinned to 2add963021)

Solutions

  1. Dedupe the array so each option class appears at most once before calling create
  2. Build/merge option arrays with CreateOpts.setOpt instead of concatenation

Example fix

// before
fs.create(out, CreateOpts.blockSize(a), CreateOpts.blockSize(b));
// after
fs.create(out, CreateOpts.blockSize(b));   // one option per type; merge via setOpt
Defensive patterns

Strategy: validation

Validate before calling

static CreateOpts[] dedupeByExactClass(CreateOpts... in) {
  Map<Class<? extends CreateOpts>, CreateOpts> m = new LinkedHashMap<>();
  for (CreateOpts o : in) m.put(o.getClass(), o);
  return m.values().toArray(new CreateOpts[0]);
}

Prevention

When it happens

Trigger: 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.

Common situations: Option arrays assembled by array concatenation instead of merge; layered wrappers each appending their own blockSize/replication option.

Related errors


AI-assisted analysis of apache/hadoop@2add963021 (2026-08-22). Data as JSON: /api/errors/af223bed979f310e. Report an issue: GitHub.