JDK 11.0.2 compilation fails with javac NPE on anonymous parameterized class type inference

Code (spring-web 5.1.2)

public static void main(String[] args) {
    RestTemplate restTemplate = new RestTemplate();

    HttpHeaders headers = new HttpHeaders();
    headers.set(HttpHeaders.AUTHORIZATION, "token");
    HttpEntity<Object> requestEntity = new HttpEntity<>(headers);

    ResponseEntity<Object> test =
            new HttpEntity<>(headers),
            new ParameterizedTypeReference<>() { // fails here

OracleJDK 1.8 (expected output)

cannot infer type arguments for org.springframework.core.ParameterizedTypeReference

reason: cannot use '<>' with anonymous inner classes

OracleJDK 11.0.2 (not expected output)

compiler message file broken: key=compiler.misc.msg.bug arguments=11.0.2, {1}, {2}, {3}, {4}, {5}, {6}, {7} java.lang.NullPointerException at jdk.compiler/$FlowAnalyzer.visitApply( at jdk.compiler/$JCMethodInvocation.accept( at jdk.compiler/ at jdk.compiler/$BaseAnalyzer.scan( at jdk.compiler/$FlowAnalyzer.visitVarDef(

If I change diamond operator to explicit type

new ParameterizedTypeReference<>(){} to new ParameterizedTypeReference<Object>(){}

then the code compiles successfully on both JDKs.

Is it a known compiler bug?


  • Bug (JDK-8212586) has been already submitted and fixed in version 12.

    Minimal, verifiable example:

    public static void main(String[] args) {
        new Bug<>(){};
    static class Bug<T> {
        Bug() {
            test(new ParameterizedTypeReference<>(){});
        void test(ParameterizedTypeReference<T> typeReference) {

    Some Details.

    Fix has been also backported to JDK 11 -

    Available starting JDK 11.0.4.