quarkusio/quarkus · error · IllegalArgumentException
Wrong number of parameters - method has " + Arrays.toString(
Error message
Wrong number of parameters - method has " + Arrays.toString(parameterTypes) + ", attempting to set " + Arrays.toString(params)
What it means
AbstractInvocationContext.validateParameters() throws IllegalArgumentException when the number of parameters supplied does not equal the executable's declared parameter count. This validates arguments before invoking a dynamically-invoked bean method (interceptor/invocation context).
Source
Thrown at independent-projects/arc/runtime/src/main/java/io/quarkus/arc/impl/AbstractInvocationContext.java:62
}
@SuppressWarnings("unchecked")
@Override
public <T extends Annotation> List<T> findIterceptorBindings(Class<T> annotationType) {
List<T> found = new ArrayList<>();
for (Annotation annotation : (Set<Annotation>) getInterceptorBindings()) {
if (annotation.annotationType().equals(annotationType)) {
found.add((T) annotation);
}
}
return found;
}
static void validateParameters(Executable executable, Object[] params) {
int newParametersCount = Objects.requireNonNull(params).length;
Class<?>[] parameterTypes = executable.getParameterTypes();
if (parameterTypes.length != newParametersCount) {
throw new IllegalArgumentException(
"Wrong number of parameters - method has " + Arrays.toString(parameterTypes) + ", attempting to set "
+ Arrays.toString(params));
}
for (int i = 0; i < params.length; i++) {
if (parameterTypes[i].isPrimitive() && params[i] == null) {
throw new IllegalArgumentException("Trying to set a null value to a primitive parameter [position: " + i
+ ", type: " + parameterTypes[i] + "]");
}
if (params[i] != null) {
if (!Types.boxedClass(parameterTypes[i]).isAssignableFrom(Types.boxedClass(params[i].getClass()))) {
throw new IllegalArgumentException("The parameter type [" + params[i].getClass()
+ "] can not be assigned to the type for the target method [" + parameterTypes[i] + "]");
}
}
}
}
@OverrideView on GitHub (pinned to e1c734241f)
Solutions
- Ensure the Object[] passed to setParameters/invoke matches the target method's exact parameter count
- Check for reflection code that builds the args array and align it with the current method signature
- Verify interceptors/decorators pass through the original parameters instead of rebuilding them
- Log Arrays.toString of both arrays (as the exception does) to compare positions
Example fix
// before
ctx.setParameters(new Object[] { id }); // method has 2 params
// after
ctx.setParameters(new Object[] { id, name }); // match declared signature Defensive patterns
Strategy: validation
Validate before calling
Object[] p = ...; if (p.length != method.getParameterCount()) throw new IllegalArgumentException("expected " + method.getParameterCount() + " args"); Try / catch
try { ctx.setParameters(args); } catch (IllegalArgumentException e) { log.warnf("Param mismatch: %s", e.getMessage()); } Prevention
- Derive parameter arrays from the method's ParameterCount
- Update reflection callers when method signatures change
- Add unit tests for interceptor invocation paths
When it happens
Trigger: Calling InvocationContext.setParameters(Object[]) (or the internal invocation path) with an array whose length differs from the target method's parameter count, including passing null params.
Common situations: Miswired interceptors or synthetic invocations (e.g. in Dev UI or generated code) passing wrong-sized argument arrays; reflection-based callers constructing parameter arrays by hand; signature change after refactoring where callers weren't updated.
Related errors
- Cache key generator instantiation failed
- Cannot instantiate JSON-B component:
- Unable to instantiate the class:
- Trying to set a null value to a primitive parameter [positio
- The parameter type [" + params[i].getClass() + "] can not be
AI-assisted analysis of quarkusio/quarkus@e1c734241f (2026-09-05).
Data as JSON: /api/errors/0125b8e9153187cb.
Report an issue: GitHub.