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

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 - https://bugs.openjdk.java.net/browse/JDK-8220578.

Available starting JDK 11.0.4.


I Had the same error,you need to create a function :

ParameterizedTypeReference<Object> createParameterizedTypeReference(){ return new ParameterizedTypeReference<>(){}; }

and call it :

ResponseEntity<Object> test = restTemplate.exchange(
"https://example.com",
HttpMethod.GET,
new HttpEntity<>(headers),
createParameterizedTypeReference() { 
});