JavaMemoryModel: Re: Are this$x fields final?

From: Bill Pugh (
Date: Mon May 24 2004 - 19:42:09 EDT

Say we have:

class A {
  final int x = 17;
  class B {
         int getX() {
                 return x;
  static B b;

Initially, A.b is initialized to be some B object.

Then, we have two incorrectly synchronized threads that perform:

Thread 1:
A.b = new B()

Thread 2:
r1 = A.b.getX();

We should be able to say whether this code can throw a null pointer
exception or not.
If this$0 is implemented as a non-final field, the code fragment can
throw NullPointerException.
If this$0 is final, then r1 will always be 17.

The real question is whether or not synchronization is required in
order to ensure that
a thread will correctly see the surrounding instance of an object.


On May 24, 2004, at 6:17 PM, Gilad Bracha wrote:

> Bill,
> The JLS very deliberately doesn't talk about this$x fields. They are
> an implementation detail that has changed over time, and may go away
> some day.
> Bill Pugh wrote:
>> It isn't part of JSR-133.
> Indeed, it better not be.
>> Is that the case? The 1.1.8 inner class specification doesn't say so
>> (and gives an example
>> where it isn't final).
> The old inner class spec has been obsolete for 4 years. It is entirely
> subsumed by the JLS 2nd edition. We don't care what it says.
> --
> Cheers, Gilad
> <gilad.bracha.vcf>

JavaMemoryModel mailing list -

This archive was generated by hypermail 2b29 : Thu Oct 13 2005 - 07:01:07 EDT