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

Instantiating a generic inner class inside a lambda causes a compiler crash

XMLWordPrintable

      ADDITIONAL SYSTEM INFORMATION :
      AdoptOpenJDK 11.0.7 (latest)

      A DESCRIPTION OF THE PROBLEM :
      Javac crashes when trying to compile an anonymous inner class inside a lambda with inferred generic type parameters

      STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
      Compile the given source code as a single .java file

      EXPECTED VERSUS ACTUAL BEHAVIOR :
      EXPECTED -
      It should compile (it should correctly infer type parameters for the anonymous ClassA instantiation)
      ACTUAL -
      It crashes out with the following exception:

      java.lang.AssertionError: isSubtype UNKNOWN
              at jdk.compiler/com.sun.tools.javac.code.Types$4.visitType(Types.java:1123)
              at jdk.compiler/com.sun.tools.javac.code.Types$4.visitType(Types.java:1100)
              at jdk.compiler/com.sun.tools.javac.code.Type.accept(Type.java:214)
              at jdk.compiler/com.sun.tools.javac.code.Types$DefaultTypeVisitor.visit(Types.java:4857)
              at jdk.compiler/com.sun.tools.javac.code.Types.isSubtype(Types.java:1096)
              at jdk.compiler/com.sun.tools.javac.code.Types.isSubtypeUncheckedInternal(Types.java:1022)
              at jdk.compiler/com.sun.tools.javac.code.Types.isSubtypeUnchecked(Types.java:1008)
              at jdk.compiler/com.sun.tools.javac.code.Types.isConvertible(Types.java:607)
              at jdk.compiler/com.sun.tools.javac.code.Types.isAssignable(Types.java:2319)
              at jdk.compiler/com.sun.tools.javac.comp.Check$1.compatible(Check.java:522)
              at jdk.compiler/com.sun.tools.javac.comp.Check.checkType(Check.java:563)
              at jdk.compiler/com.sun.tools.javac.comp.Check.checkType(Check.java:550)
              at jdk.compiler/com.sun.tools.javac.comp.Annotate.attributeAnnotationValues(Annotate.java:459)
              at jdk.compiler/com.sun.tools.javac.comp.Annotate.attributeAnnotation(Annotate.java:415)
              at jdk.compiler/com.sun.tools.javac.comp.Annotate.annotateNow(Annotate.java:341)
              at jdk.compiler/com.sun.tools.javac.comp.Annotate.lambda$annotateLater$0(Annotate.java:267)
              at jdk.compiler/com.sun.tools.javac.comp.Annotate.flush(Annotate.java:191)
              at jdk.compiler/com.sun.tools.javac.comp.Annotate.unblockAnnotations(Annotate.java:144)
              at jdk.compiler/com.sun.tools.javac.comp.TypeEnter.complete(TypeEnter.java:213)
              at jdk.compiler/com.sun.tools.javac.code.Symbol.complete(Symbol.java:642)
              at jdk.compiler/com.sun.tools.javac.code.Symbol$ClassSymbol.complete(Symbol.java:1326)
              at jdk.compiler/com.sun.tools.javac.comp.Attr.visitClassDef(Attr.java:941)
              at jdk.compiler/com.sun.tools.javac.tree.JCTree$JCClassDecl.accept(JCTree.java:774)
              at jdk.compiler/com.sun.tools.javac.comp.Attr.attribTree(Attr.java:655)
              at jdk.compiler/com.sun.tools.javac.comp.Attr.attribStat(Attr.java:724)
              at jdk.compiler/com.sun.tools.javac.comp.Attr.visitAnonymousClassDefinition(Attr.java:2397)
              at jdk.compiler/com.sun.tools.javac.comp.Attr.lambda$visitAnonymousClassDefinition$2(Attr.java:2355)
              at jdk.compiler/com.sun.tools.javac.comp.InferenceContext.notifyChange(InferenceContext.java:265)
              at jdk.compiler/com.sun.tools.javac.comp.InferenceContext.notifyChange(InferenceContext.java:256)
              at jdk.compiler/com.sun.tools.javac.comp.Infer.instantiateMethod(Infer.java:242)
              at jdk.compiler/com.sun.tools.javac.comp.Resolve.rawInstantiate(Resolve.java:605)
              at jdk.compiler/com.sun.tools.javac.comp.Resolve.checkMethod(Resolve.java:644)
              at jdk.compiler/com.sun.tools.javac.comp.Attr.checkMethod(Attr.java:4120)
              at jdk.compiler/com.sun.tools.javac.comp.Attr.checkIdInternal(Attr.java:3913)
              at jdk.compiler/com.sun.tools.javac.comp.Attr.checkMethodIdInternal(Attr.java:3814)
              at jdk.compiler/com.sun.tools.javac.comp.Attr.checkId(Attr.java:3803)
              at jdk.compiler/com.sun.tools.javac.comp.Attr.visitNewClass(Attr.java:2251)
              at jdk.compiler/com.sun.tools.javac.tree.JCTree$JCNewClass.accept(JCTree.java:1689)
              at jdk.compiler/com.sun.tools.javac.comp.Attr.attribTree(Attr.java:655)
              at jdk.compiler/com.sun.tools.javac.comp.Attr.attribExpr(Attr.java:702)
              at jdk.compiler/com.sun.tools.javac.comp.Attr.visitExec(Attr.java:1773)
              at jdk.compiler/com.sun.tools.javac.tree.JCTree$JCExpressionStatement.accept(JCTree.java:1452)
              at jdk.compiler/com.sun.tools.javac.comp.Attr.attribTree(Attr.java:655)
              at jdk.compiler/com.sun.tools.javac.comp.Attr.attribStat(Attr.java:724)
              at jdk.compiler/com.sun.tools.javac.comp.Attr.attribStats(Attr.java:743)
              at jdk.compiler/com.sun.tools.javac.comp.Attr.visitBlock(Attr.java:1294)
              at jdk.compiler/com.sun.tools.javac.tree.JCTree$JCBlock.accept(JCTree.java:1020)
              at jdk.compiler/com.sun.tools.javac.comp.Attr.attribTree(Attr.java:655)
              at jdk.compiler/com.sun.tools.javac.comp.Attr.attribStat(Attr.java:724)
              at jdk.compiler/com.sun.tools.javac.comp.Attr.visitMethodDef(Attr.java:1098)
              at jdk.compiler/com.sun.tools.javac.tree.JCTree$JCMethodDecl.accept(JCTree.java:866)
              at jdk.compiler/com.sun.tools.javac.comp.Attr.attribTree(Attr.java:655)
              at jdk.compiler/com.sun.tools.javac.comp.Attr.attribStat(Attr.java:724)
              at jdk.compiler/com.sun.tools.javac.comp.Attr.attribClassBody(Attr.java:4683)
              at jdk.compiler/com.sun.tools.javac.comp.Attr.attribClass(Attr.java:4574)
              at jdk.compiler/com.sun.tools.javac.comp.Attr.attribClass(Attr.java:4503)
              at jdk.compiler/com.sun.tools.javac.comp.Attr.attrib(Attr.java:4448)
              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)

      ---------- BEGIN SOURCE ----------
      public class CrashTest {
          public CrashTest() {
              new ClassB<>(() ->
                      new ClassA<>() {
                          @Override
                          public String toString() {
                              return "Overridden toString";
                          }
                      });
          }
      }

      class ClassA<T> {}

      class ClassB<T> {
          public ClassB(java.util.function.Supplier<T> ctor) {}
      }
      ---------- END SOURCE ----------

      CUSTOMER SUBMITTED WORKAROUND :
      Specify explicit type parameters on ClassA, or remove the overridden toString() method

      FREQUENCY : always


            Unassigned Unassigned
            webbuggrp Webbug Group
            Votes:
            0 Vote for this issue
            Watchers:
            4 Start watching this issue

              Created:
              Updated:
              Resolved: