quarkusio/quarkus · error · IllegalArgumentException

Trying to set a null value to a primitive parameter [positio

Error message

Trying to set a null value to a primitive parameter [position: " + i + ", type: " + parameterTypes[i] + "]

What it means

Runtime IllegalArgumentException from AbstractInvocationContext.validateParameters: an interceptor/decorator invocation tried to pass null for a primitive-valued method parameter. The message reports the parameter position and primitive type; the params array contains null where a non-null primitive wrapper is required.

Source

Thrown at independent-projects/arc/runtime/src/main/java/io/quarkus/arc/impl/AbstractInvocationContext.java:68

        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
    public Method getMethod() {
        return null;
    }

    @Override
    public Object getTarget() {

View on GitHub (pinned to e1c734241f)

Solutions

  1. Replace null with the primitive's default (0, 0L, false, etc.) at that position
  2. Change the target method parameter to the boxed type (Integer, Long, Boolean) if null is meaningful
  3. Validate the params array against declared types before calling setParameters

Example fix

// before
ctx.setParameters(new Object[] { null }); // method param is int
// after
ctx.setParameters(new Object[] { 0 }); // or make param Integer
Defensive patterns

Strategy: validation

Validate before calling

for (int i = 0; i < params.length; i++) {
  if (method.getParameterTypes()[i].isPrimitive() && params[i] == null) params[i] = defaultPrimitive(method.getParameterTypes()[i]);
}

Try / catch

try { ctx.setParameters(args); } catch (IllegalArgumentException e) { /* null primitive at position i — supply defaults */ }

Prevention

When it happens

Trigger: Calling setParameters()/invocation with an Object[] containing null at an index whose declared parameter type is int/long/boolean/etc. Common with Optional-style callers that map missing values to null.

Common situations: Passing null defaults into methods with primitive signatures; deserializers producing nulls for primitives; DTO-to-invocation mapping code that doesn't know primitive vs boxed types.

Related errors


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