{"record":{"id":"fdf79d25e3470997","repo":"oracle/graal","slug":"expected-an-espressoexternalresolvedjavafield-got","errorCode":null,"errorMessage":"Expected an EspressoExternalResolvedJavaField, got {}","messagePattern":"Expected an EspressoExternalResolvedJavaField, 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":524,"sourceCode":"    }\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();\n        Value array;\n        boolean isPrimitiveArray;\n        int dimensions = arrayType.getDimensions();\n        if (elementalType instanceof EspressoExternalResolvedInstanceType elementalInstanceType) {\n            array = invokeJVMCIHelper(\"newObjectArray\", elementalInstanceType.getMetaObject(), dimensions, elements.length);\n            isPrimitiveArray = false;\n        } else {\n            JavaKind javaKind = elementalType.getJavaKind();","sourceCodeStart":506,"sourceCodeEnd":542,"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#L506-L542","documentation":"EspressoExternalVMAccess.writeField(field, receiver, value) requires an EspressoExternalResolvedJavaField because only that class exposes the guest field Value needed to perform the reflective store. Passing a field implementation from another JVMCI backend makes the write impossible, so it fails fast with IllegalArgumentException instead of silently writing to the wrong target.","triggerScenarios":"Calling vmAccess.writeField() with a ResolvedJavaField resolved through the host HotSpot provider or a hand-rolled/stub field object.","commonSituations":"Snippet parameter patching and foreign-object initialization that mix providers; test doubles implementing ResolvedJavaField; cross-context field writes in polyglot embeddings.","solutions":["Resolve the field on an Espresso-resolved type so you get an EspressoExternalResolvedJavaField.","Check field instanceof EspressoExternalResolvedJavaField (or owns(field)) before writing; use the owning provider otherwise.","Avoid mocking ResolvedJavaField in tests; use the real Espresso meta access."],"exampleFix":"// before\nvmAccess.writeField(field, receiver, value);\n\n// after\nif (vmAccess.owns(field)) {\n    vmAccess.writeField(field, receiver, value);\n} else {\n    foreignAccess.writeField(field, receiver, value);\n}","handlingStrategy":"type-guard","validationCode":"if (!(field instanceof EspressoExternalResolvedJavaField)) {\n    // route to the owning provider's write path\n}","typeGuard":"static boolean isEspressoField(ResolvedJavaField f) {\n    return f instanceof EspressoExternalResolvedJavaField;\n}","tryCatchPattern":"catch (IllegalArgumentException e) with 'Expected an EspressoExternalResolvedJavaField' -> re-resolve the field on the Espresso type and retry.","preventionTips":["Resolve fields on Espresso-resolved types only.","Keep field writes within one provider boundary.","Audit substitution code for cross-provider field handles."],"tags":["jvmci","espresso","graalvm","reflection","fields"],"backgroundTag":null,"analyzedSha":"a66e9ccd1d7bf2552883939aa0788dfd0e294aab","analyzedAt":"2026-08-14T13:58:47.161Z","schemaVersion":2},"datasetVersion":"2026-08-15T17:31:12.345Z"}