JDK-4158906 : NullPointerException accessing outer class variable
  • Type: Bug
  • Component: tools
  • Sub-Component: javac
  • Affected Version: 1.1.5,1.1.6,1.2.0
  • Priority: P4
  • Status: Closed
  • Resolution: Duplicate
  • OS: solaris_2.6,windows_nt
  • CPU: x86,sparc
  • Submitted: 1998-07-20
  • Updated: 1998-07-28
  • Resolved: 1998-07-28
Related Reports
Duplicate :  
Description

Name: bk70084			Date: 07/20/98


Try running the following code.  The bang() function
in bar2 will cause a NullPointerException, even though the
access is completely correct.  I would guess it has something to
do with the subclassing from bar1, which is not an inner class


class bar1 {
    bar1() {
        bang();
    }

    void bang() {
    }
}

class foo {
    String i = "hi";

    class bar2 extends bar1 {
	bar2() {
	    super();
	}

	void bang() {
            System.out.println("outer instance is "+foo.this);  // will print null
	    System.out.println("i is "+i); // will throw NullPointerException
	}
    }

    foo() {
	new bar2();
    }	

    public static void main(String argv[]) {
        new foo();
    }
}
(Review ID: 29780)
======================================================================

Comments
WORK AROUND Name: bk70084 Date: 07/20/98 none. ======================================================================
11-06-2004

EVALUATION Sheng says this looks very much like a inner class compiler bug where the class of the pointer to the enclosing scope was not getting initialized. anand.palaniswamy@Eng 1998-07-27
27-07-1998