---
spec: JVMS
title: "The Java Virtual Machine Specification"
edition: "Java SE 25 Edition"
java_version: 25
chapter: "Chapter 4. The class File Format"
section: "4.10.1.9.putfield"
heading: "putfield"
parent: "4.10.1.9. Type Checking Instructions"
source: https://docs.oracle.com/javase/specs/jvms/se25/html/jvms-4.html#jvms-4.10.1.9.putfield
id: "4.10.1.9.putfield"
url: https://jvm.obfuscated.software/jvms/se25/4.10.1.9.putfield.html
raw: https://jvm.obfuscated.software/jvms/se25/4.10.1.9.putfield.md
---

# putfield

A *putfield* instruction with operand `CP` is type safe iff all of the following are true:

- Its first operand, `CP`, refers to a constant pool entry denoting a field whose declared type is `FieldType` that is a member of a type `FieldClassType`.

- Either:

  - One can validly pop types matching `FieldType` and `FieldClassType` off the incoming operand stack yielding the outgoing type state.
  - `protected` fields are subject to additional checks ([§4.10.1.8](4.10.1.8.md)).

```
instructionIsTypeSafe(putfield(CP), Environment, _Offset, StackFrame,
                      NextStackFrame, ExceptionStackFrame) :-
    CP = field(FieldClassType, FieldName, FieldDescriptor),
    parseFieldDescriptor(FieldDescriptor, FieldType),
    canPop(StackFrame, [FieldType], PoppedFrame),
    passesProtectedCheck(Environment, FieldClassType, FieldName,
                         FieldDescriptor, PoppedFrame),
    canPop(StackFrame, [FieldType, FieldClassType], NextStackFrame),
    exceptionStackFrame(StackFrame, ExceptionStackFrame).
```

- Or:

  - If the instruction occurs in an instance initialization method of the class named by `FieldClassType` and assigns to a field declared by the class, then one can validly pop types matching `FieldType` and `uninitializedThis` off the incoming operand stack yielding the outgoing type state. This allows instance fields of `this` that are declared in the current class to be assigned prior to complete initialization of `this`.

```
instructionIsTypeSafe(putfield(CP), Environment, _Offset, StackFrame,
                      NextStackFrame, ExceptionStackFrame) :-
    CP = field(FieldClassType, FieldName, FieldDescriptor),
    thisType(Environment, FieldClassType),
    Environment = environment(CurrentClass, CurrentMethod, _, _, _, _),
    methodName(CurrentMethod, '<init>'),
    classDeclaresMember(CurrentClass, FieldName, FieldDescriptor),
    parseFieldDescriptor(FieldDescriptor, FieldType),
    canPop(StackFrame, [FieldType, uninitializedThis], NextStackFrame),
    exceptionStackFrame(StackFrame, ExceptionStackFrame).
```
