{"record":{"id":"c72743388df13ee3","repo":"oracle/graal","slug":"for-instance-fields-the-receiver-argument-must-no","errorCode":null,"errorMessage":"For instance fields, the receiver argument must not be null","messagePattern":"For instance fields, the receiver argument must not be null","errorType":"exception","errorClass":"NullPointerException","httpStatus":null,"severity":"error","filePath":"compiler/src/jdk.graal.compiler.hostvmaccess/src/jdk/graal/compiler/hostvmaccess/HostVMAccess.java","lineNumber":230,"sourceCode":"            throw new InvocationException(snippetReflection.forObject(cause), cause);\n        } catch (IllegalAccessException e) {\n            throw new RuntimeException(\"Should not reach here\", e);\n        }\n    }\n\n    @Override\n    public void writeField(ResolvedJavaField field, JavaConstant receiver, JavaConstant value) {\n        SnippetReflectionProvider snippetReflection = providers.getSnippetReflection();\n        Field reflectionField = snippetReflection.originalField(field);\n        makeAccessible(reflectionField);\n        var fieldKind = field.getJavaKind();\n\n        if (Modifier.isStatic(reflectionField.getModifiers())) {\n            if (receiver != null) {\n                throw new IllegalArgumentException(\"For static fields, the receiver argument must be null\");\n            }\n        } else if (receiver == null) {\n            throw new NullPointerException(\"For instance fields, the receiver argument must not be null\");\n        } else if (receiver.isNull()) {\n            throw new IllegalArgumentException(\"For instance fields, the receiver argument must not represent a null constant\");\n        }\n\n        Object unboxedValue;\n        if (fieldKind.isObject()) {\n            unboxedValue = snippetReflection.asObject(reflectionField.getType(), value);\n        } else {\n            assert fieldKind.isPrimitive();\n            if (fieldKind != value.getJavaKind()) {\n                throw new IllegalArgumentException(\"Expected value kind \" + fieldKind + \" but got \" + value.getJavaKind());\n            }\n            unboxedValue = value.asBoxedPrimitive();\n        }\n\n        Object unboxedReceiver;\n        if (Modifier.isStatic(reflectionField.getModifiers())) {\n            unboxedReceiver = null;","sourceCodeStart":212,"sourceCodeEnd":248,"githubUrl":"https://github.com/oracle/graal/blob/a66e9ccd1d7bf2552883939aa0788dfd0e294aab/compiler/src/jdk.graal.compiler.hostvmaccess/src/jdk/graal/compiler/hostvmaccess/HostVMAccess.java#L212-L248","documentation":"Thrown (as NullPointerException) by HostVMAccess.writeField when writing an instance field with a null receiver reference. An instance field store requires a target object; a literal null receiver is a programming error in the caller, distinct from passing the null constant.","triggerScenarios":"Calling writeField(instanceField, null, value) where the reflective Field is non-static.","commonSituations":"A generic setter that defaults receiver to null for static fields but is also reached on the instance path; holders becoming null after a failed lookup that was forwarded unchecked.","solutions":["Pass a real receiver constant: snippetReflection.forObject(instance)","Null-check the holder object before the call and fail fast with a clearer error if it is missing","If the field should be static, verify the resolved ResolvedJavaField really maps to a static Field"],"exampleFix":"// before\nObject holder = maybeNull;\nhostVM.writeField(instanceField, holder == null ? null : snippetReflection.forObject(holder), value);\n\n// after\nObjects.requireNonNull(holder, \"holder for instance field write\");\nhostVM.writeField(instanceField, snippetReflection.forObject(holder), value);","handlingStrategy":"validation","validationCode":"if (!field.isStatic() && receiver == null) {\n    throw new NullPointerException(\"receiver required for instance field \" + field);","typeGuard":null,"tryCatchPattern":"catch (NullPointerException e) { fail fast naming the field; fix the null holder at its source }","preventionTips":["Objects.requireNonNull(holder) before forObject","Never default instance-field receivers to null","Validate holder lookups (map/class resolution) upstream"],"tags":["graalvm","hostvmaccess","reflection","fields","null-safety"],"backgroundTag":null,"analyzedSha":"a66e9ccd1d7bf2552883939aa0788dfd0e294aab","analyzedAt":"2026-08-14T13:58:47.161Z","schemaVersion":2},"datasetVersion":"2026-08-15T17:31:12.345Z"}