{"record":{"id":"68d5a0bdd9e38455","repo":"oracle/graal","slug":"illegal-argument-type-arguments-of-type-co","errorCode":null,"errorMessage":"Illegal argument type: arguments[{}] of type {} could not be converted to a {}","messagePattern":"Illegal argument type: arguments\\[(.+?)\\] of type (.+?) could not be converted to a (.+?)","errorType":"exception","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"compiler/src/jdk.graal.compiler.hostvmaccess/src/jdk/graal/compiler/hostvmaccess/HostVMAccess.java","lineNumber":163,"sourceCode":"            throw new NullPointerException(\"For instance methods, the receiver argument must not be null\");\n        } else if (receiver.isNull()) {\n            throw new IllegalArgumentException(\"For instance methods, the receiver argument must not represent a null constant\");\n        }\n        if (parameterTypes.length != arguments.length) {\n            throw new IllegalArgumentException(\"Wrong number of arguments: expected \" + parameterTypes.length + \" but got \" + arguments.length);\n        }\n        Signature signature = method.getSignature();\n        Object[] unboxedArguments = new Object[parameterTypes.length];\n        for (int i = 0; i < unboxedArguments.length; i++) {\n            JavaKind parameterKind = signature.getParameterKind(i);\n            JavaConstant argument = arguments[i];\n            if (parameterKind.isObject()) {\n                if (argument.isNull()) {\n                    unboxedArguments[i] = null;\n                } else {\n                    unboxedArguments[i] = snippetReflection.asObject(parameterTypes[i], argument);\n                    if (unboxedArguments[i] == null) {\n                        throw new IllegalArgumentException(\n                                        \"Illegal argument type: arguments[\" + i + \"] of type \" + providers.getMetaAccess().lookupJavaType(arguments[i]).toClassName() +\n                                                        \" could not be converted to a \" + parameterTypes[i]);\n                    }\n                }\n            } else {\n                assert parameterKind.isPrimitive();\n                unboxedArguments[i] = argument.asBoxedPrimitive();\n            }\n        }\n        try {\n            if (isConstructor) {\n                Constructor<?> constructor = (Constructor<?>) executable;\n                return snippetReflection.forObject(constructor.newInstance(unboxedArguments));\n            } else {\n                Method reflectionMethod = (Method) executable;\n                Object unboxedReceiver;\n                if (Modifier.isStatic(reflectionMethod.getModifiers())) {\n                    unboxedReceiver = null;","sourceCodeStart":145,"sourceCodeEnd":181,"githubUrl":"https://github.com/oracle/graal/blob/a66e9ccd1d7bf2552883939aa0788dfd0e294aab/compiler/src/jdk.graal.compiler.hostvmaccess/src/jdk/graal/compiler/hostvmaccess/HostVMAccess.java#L145-L181","documentation":"Thrown by HostVMAccess.invoke when an object-typed argument constant cannot be unboxed to the declared parameter type: SnippetReflectionProvider.asObject(parameterType, argument) returned null, meaning the constant's runtime type is not assignable to the parameter. The message reports the offending index, the constant's actual class, and the expected parameter type.","triggerScenarios":"Calling invoke with arguments[i] whose wrapped object's class is incompatible with parameterTypes[i] — e.g. passing a String constant for an Integer parameter, or an object from a different class hierarchy. asObject only succeeds when the constant's type matches/extends the requested type.","commonSituations":"Building argument constants from folded snippet values whose static type is Object, version changes where a library method's parameter type was narrowed, or boxing mismatches (passing the boxed wrapper when a primitive overload vs object overload exist — the primitive path is handled by asBoxedPrimitive, so this throw means the wrong overload was selected).","solutions":["Read the message: it names arguments[i]'s actual class and the expected parameter type — convert the value before wrapping (e.g. cast/convert String to Integer)","Verify you resolved the intended overload; pick the overload whose parameter type matches your constant","For primitives, ensure the constant kind is primitive so the asBoxedPrimitive path is taken instead of the object path"],"exampleFix":"// before\n// target: void set(int v)\nhostVM.invoke(setMethod, receiver, snippetReflection.forObject(\"42\"));  // String vs int param -> throws\n\n// after\nhostVM.invoke(setMethod, receiver, JavaConstant.forInt(42));","handlingStrategy":"type-guard","validationCode":"for (int i = 0; i < args.length; i++) {\n    if (parameterTypes[i].isPrimitive() != args[i].getJavaKind().isPrimitive()) {\n        throw new IllegalArgumentException(\"kind mismatch at \" + i);\n    }\n}","typeGuard":"static boolean argMatches(JavaConstant c, Class<?> p, MetaAccessProvider m) {\n    return p.isInstance(m.getSnippetReflection() != null ? null : null); // use snippetReflection.asObject(p, c) != null as the real guard\n}","tryCatchPattern":"catch (IllegalArgumentException e) { parse the message for index/actual/expected types and convert the value accordingly }","preventionTips":["Pre-convert values to the parameter type before wrapping","Select overloads explicitly when primitive/object overloads coexist","Use primitive constants (forInt/forLong/...) for primitive parameters"],"tags":["graalvm","hostvmaccess","reflection","type-mismatch"],"backgroundTag":null,"analyzedSha":"a66e9ccd1d7bf2552883939aa0788dfd0e294aab","analyzedAt":"2026-08-14T13:58:47.161Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}