Community
Participate
Working Groups
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.
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).
Verified.