{"record":{"id":"6ddd776afc890198","repo":"oracle/graal","slug":"expected-an-espressoexternalresolvedjavamethod-go","errorCode":null,"errorMessage":"Expected an EspressoExternalResolvedJavaMethod, got {}","messagePattern":"Expected an EspressoExternalResolvedJavaMethod, 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/EspressoExternalVMAccess.java","lineNumber":516,"sourceCode":"    @Override\n    public boolean owns(ResolvedJavaType value) {\n        return value instanceof Element;\n    }\n\n    @Override\n    public boolean owns(ResolvedJavaMethod value) {\n        return value instanceof Element;\n    }\n\n    @Override\n    public boolean owns(ResolvedJavaField value) {\n        return value instanceof Element;\n    }\n\n    @Override\n    public JavaConstant invoke(ResolvedJavaMethod method, JavaConstant receiver, JavaConstant... arguments) {\n        if (!(method instanceof EspressoExternalResolvedJavaMethod espressoMethod)) {\n            throw new IllegalArgumentException(\"Expected an EspressoExternalResolvedJavaMethod, got \" + safeGetClass(method));\n        }\n        return espressoMethod.invoke(receiver, arguments);\n    }\n\n    @Override\n    public void writeField(ResolvedJavaField field, JavaConstant receiver, JavaConstant value) {\n        if (!(field instanceof EspressoExternalResolvedJavaField espressoField)) {\n            throw new IllegalArgumentException(\"Expected an EspressoExternalResolvedJavaField, got \" + safeGetClass(field));\n        }\n        espressoField.writeValue(receiver, value);\n    }\n\n    @Override\n    public JavaConstant asArrayConstant(ResolvedJavaType componentType, JavaConstant... elements) {\n        if (!(componentType.getArrayClass() instanceof EspressoExternalResolvedArrayType arrayType)) {\n            throw new IllegalArgumentException(\"Invalid component type\");\n        }\n        EspressoResolvedJavaType elementalType = arrayType.getElementalType();","sourceCodeStart":498,"sourceCodeEnd":534,"githubUrl":"https://github.com/oracle/graal/blob/a66e9ccd1d7bf2552883939aa0788dfd0e294aab/espresso-compiler-stub/src/com.oracle.truffle.espresso.vmaccess/src/com/oracle/truffle/espresso/vmaccess/EspressoExternalVMAccess.java#L498-L534","documentation":"EspressoExternalVMAccess.invoke(method, receiver, args) can only execute methods it owns — those represented by EspressoExternalResolvedJavaMethod, which carry a guest Truffle Value that can be reflectively invoked. Any other ResolvedJavaMethod implementation (HotSpot-based, proxy, or from another context) has no guest Value, so the call is rejected with IllegalArgumentException before any execution is attempted.","triggerScenarios":"Calling vmAccess.invoke() with a ResolvedJavaMethod obtained from host HotSpot meta access, a mocking/stub implementation, or a second Espresso context's provider.","commonSituations":"Foreign-call setup in substitutions that resolves methods via the wrong MetaAccessProvider; test harnesses that pass mocked ResolvedJavaMethod objects; refactors that share method handles across contexts.","solutions":["Resolve the method through this Espresso provider (lookupMethod / resolve on Espresso types) before invoking.","Guard with method instanceof EspressoExternalResolvedJavaMethod (or owns(method)) and route foreign methods to their own invocation path.","In tests, build methods via the Espresso external meta access rather than mocking the interface."],"exampleFix":"// before\nJavaConstant r = vmAccess.invoke(method, receiver, args);\n\n// after\nif (vmAccess.owns(method)) {\n    JavaConstant r = vmAccess.invoke(method, receiver, args);\n} else {\n    JavaConstant r = foreignInvoke(method, receiver, args);\n}","handlingStrategy":"type-guard","validationCode":"if (!(method instanceof EspressoExternalResolvedJavaMethod)) {\n    // re-resolve via this provider or route to foreign invocation\n}","typeGuard":"static boolean isEspressoMethod(ResolvedJavaMethod m) {\n    return m instanceof EspressoExternalResolvedJavaMethod;\n}","tryCatchPattern":"catch (IllegalArgumentException e) with 'Expected an EspressoExternalResolvedJavaMethod' -> re-resolve the method through Espresso meta access and retry once.","preventionTips":["Always resolve invocable methods via the Espresso meta access that owns the receiver type.","Never mock ResolvedJavaMethod in tests.","Log method.getClass() when routing fails to identify the foreign provider."],"tags":["jvmci","espresso","graalvm","reflection","method-invocation"],"backgroundTag":null,"analyzedSha":"a66e9ccd1d7bf2552883939aa0788dfd0e294aab","analyzedAt":"2026-08-14T13:58:47.161Z","schemaVersion":2},"datasetVersion":"2026-08-15T17:31:12.345Z"}