{"record":{"id":"7d2a167b00d164df","repo":"oracle/graal","slug":"bad-argument-kind-at-index-expected-int-got","errorCode":null,"errorMessage":"Bad argument kind at index {}: expected Int, got {}","messagePattern":"Bad argument kind at index (.+?): expected Int, got (.+?)","errorType":"validation","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"espresso-compiler-stub/src/com.oracle.truffle.espresso.vmaccess/src/com/oracle/truffle/espresso/vmaccess/EspressoExternalResolvedJavaMethod.java","lineNumber":343,"sourceCode":"                case Byte -> switch (argumentKind) {\n                    case Byte -> argument.asInt();\n                    default ->\n                        throw new IllegalArgumentException(\"Bad argument kind at index \" + i + \": expected Byte, got \" + argumentKind);\n                };\n                case Char -> switch (argumentKind) {\n                    case Char -> argument.asInt();\n                    default ->\n                        throw new IllegalArgumentException(\"Bad argument kind at index \" + i + \": expected Char, got \" + argumentKind);\n                };\n                case Short -> switch (argumentKind) {\n                    case Short, Byte -> argument.asInt();\n                    default ->\n                        throw new IllegalArgumentException(\"Bad argument kind at index \" + i + \": expected Short, got \" + argumentKind);\n                };\n                case Int -> switch (argumentKind) {\n                    case Int, Char, Short, Byte -> argument.asInt();\n                    default ->\n                        throw new IllegalArgumentException(\"Bad argument kind at index \" + i + \": expected Int, got \" + argumentKind);\n                };\n                case Long -> switch (argumentKind) {\n                    case Long, Int, Char, Short, Byte -> argument.asLong();\n                    default ->\n                        throw new IllegalArgumentException(\"Bad argument kind at index \" + i + \": expected Long, got \" + argumentKind);\n                };\n                case Float -> switch (argumentKind) {\n                    case Long, Int, Char, Short, Byte -> (float) argument.asLong();\n                    case Float -> argument.asFloat();\n                    default ->\n                        throw new IllegalArgumentException(\"Bad argument kind at index \" + i + \": expected Float, got \" + argumentKind);\n                };\n                case Double -> switch (argumentKind) {\n                    case Long, Int, Char, Short, Byte -> (double) argument.asLong();\n                    case Float -> (double) argument.asFloat();\n                    case Double -> argument.asDouble();\n                    default ->\n                        throw new IllegalArgumentException(\"Bad argument kind at index \" + i + \": expected Double, got \" + argumentKind);","sourceCodeStart":325,"sourceCodeEnd":361,"githubUrl":"https://github.com/oracle/graal/blob/a66e9ccd1d7bf2552883939aa0788dfd0e294aab/espresso-compiler-stub/src/com.oracle.truffle.espresso.vmaccess/src/com/oracle/truffle/espresso/vmaccess/EspressoExternalResolvedJavaMethod.java#L325-L361","documentation":"Thrown by the argument marshalling switch in EspressoExternalResolvedJavaMethod.invoke when a parameter is declared int but the argument constant's kind is not one of Int, Char, Short, Byte. The adapter widens all subword integral kinds to int (JLS 5.1.2), matching bytecode stack semantics, but rejects Long, Float, Double, Boolean, and Object constants — those cannot reach an int parameter under strict invocation without an explicit cast.","triggerScenarios":"Passing a Long constant (e.g. from a long literal or forLong-based helper) to an int parameter; passing a Boolean or object constant where an int is declared; Float/Double constants for an int slot.","commonSituations":"APIs that changed a parameter from long to int (or vice versa) between guest versions while callers kept forLong; uniform long-based constant helpers; misaligned argument arrays after an arity fix.","solutions":["Convert explicitly: JavaConstant.forInt((int) c.asLong()) when the narrowing is intended","Re-resolve the method signature if a guest class changed a parameter type","Double-check argument index alignment — an off-by-one shift often surfaces as this error at an unexpected index"],"exampleFix":"// before\nargs[i] = JavaConstant.forLong(v); // parameter is int\n\n// after\nargs[i] = JavaConstant.forInt((int) v);","handlingStrategy":"validation","validationCode":"JavaKind pk = signature.getParameterKind(i);\nif (pk == JavaKind.Int && args[i].getJavaKind() != JavaKind.Int\n    && args[i].getJavaKind().isPrimitiveWord\n    && args[i].getJavaKind() != JavaKind.Long /* Long needs explicit cast */) {\n    args[i] = JavaConstant.forInt(args[i].asInt());\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Int accepts Int/Char/Short/Byte; Long, Float, Double, Boolean, Object are rejected","long-to-int needs an explicit (int) cast and forInt reboxing","A kind mismatch at a surprising index usually means argument misalignment — check arity first"],"tags":["espresso","jvmci","method-invocation","javakind","int","widening"],"backgroundTag":null,"analyzedSha":"a66e9ccd1d7bf2552883939aa0788dfd0e294aab","analyzedAt":"2026-08-14T13:58:47.161Z","schemaVersion":2},"datasetVersion":"2026-08-15T17:31:12.345Z"}