RFR JDK-8203195: Anonymous class type inference results in NPE

Vicente Romero vicente.romero at oracle.com
Wed Jun 20 01:47:17 UTC 2018


Please review the patch for [1] which can be found at [2]. The issue is 
a bit weird. This is the test case that shows it:

A.java:
---------------------------------------------------------
import foo.B;

public class A {

   interface Foo {
     <T> T foo(B<T> key);
   }

   private Foo foo;

   A() {
     Object baz = foo.foo(new B<>() {});
   }
}
---------------------------------------------------------

B.java:
---------------------------------------------------------
package foo;

public class B<T> {
/*
   // if the constructor is placed here the compilation is accepted
   B(int baz) {
   }
*/

   protected B() {
   }


   // but fails if placed here
   B(int baz) {
   }

}
---------------------------------------------------------

so depending on the order in which the constructor, B(int), appears, the 
output of the compiler is different. This code path is used for all 
methods so I had some doubts about modifying it but in any case I think 
that having a different outcome depending on the order in which a method 
appears in a class should be fixed. The proposed fix is to return an 
access error symbol in more cases than before at Resolve::selectBest.

Thanks,
Vicente

[1] https://bugs.openjdk.java.net/browse/JDK-8203195
[2] http://cr.openjdk.java.net/~vromero/8203195/webrev.00/


More information about the compiler-dev mailing list