{"record":{"id":"1e3e569e47adaedc","repo":"oracle/graal","slug":"for-instance-fields-the-receiver-argument-must-no-1e3e56","errorCode":null,"errorMessage":"For instance fields, the receiver argument must not represent a null constant","messagePattern":"For instance fields, the receiver argument must not represent a null constant","errorType":"exception","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"compiler/src/jdk.graal.compiler.hostvmaccess/src/jdk/graal/compiler/hostvmaccess/HostVMAccess.java","lineNumber":232,"sourceCode":"            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;\n        } else {\n            unboxedReceiver = snippetReflection.asObject(reflectionField.getDeclaringClass(), receiver);","sourceCodeStart":214,"sourceCodeEnd":250,"githubUrl":"https://github.com/oracle/graal/blob/a66e9ccd1d7bf2552883939aa0788dfd0e294aab/compiler/src/jdk.graal.compiler.hostvmaccess/src/jdk/graal/compiler/hostvmaccess/HostVMAccess.java#L214-L250","documentation":"Thrown by HostVMAccess.writeField when writing an instance field with a receiver constant that represents null (receiver.isNull()). Reflection cannot store a field on a null object, so the null constant is rejected explicitly even though the reference itself is non-null.","triggerScenarios":"Calling writeField(instanceField, JavaConstant.NULL_POINTER, value) or any constant produced by forObject(null), for a non-static field.","commonSituations":"Uniform wrapping of possibly-null holders via snippetReflection.forObject(holder) which silently yields the null constant; guest-level null receivers reaching host field stores during snippet unfolding.","solutions":["Guard before the call: if the receiver constant isNull(), raise the guest NullPointerException explicitly or skip the store","Only call forObject on non-null holders; keep null as a literal null reference reserved for static fields","Validate holder objects at the source (lookup/creation) so null never reaches writeField"],"exampleFix":"// before\nhostVM.writeField(instanceField, snippetReflection.forObject(maybeNullHolder), value);  // throws\n\n// after\nif (maybeNullHolder == null) {\n    throw new NullPointerException(\"holder\"); // explicit semantics\n}\nhostVM.writeField(instanceField, snippetReflection.forObject(maybeNullHolder), value);","handlingStrategy":"type-guard","validationCode":"if (receiver != null && receiver.isNull() && !field.isStatic()) {\n    throw new NullPointerException(\"null holder for instance field \" + field);","typeGuard":"static boolean isNullConstant(JavaConstant c) { return c != null && c.isNull(); }","tryCatchPattern":"catch (IllegalArgumentException e) { translate to guest NPE semantics }","preventionTips":["Do not forward forObject(null) results as receivers","Keep null constants reserved for value slots, not receivers","Fold null checks before field stores"],"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"}