oracle/graal · error · NullPointerException
For instance fields, the receiver argument must not be null
Error message
For instance fields, the receiver argument must not be null
What it means
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.
Source
Thrown at compiler/src/jdk.graal.compiler.hostvmaccess/src/jdk/graal/compiler/hostvmaccess/HostVMAccess.java:230
throw new InvocationException(snippetReflection.forObject(cause), cause);
} catch (IllegalAccessException e) {
throw new RuntimeException("Should not reach here", e);
}
}
@Override
public void writeField(ResolvedJavaField field, JavaConstant receiver, JavaConstant value) {
SnippetReflectionProvider snippetReflection = providers.getSnippetReflection();
Field reflectionField = snippetReflection.originalField(field);
makeAccessible(reflectionField);
var fieldKind = field.getJavaKind();
if (Modifier.isStatic(reflectionField.getModifiers())) {
if (receiver != null) {
throw new IllegalArgumentException("For static fields, the receiver argument must be null");
}
} else if (receiver == null) {
throw new NullPointerException("For instance fields, the receiver argument must not be null");
} else if (receiver.isNull()) {
throw new IllegalArgumentException("For instance fields, the receiver argument must not represent a null constant");
}
Object unboxedValue;
if (fieldKind.isObject()) {
unboxedValue = snippetReflection.asObject(reflectionField.getType(), value);
} else {
assert fieldKind.isPrimitive();
if (fieldKind != value.getJavaKind()) {
throw new IllegalArgumentException("Expected value kind " + fieldKind + " but got " + value.getJavaKind());
}
unboxedValue = value.asBoxedPrimitive();
}
Object unboxedReceiver;
if (Modifier.isStatic(reflectionField.getModifiers())) {
unboxedReceiver = null;View on GitHub (pinned to a66e9ccd1d)
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
Example fix
// before Object holder = maybeNull; hostVM.writeField(instanceField, holder == null ? null : snippetReflection.forObject(holder), value); // after Objects.requireNonNull(holder, "holder for instance field write"); hostVM.writeField(instanceField, snippetReflection.forObject(holder), value);
Defensive patterns
Strategy: validation
Validate before calling
if (!field.isStatic() && receiver == null) {
throw new NullPointerException("receiver required for instance field " + field); Try / catch
catch (NullPointerException e) { fail fast naming the field; fix the null holder at its source } Prevention
- Objects.requireNonNull(holder) before forObject
- Never default instance-field receivers to null
- Validate holder lookups (map/class resolution) upstream
When it happens
Trigger: Calling writeField(instanceField, null, value) where the reflective Field is non-static.
Common situations: 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.
Related errors
- For instance fields, the receiver argument must not represen
- For instance methods, the receiver argument must not be null
- For instance methods, the receiver argument must not represe
- For static fields, the receiver argument must be null
- Expected value kind {} but got {}
AI-assisted analysis of oracle/graal@a66e9ccd1d (2026-08-14).
Data as JSON: /api/errors/c72743388df13ee3.
Report an issue: GitHub.