---
spec: JVMS
title: "The Java Virtual Machine Specification"
edition: "Java SE 25 Edition"
java_version: 25
chapter: "Chapter 6. The Java Virtual Machine Instruction Set"
section: "6.5.putfield"
heading: "putfield"
parent: "6.5. Instructions"
source: https://docs.oracle.com/javase/specs/jvms/se25/html/jvms-6.html#jvms-6.5.putfield
id: "6.5.putfield"
url: https://jvm.obfuscated.software/jvms/se25/6.5.putfield.html
raw: https://jvm.obfuscated.software/jvms/se25/6.5.putfield.md
---

# putfield

## Operation

Set field in object

## Format

```
putfield
indexbyte1
indexbyte2
```

## Forms

*putfield* = 181 (0xb5)

## Operand Stack

..., *objectref*, *value* →

...

## Description

The unsigned *indexbyte1* and *indexbyte2* are used to construct an index into the run-time constant pool of the current class ([§2.6](2.6.md)), where the value of the index is (*indexbyte1* `<<` 8) | *indexbyte2*. The run-time constant pool entry at the index must be a symbolic reference to a field ([§5.1](5.1.md)), which gives the name and descriptor of the field as well as a symbolic reference to the class in which the field is to be found. The referenced field is resolved ([§5.4.3.2](5.4.3.2.md)).

The type of a *value* stored by a *putfield* instruction must be compatible with the descriptor of the referenced field ([§4.3.2](4.3.2.md)). If the field descriptor type is `boolean`, `byte`, `char`, `short`, or `int`, then the *value* must be an `int`. If the field descriptor type is `float`, `long`, or `double`, then the *value* must be a `float`, `long`, or `double`, respectively. If the field descriptor type is a class type or an array type, then the *value* must be a value of the field descriptor type. If the field is `final`, it must be declared in the current class, and the instruction must occur in an instance initialization method of the current class ([§2.9.1](2.9.1.md)).

The *value* and *objectref* are popped from the operand stack.

The *objectref* must be of type `reference` but not an array type.

If the *value* is of type `int` and the field descriptor type is one of `byte`, `char`, `short`, or `boolean`, then the `int` *value* is converted to the field descriptor type as follows. If the field descriptor type is `byte`, `char`, or `short`, then the `int` *value* is truncated to a value of the field descriptor type, *value*'. If the field descriptor type is `boolean`, then the `int` *value* is narrowed by taking the bitwise AND of *value* and 1, resulting in *value*'. The referenced field in *objectref* is set to *value*'.

Otherwise, the referenced field in *objectref* is set to *value*.

## Linking Exceptions

During resolution of the symbolic reference to the field, any of the exceptions pertaining to field resolution ([§5.4.3.2](5.4.3.2.md)) can be thrown.

Otherwise, if the resolved field is a `static` field, *putfield* throws an `IncompatibleClassChangeError`.

Otherwise, if the resolved field is `final`, it must be declared in the current class, and the instruction must occur in an instance initialization method of the current class. Otherwise, an `IllegalAccessError` is thrown.

## Run-time Exception

Otherwise, if *objectref* is `null`, the *putfield* instruction throws a `NullPointerException`.
