Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-8215914

NPE in Types.erasure with type-annotated generic supertype

XMLWordPrintable

      ```
      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

            sadayapalam Srikanth Adayapalam (Inactive)
            cushon Liam Miller-Cushon
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated:
              Resolved: