JDK-8215914 : NPE in Types.erasure with type-annotated generic supertype
  • Type: Bug
  • Component: tools
  • Sub-Component: javac
  • Affected Version: 9,10,11,12
  • Priority: P3
  • Status: Resolved
  • Resolution: Cannot Reproduce
  • Submitted: 2018-12-25
  • Updated: 2022-01-11
  • Resolved: 2019-06-17
The Version table provides details related to the release that this issue/RFE will be addressed.

Unresolved : Release in which this issue/RFE will be addressed.
Resolved: Release in which this issue/RFE has been resolved.
Fixed : Release in which this issue/RFE has been fixed. The release containing this fix may be available for download as an Early Access Release or a General Availability Release.

To download the current JDK release, click here.
JDK 13
13Resolved
Related Reports
Duplicate :  
Description
```
import java.lang.annotation.ElementType;
import java.lang.annotation.Target;

@Target(ElementType.TYPE_USE)
@interface A {}

abstract class E<T extends Enum<T>> extends R<@A T[]> {}

abstract class R<T> {
  T t;

  public R(T t) {
    this.t = t;
  }
}
```

With 12-ea+25:

An exception has occurred in the compiler (12-ea). Please file a bug against the Java compiler via the Java bug reporting page (http://bugreport.java.com) after checking the Bug Database (http://bugs.java.com) for duplicates. Include your program and the following diagnostic in your report. Thank you.
java.lang.NullPointerException
        at jdk.compiler/com.sun.tools.javac.code.Types.erasure(Types.java:2337)
        at jdk.compiler/com.sun.tools.javac.code.Types$14.visitTypeVar(Types.java:2395)
        at jdk.compiler/com.sun.tools.javac.code.Types$14.visitTypeVar(Types.java:2345)
        at jdk.compiler/com.sun.tools.javac.code.Type$TypeVar.accept(Type.java:1654)
        at jdk.compiler/com.sun.tools.javac.code.Types$DefaultTypeVisitor.visit(Types.java:4854)
        at jdk.compiler/com.sun.tools.javac.code.Type$StructuralTypeMapping.visitArrayType(Type.java:266)
        at jdk.compiler/com.sun.tools.javac.code.Type$StructuralTypeMapping.visitArrayType(Type.java:230)
        at jdk.compiler/com.sun.tools.javac.code.Type$ArrayType.accept(Type.java:1314)
        at jdk.compiler/com.sun.tools.javac.code.Types$DefaultTypeVisitor.visit(Types.java:4854)
        at jdk.compiler/com.sun.tools.javac.code.Types$TypeMapping.lambda$visit$0(Types.java:4962)
        at jdk.compiler/com.sun.tools.javac.util.List.map(List.java:425)
        at jdk.compiler/com.sun.tools.javac.code.Types$TypeMapping.visit(Types.java:4962)
        at jdk.compiler/com.sun.tools.javac.code.Type$StructuralTypeMapping.visitMethodType(Type.java:281)
        at jdk.compiler/com.sun.tools.javac.code.Type$StructuralTypeMapping.visitMethodType(Type.java:230)
        at jdk.compiler/com.sun.tools.javac.code.Type$MethodType.accept(Type.java:1448)
        at jdk.compiler/com.sun.tools.javac.code.Types$DefaultTypeVisitor.visit(Types.java:4854)
        at jdk.compiler/com.sun.tools.javac.code.Types.erasure(Types.java:2340)
        at jdk.compiler/com.sun.tools.javac.code.Types.erasure(Types.java:2326)
        at jdk.compiler/com.sun.tools.javac.code.Types.overrideEquivalent(Types.java:2763)
        at jdk.compiler/com.sun.tools.javac.comp.Check.firstDirectIncompatibility(Check.java:1959)
        at jdk.compiler/com.sun.tools.javac.comp.Check.firstIncompatibility(Check.java:1917)
        at jdk.compiler/com.sun.tools.javac.comp.Check.checkCompatibleAbstracts(Check.java:1895)
        at jdk.compiler/com.sun.tools.javac.comp.Check.checkCompatibleSupertypes(Check.java:2400)
        at jdk.compiler/com.sun.tools.javac.comp.Attr.attribClassBody(Attr.java:4854)
        at jdk.compiler/com.sun.tools.javac.comp.Attr.attribClass(Attr.java:4775)
        at jdk.compiler/com.sun.tools.javac.comp.Attr.attribClass(Attr.java:4704)
        at jdk.compiler/com.sun.tools.javac.comp.Attr.attrib(Attr.java:4649)
        at jdk.compiler/com.sun.tools.javac.main.JavaCompiler.attribute(JavaCompiler.java:1341)
        at jdk.compiler/com.sun.tools.javac.main.JavaCompiler.compile(JavaCompiler.java:973)
        at jdk.compiler/com.sun.tools.javac.main.Main.compile(Main.java:311)
        at jdk.compiler/com.sun.tools.javac.main.Main.compile(Main.java:170)
        at jdk.compiler/com.sun.tools.javac.Main.compile(Main.java:57)
        at jdk.compiler/com.sun.tools.javac.Main.main(Main.java:43)

The crash reproduces with 9, 10, and 11.

1.8.0_192-b12 produces a different error:

T.java:7: error: constructor R in class R<T#2> cannot be applied to given types;
abstract class E<T extends Enum<T>> extends R<@A T[]> {}
         ^
  required: T#1[]
  found: no arguments
  reason: actual and formal argument lists differ in length
  where T#1,T#2 are type-variables:
    T#1 extends Enum<T#1> declared in class E
    T#2 extends Object declared in class R
1 error

Comments
I think this was a dupe of https://bugs.openjdk.java.net/browse/JDK-8193367, which was fixed in 13-ga, which explains why it reproduces with 12 and not 13.
11-01-2022

Eclipse complains: "Implicit super constructor R<T[]>() is undefined for default constructor. Must define an explicit constructor" I reconfirmed that in tip, we don't get a crash but get: X.java:7: error: constructor R in class R<T#1> cannot be applied to given types; abstract class E<T extends Enum<T>> extends R<@A T[]> {} ^ required: @A T#1[] found: no arguments reason: actual and formal argument lists differ in length where @A T#1,T#1 are type-variables: @A T#1 extends Enum<T#1> declared in class E T#1 extends Object declared in class R 1 error
17-06-2019

On jdk/jdk tip I see: X.java:7: error: constructor R in class R<T#1> cannot be applied to given types; abstract class E<T extends Enum<T>> extends R<@A T[]> {} ^ required: @A T#1[] found: no arguments reason: actual and formal argument lists differ in length where @A T#1,T#1 are type-variables: @A T#1 extends Enum<T#1> declared in class E T#1 extends Object declared in class R 1 error
25-02-2019