When http://www.cs.umd.edu/~pugh/java/memoryModel/jsr-133-faq.html#finalRight says
The values for an object's final fields are set in its constructor. Assuming the object is constructed "correctly", once an object is constructed, the values assigned to the final fields in the constructor will be visible to all other threads without synchronization. In addition, the visible values for any other object or array referenced by those final fields will be at least as up-to-date as the final fields. What does it mean for an object to be properly constructed? It simply means that no reference to the object being constructed is allowed to "escape" during construction.
Does it mean that only the thread that had seen an improperly constructed object might see it in a bad state but all other threads are fine?
For example say you have some simple code
public class Foo {
final int x = 5;
public Foo() {
new Thread(() -> System.out.print(x)).start();
}
}
Does that mean that only that thread that had seen the implicit this
reference might have visibility issues, but any other threads to come that use the instance of Foo is guaranteed to see a perfectly visible Foo reference and its field x
to be 5?
The JLS states,
An object is considered to be completely initialized when its constructor finishes. A thread that can only see a reference to an object after that object has been completely initialized is guaranteed to see the correctly initialized values for that object's
final
fields.
There's no indication that the visibility guarantee toward one thread would be affected by unsafe publication with respect to another thread.