{"record":{"id":"7b8a980941f52588","repo":"quarkusio/quarkus","slug":"trying-to-set-a-null-value-to-a-primitive-paramete","errorCode":null,"errorMessage":"Trying to set a null value to a primitive parameter [position: \" + i + \", type: \" + parameterTypes[i] + \"]","messagePattern":"Trying to set a null value to a primitive parameter \\[position: \" \\+ i \\+ \", type: \" \\+ parameterTypes\\[i\\] \\+ \"\\]","errorType":"exception","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"independent-projects/arc/runtime/src/main/java/io/quarkus/arc/impl/AbstractInvocationContext.java","lineNumber":68,"sourceCode":"        for (Annotation annotation : (Set<Annotation>) getInterceptorBindings()) {\n            if (annotation.annotationType().equals(annotationType)) {\n                found.add((T) annotation);\n            }\n        }\n        return found;\n    }\n\n    static void validateParameters(Executable executable, Object[] params) {\n        int newParametersCount = Objects.requireNonNull(params).length;\n        Class<?>[] parameterTypes = executable.getParameterTypes();\n        if (parameterTypes.length != newParametersCount) {\n            throw new IllegalArgumentException(\n                    \"Wrong number of parameters - method has \" + Arrays.toString(parameterTypes) + \", attempting to set \"\n                            + Arrays.toString(params));\n        }\n        for (int i = 0; i < params.length; i++) {\n            if (parameterTypes[i].isPrimitive() && params[i] == null) {\n                throw new IllegalArgumentException(\"Trying to set a null value to a primitive parameter [position: \" + i\n                        + \", type: \" + parameterTypes[i] + \"]\");\n            }\n            if (params[i] != null) {\n                if (!Types.boxedClass(parameterTypes[i]).isAssignableFrom(Types.boxedClass(params[i].getClass()))) {\n                    throw new IllegalArgumentException(\"The parameter type [\" + params[i].getClass()\n                            + \"] can not be assigned to the type for the target method [\" + parameterTypes[i] + \"]\");\n                }\n            }\n        }\n    }\n\n    @Override\n    public Method getMethod() {\n        return null;\n    }\n\n    @Override\n    public Object getTarget() {","sourceCodeStart":50,"sourceCodeEnd":86,"githubUrl":"https://github.com/quarkusio/quarkus/blob/e1c734241f34c7919086ceb4c9262b4a58f6de44/independent-projects/arc/runtime/src/main/java/io/quarkus/arc/impl/AbstractInvocationContext.java#L50-L86","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","solutions":["Replace null with the primitive's default (0, 0L, false, etc.) at that position","Change the target method parameter to the boxed type (Integer, Long, Boolean) if null is meaningful","Validate the params array against declared types before calling setParameters"],"exampleFix":"// before\nctx.setParameters(new Object[] { null }); // method param is int\n// after\nctx.setParameters(new Object[] { 0 }); // or make param Integer","handlingStrategy":"validation","validationCode":"for (int i = 0; i < params.length; i++) {\n  if (method.getParameterTypes()[i].isPrimitive() && params[i] == null) params[i] = defaultPrimitive(method.getParameterTypes()[i]);\n}","typeGuard":null,"tryCatchPattern":"try { ctx.setParameters(args); } catch (IllegalArgumentException e) { /* null primitive at position i — supply defaults */ }","preventionTips":["Use boxed types when values may be null","Map missing values to primitive defaults during deserialization","Validate primitive params before reflective invocation"],"tags":["cdi","reflection","null-safety"],"backgroundTag":"null-for-primitive-parameter","analyzedSha":"e1c734241f34c7919086ceb4c9262b4a58f6de44","analyzedAt":"2026-09-05T17:01:29.979Z","contentChangedAt":"2026-09-05T17:01:29.979Z","schemaVersion":2},"datasetVersion":"2026-09-14T00:17:10.932Z"}