{"record":{"id":"a0cb8b22c9b16fa9","repo":"apache/hadoop","slug":"parameters-are-required-but-arguments-are-pr","errorCode":null,"errorMessage":"{} parameters are required but {} arguments are provided","messagePattern":"(.+?) parameters are required but (.+?) arguments are provided","errorType":"validation","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/util/ReflectionUtils.java","lineNumber":143,"sourceCode":"  public static <T> T newInstance(Class<T> theClass, Configuration conf) {\n    return newInstance(theClass, conf, EMPTY_ARRAY);\n  }\n\n  /** Create an object for the given class and initialize it from conf\n   *\n   * @param theClass class of which an object is created\n   * @param conf Configuration\n   * @param argTypes the types of the arguments\n   * @param values the values of the arguments\n   * @param <T> Generics Type.\n   * @return a new object\n   */\n  @SuppressWarnings(\"unchecked\")\n  public static <T> T newInstance(Class<T> theClass, Configuration conf,\n      Class<?>[] argTypes, Object ... values) {\n    T result;\n    if (argTypes.length != values.length) {\n      throw new IllegalArgumentException(argTypes.length\n          + \" parameters are required but \"\n          + values.length\n          + \" arguments are provided\");\n    }\n    try {\n      Constructor<T> meth = (Constructor<T>) CONSTRUCTOR_CACHE.get(theClass);\n      if (meth == null) {\n        meth = theClass.getDeclaredConstructor(argTypes);\n        meth.setAccessible(true);\n        CONSTRUCTOR_CACHE.put(theClass, meth);\n      }\n      result = meth.newInstance(values);\n    } catch (Exception e) {\n      throw new RuntimeException(e);\n    }\n    setConf(result, conf);\n    return result;\n  }","sourceCodeStart":125,"sourceCodeEnd":161,"githubUrl":"https://github.com/apache/hadoop/blob/2add9630210752f88ceb1bb74eb65e37bf41da8e/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/util/ReflectionUtils.java#L125-L161","documentation":"ReflectionUtils.newInstance(theClass, conf, argTypes, values) constructs an object via a reflected constructor, but first enforces argTypes.length == values.length; a mismatch throws IllegalArgumentException(\"N parameters are required but M arguments are provided\") before any reflection happens. It is a pure caller-side arity bug — not a classpath or access problem.","triggerScenarios":"Passing argTypes = {String.class, int.class} with only one varargs value; building values from a parsed list whose size is computed independently of the fixed types array; the varargs Object... parameter silently accepting the wrong count at compile time.","commonSituations":"Glue code instantiating pluggable classes (filesystems, schedulers, codecs) from config where the types are fixed but values come from parsing; refactors that add a parameter to one array but not the other.","solutions":["Assert argTypes.length == values.length before the call, or derive both from one source","Use the two-argument newInstance(theClass, conf) when the constructor takes no arguments","Check the traceback line to see which construction site dropped or added an element"],"exampleFix":"// before\nObject plugin = ReflectionUtils.newInstance(cls, conf,\n    new Class<?>[] {String.class, int.class}, pathOnly);\n\n// after\nif (argTypes.length != values.length) {\n  throw new IllegalArgumentException(\"arity mismatch\");\n}\nObject plugin = ReflectionUtils.newInstance(cls, conf, argTypes, values);","handlingStrategy":"validation","validationCode":"if (argTypes.length != values.length) {\n  throw new IllegalArgumentException(argTypes.length + \" params vs \" + values.length + \" args\");\n}\nT obj = ReflectionUtils.newInstance(cls, conf, argTypes, values);","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Derive argTypes and values from one source structure or assert equal lengths","Use newInstance(theClass, conf) for no-arg constructors","Compile-time alternative: prefer direct constructor calls where the type is known"],"tags":["hadoop","java","reflection","argument-validation","constructor"],"backgroundTag":"constructor-argument-mismatch","analyzedSha":"2add9630210752f88ceb1bb74eb65e37bf41da8e","analyzedAt":"2026-08-22T19:55:07.957Z","schemaVersion":2},"datasetVersion":"2026-08-22T20:17:22.307Z"}