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] + "]");
                }
            }
        }
    }

    @Override

View on GitHub (pinned to e1c734241f)

Solutions

  1. Ensure the Object[] passed to setParameters/invoke matches the target method's exact parameter count
  2. Check for reflection code that builds the args array and align it with the current method signature
  3. Verify interceptors/decorators pass through the original parameters instead of rebuilding them
  4. 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

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


AI-assisted analysis of quarkusio/quarkus@e1c734241f (2026-09-05). Data as JSON: /api/errors/0125b8e9153187cb. Report an issue: GitHub.