apache/hadoop · error · IllegalArgumentException
{} parameters are required but {} arguments are provided
Error message
{} parameters are required but {} arguments are provided What it means
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.
Source
Thrown at hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/util/ReflectionUtils.java:143
public static <T> T newInstance(Class<T> theClass, Configuration conf) {
return newInstance(theClass, conf, EMPTY_ARRAY);
}
/** Create an object for the given class and initialize it from conf
*
* @param theClass class of which an object is created
* @param conf Configuration
* @param argTypes the types of the arguments
* @param values the values of the arguments
* @param <T> Generics Type.
* @return a new object
*/
@SuppressWarnings("unchecked")
public static <T> T newInstance(Class<T> theClass, Configuration conf,
Class<?>[] argTypes, Object ... values) {
T result;
if (argTypes.length != values.length) {
throw new IllegalArgumentException(argTypes.length
+ " parameters are required but "
+ values.length
+ " arguments are provided");
}
try {
Constructor<T> meth = (Constructor<T>) CONSTRUCTOR_CACHE.get(theClass);
if (meth == null) {
meth = theClass.getDeclaredConstructor(argTypes);
meth.setAccessible(true);
CONSTRUCTOR_CACHE.put(theClass, meth);
}
result = meth.newInstance(values);
} catch (Exception e) {
throw new RuntimeException(e);
}
setConf(result, conf);
return result;
}View on GitHub (pinned to 2add963021)
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
Example fix
// before
Object plugin = ReflectionUtils.newInstance(cls, conf,
new Class<?>[] {String.class, int.class}, pathOnly);
// after
if (argTypes.length != values.length) {
throw new IllegalArgumentException("arity mismatch");
}
Object plugin = ReflectionUtils.newInstance(cls, conf, argTypes, values); Defensive patterns
Strategy: validation
Validate before calling
if (argTypes.length != values.length) {
throw new IllegalArgumentException(argTypes.length + " params vs " + values.length + " args");
}
T obj = ReflectionUtils.newInstance(cls, conf, argTypes, values); Prevention
- 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
When it happens
Trigger: 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.
Common situations: 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.
Related errors
- Illegal initial capacity: " + initCapacity
- Param class [{0}] does not have default constructor
- Illegal option {}
- Not enough arguments: expected {} but got {}
- Too many arguments: expected {} but got {}
AI-assisted analysis of apache/hadoop@2add963021 (2026-08-22).
Data as JSON: /api/errors/a0cb8b22c9b16fa9.
Report an issue: GitHub.