Bug 27247

Summary: Missing generation for the qualifier in 1.4 mode
Product: [Eclipse Project] JDT Reporter: Olivier Thomann <Olivier_Thomann>
Component: CoreAssignee: Philipe Mulet <philippe_mulet>
Status: VERIFIED FIXED QA Contact:
Severity: normal    
Priority: P3    
Version: 2.1   
Target Milestone: 2.1 M4   
Hardware: PC   
OS: Windows 2000   
Whiteboard:

Description Olivier Thomann CLA 2002-11-27 10:57:04 EST
Using 1119, we have a case where we should throw a NPE earlier. We do it, but
too late (inside the member constructor).

class A {
	class B {
		B(int i) {
		}
	}
	public static void main(String[] args) {
		int i = 1;
		try {
			A t = null;
			t.new B(i++);
		} catch (NullPointerException e) {
			System.out.println(i);
		}
		try {
			((A) null).new B(i++);
		} catch (NullPointerException e) {
			System.out.println(i);
		}
	}
}

We generate a getClass() inside the member constructor, but it should be done
before the constructor call if we don't want the side effect on 'i' (i++). Javac
1.4.1 adds the getClass() call before the constructor call in the outer class A.
I can give the bytecodes if needed.

In this case, the expected output is:
1
1
But we have:
2
3

In 1.3 mode, we don't throw any exception at all. Javac 1.3 has the same issue.
Comment 1 Philipe Mulet CLA 2002-11-28 06:14:08 EST
Solved. Null check in 1.4 mode got moved from constructor to allocation, so it 
gets performed prior to evaluating allocation arguments (JLS 15.9.4).

Fixed. In 1.3 mode, we don't want to complain for backward compatibility (see 
bug 25174).

Comment 2 David Audel CLA 2002-12-17 11:52:29 EST
Verified.