Scrivio Interview library
ConceptFoundations7 min read · updated 12 November 2026

What does the Java Memory Model guarantee about final fields, and when does that guarantee break?

If an object is properly constructed, meaning this does not escape during the constructor, then any thread that obtains a reference to it sees the values its final fields were given in the constructor, without any synchronization, and objects reachable through a final field are seen at least as up to date as at the end of the constructor. The guarantee breaks if this escapes during construction, and non-final fields get no such guarantee when the object is published through a data race. This is why immutable objects with final fields are safe to share.

Why this question is asked

Most of us use final to say that a field is assigned once. In concurrent code it means much more: it is the only way a Java object can be shared safely without any synchronization at all. That is what makes String, Integer and records safe to pass around freely. Interviewers ask about it because the guarantee is precise and has a clear condition, and because the cases where it breaks are common in real code. In this answer, we will see what problem the guarantee solves, state exactly what it promises, see how it extends to objects reachable through final fields, and look at the two ways to lose it.

1The Problem Final Fields Solve

When one thread creates an object and stores the reference in a plain shared field, another thread may read that field with no happens-before edge connecting the two. The Java Memory Model then allows the reader to see the reference before it sees the writes the constructor made, so it can read default values, 0, false or null, from an object that was fully built on the writer's side. Normally we avoid this with safe publication, such as a volatile field or a lock.

Final fields give a second line of defence that does not depend on how the reference was published. This was added by JSR-133 in Java 5, mainly so that immutable objects like String could not appear to change their value when shared through a data race, which mattered for security as well as correctness.

2What the Guarantee Says

The rule has a condition and a promise. The condition is that the object is properly constructed: no reference to it escapes before the constructor finishes. The promise is that a thread that obtains a reference to the object, after the constructor finishes, sees each final field with the value the constructor assigned, even if the reference reached it through a data race.

Java
final class Point {
final int x;
int y; // not final
Point(int x, int y) { this.x = x; this.y = y; }
}
static Point shared; // plain field, published racily
// Thread 1
shared = new Point(3, 4);
// Thread 2
Point p = shared;
if (p != null) {
System.out.println(p.x); // 3, guaranteed by the final field rule
System.out.println(p.y); // 4 or 0: no guarantee for a non-final field
}

The JVM implements this with what the specification calls a freeze at the end of the constructor: the final field writes are ordered before the reference can be seen by other threads. In practice, the JIT emits a store-store barrier at the end of a constructor that writes final fields on platforms that need one. On x86 that barrier is free, because stores are already kept in order, but the JIT still must not reorder the writes.

3Objects Reachable Through a Final Field

The guarantee is deeper than the field itself. Objects reached through a final field are seen as at least as up to date as they were at the end of the constructor. So if the constructor fills an array or a list and stores it in a final field, another thread sees the contents as they were at that point.

Java
final class Palette {
private final int[] colors;
Palette() {
int[] c = new int[3];
c[0] = 0xFF0000; c[1] = 0x00FF00; c[2] = 0x0000FF; // writes before the freeze
this.colors = c;
}
int first() { return colors[0]; } // 0xFF0000 for every thread, even via a race
}
What another thread sees after a racy publication
FieldGuaranteed valueWhy
final int xConstructor's valueFinal field freeze
final int[] colors, contentsAs at constructor endReachable through a final field
Non-final int yNone, may be 0No happens-before, no freeze
Change after constructionNoneOutside the guarantee

Notice the limit. Only writes made before the end of the constructor are covered. If some method later changes colors[0], that change is an ordinary write to an array element with no guarantee at all for other threads. So the reachable objects must not change after construction for the object to be safe to share without synchronization.

4When the Guarantee Breaks: this Escapes

The condition, properly constructed, is where most real failures come from. If the constructor lets this escape, by registering it as a listener, storing it in a static field, starting a thread that uses it, or passing a lambda that captures it, another thread can obtain the reference before the constructor ends. For that thread, the final fields may not be set yet, and the specification gives no guarantee at all.

Java
class Service {
static Service last;
private final Map<String, Rule> rules;
Service(Map<String, Rule> input) {
last = this; // this escapes before rules is set
this.rules = Map.copyOf(input);
}
}
// Another thread reading Service.last.rules may see null, even though rules is final

The fix is always to finish construction first and only then expose the object, for example in a static factory method or a separate start() step. Combined with final fields, that gives objects that are safe to share no matter how the reference travels.

5Why Immutable Objects Are Safe to Share

Put together, these rules explain why immutable objects are the easiest way to write thread-safe code. If every field is final, the constructor does not let this escape, and nothing reachable through the fields changes after construction, then every thread that obtains the object sees exactly its constructed state, and nothing ever changes it afterwards. No locks, no volatile, no reasoning about publication. This is how String, the boxed primitives, java.time types and records with immutable components work. Records make the pattern concise, because their fields are final by definition, though their components must be immutable too, which is why lists passed in should be copied with List.copyOf.

6Follow-up questions

Do final fields make an object immutable?

Only shallowly. A final field cannot be reassigned, but the object it points to can still change if it is mutable, such as an ArrayList. For real immutability, the referenced objects must also be immutable, or be private copies that nothing modifies after construction.

Does the guarantee hold if we set a final field with reflection?

No. The guarantee covers values written in the constructor before the freeze. Changing a final field afterwards through reflection is outside it, other threads may not see the change, and the JIT may even have constant-folded the old value. Recent JDKs restrict modifying final fields by reflection, so check your JDK's behaviour, and prefer setting such fields through a constructor.

Is safe publication still needed for objects with final fields?

For objects whose state is entirely in final fields and never changes, no; that is the point of the guarantee. For objects that also have non-final fields, or whose reachable objects change later, yes. Safe publication through volatile, a lock or a concurrent collection covers the whole state at the time of publication, not only the final fields.

7Conclusion

In this answer, we saw that the final field guarantee lets any thread that obtains a reference to a properly constructed object see its final fields as the constructor set them, without synchronization, and see objects reachable through them as at least as up to date as at the end of the constructor. It breaks if this escapes during construction, non-final fields get no such guarantee under racy publication, and later changes are never covered. Immutable objects with final fields and no escaping this are therefore safe to share freely.

What to say in the interviewAbout 100 seconds aloud

Open with

The final field guarantee says that if an object is properly constructed, meaning no reference to it escapes before the constructor finishes, then any thread that gets a reference to it sees the final fields with the values the constructor set, without any synchronization, even if the reference was published through a data race.

Then, if they want more

It goes one level deeper as well: objects reachable through a final field, like an array or list the constructor filled in, are seen at least as up to date as they were at the end of the constructor.

The JVM implements this as a freeze at the end of the constructor, so the final field writes are ordered before the reference becomes visible. Non-final fields have no such guarantee: if I publish an object through a plain field, another thread can see the reference and still read zero or null from a non-final field.

The guarantee breaks in two common ways. If this escapes during construction, by registering a listener, starting a thread, or storing this in a static field, another thread can see the object before the freeze and the final fields may not be set.

And changes made after construction, either to objects reachable through final fields or to finals via reflection, are not covered. That is why immutable objects, all fields final, built without letting this escape, and nothing changing afterwards, are safe to share between threads freely.

String, the java.time classes and records with immutable components work that way, and it is why I default to records with List.copyOf for shared value objects.

About this answer

Last updated
12 November 2026
Versions it names
Java 5
Checked
Its structure and format are checked automatically. Use it as a carefully prepared study note: where a detail matters, confirm it against the documentation below. What the checks cover
Where the question comes from
Written by Scrivio for practice. It is not taken from an interview.
Official documentation
JLS chapter 17, Threads and Locks
Report an issue with this answer

Copy the line below and send it to the author with what you found. It carries the address of this page.

Issue with "What does the Java Memory Model guarantee about final fields, and when does that...": https://scrivio-interview-library.netlify.app/java/java-memory-model/5ce7d4f7ae/