{"record":{"id":"17493e955f17e40b","repo":"oracle/graal","slug":"bad-argument-kind-at-index-expected-long-got","errorCode":null,"errorMessage":"Bad argument kind at index {}: expected Long, got {}","messagePattern":"Bad argument kind at index (.+?): expected Long, 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":348,"sourceCode":"                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);\n                };\n                case Object -> {\n                    if (argument.isNull()) {\n                        yield null;\n                    }","sourceCodeStart":330,"sourceCodeEnd":366,"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#L330-L366","documentation":"Thrown by the argument marshalling switch in EspressoExternalResolvedJavaMethod.invoke when a parameter is declared long but the argument constant's kind is not in {Long, Int, Char, Short, Byte}. All subword integral kinds widen to long (JLS 5.1.2); Float, Double, Boolean, and Object constants are rejected because converting them to long is either lossy or invalid under strict invocation. The index in the message identifies which parameter mismatches.","triggerScenarios":"Passing JavaConstant.forDouble/forFloat to a long parameter; passing a Boolean constant; passing an EspressoExternalObjectConstant where a long is declared (argument order shifted).","commonSituations":"Argument array misalignment (extra/missing element earlier shifts an Object into a long slot); signature drift between guest class versions; interop bridges that represent all numbers as doubles.","solutions":["Convert explicitly when narrowing from double: JavaConstant.forLong((long) d.asDouble())","Verify the argument array is aligned to getSignature().getParameterCount(false) with no receiver included","If a Float constant is intended for a long parameter, rebox via forLong(argument.asLong()-compatible path) after explicit cast"],"exampleFix":"// before\nargs[i] = JavaConstant.forDouble(seconds); // parameter is long\n\n// after\nargs[i] = JavaConstant.forLong((long) seconds);","handlingStrategy":"validation","validationCode":"JavaKind ak = args[i].getJavaKind();\nif (signature.getParameterKind(i) == JavaKind.Long && !(ak == JavaKind.Long || ak == JavaKind.Int || ak == JavaKind.Char || ak == JavaKind.Short || ak == JavaKind.Byte)) {\n    throw new IllegalStateException(\"argument \" + i + \" cannot widen to long; got \" + ak);\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["All integral subwords widen to long automatically; floating-point does not","Double-to-long requires an explicit cast and forLong","An Object constant at a long slot means the argument array is shifted — verify alignment"],"tags":["espresso","jvmci","method-invocation","javakind","long","widening"],"backgroundTag":null,"analyzedSha":"a66e9ccd1d7bf2552883939aa0788dfd0e294aab","analyzedAt":"2026-08-14T13:58:47.161Z","schemaVersion":2},"datasetVersion":"2026-08-15T17:31:12.345Z"}