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

Compiler crashes when using generics

    Details

    • Type: Bug
    • Status: Closed
    • Priority: P4
    • Resolution: Duplicate
    • Affects Version/s: 11.0.4
    • Fix Version/s: None
    • Component/s: tools
    • Labels:
    • Subcomponent:
    • CPU:
      generic
    • OS:
      generic

      Description

      A DESCRIPTION OF THE PROBLEM :
      Javac crashes when trying to compile this small code snippet

      ```
      interface Bar<T> {
          T bar();
      }

      public class Foo {

          static <T> void foo(Bar<T> iterable) {
          }

          private void run() {
              foo(() -> new Bar<>() {
                  @Override
                  public String bar() {
                      return "";
                  }
              });
          }
      }
      ```
      Compiler exception stacktrace
      ```
      An exception has occurred in the compiler (11.0.4). 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.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.visitIdent(Attr.java:3553)
      at jdk.compiler/com.sun.tools.javac.tree.JCTree$JCIdent.accept(JCTree.java:2248)
      at jdk.compiler/com.sun.tools.javac.comp.Attr.attribTree(Attr.java:655)
      at jdk.compiler/com.sun.tools.javac.comp.Attr.visitApply(Attr.java:2006)
      at jdk.compiler/com.sun.tools.javac.tree.JCTree$JCMethodInvocation.accept(JCTree.java:1634)
      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)
      ```

      STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
      put this code in a file named "Foo.java" and run "javac Foo.java"
      ```
      interface Bar<T> {
          T bar();
      }

      public class Foo {

          static <T> void foo(Bar<T> iterable) {
          }

          private void run() {
              foo(() -> new Bar<>() {
                  @Override
                  public String bar() {
                      return "";
                  }
              });
          }
      }
      ```

      EXPECTED VERSUS ACTUAL BEHAVIOR :
      EXPECTED -
      the compiler emits a meaningful error message
      ACTUAL -
      the compiler crashes asking for a bug report submission

      ---------- BEGIN SOURCE ----------
      interface Bar<T> {
          T bar();
      }

      public class Foo {

          static <T> void foo(Bar<T> iterable) {
          }

          private void run() {
              foo(() -> new Bar<>() {
                  @Override
                  public String bar() {
                      return "";
                  }
              });
          }
      }
      ---------- END SOURCE ----------

      CUSTOMER SUBMITTED WORKAROUND :
      avoid diamond operator usage

      FREQUENCY : always


        Attachments

          Issue Links

            Activity

              People

              • Assignee:
                psonal Pallavi Sonal (Inactive)
                Reporter:
                webbuggrp Webbug Group
              • Votes:
                0 Vote for this issue
                Watchers:
                2 Start watching this issue

                Dates

                • Created:
                  Updated:
                  Resolved: