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

javac - crash on unknown type referenced in yield statement

    XMLWordPrintable

Details

    • Bug
    • Resolution: Fixed
    • P4
    • 24
    • 17, 21, 22, 23
    • tools
    • None
    • b04

    Description

      Encountered while using jshell, javac swallows the exception because it already reported errors.

      If a variable of an unknown type is referenced in a(n implicit) yield statement, the variable has type null.

      For example, pasting

      I m(I i, int x) {
         return switch (x) {
              default -> i;
         };
      }

      into jshell will crash the

      The relevant part of the stacktrace:
      Caused by: java.lang.AssertionError
              at jdk.compiler/com.sun.tools.javac.util.Assert.error(Assert.java:155)
              at jdk.compiler/com.sun.tools.javac.util.Assert.checkNonNull(Assert.java:62)
              at jdk.compiler/com.sun.tools.javac.util.ListBuffer.append(ListBuffer.java:127)
              at jdk.compiler/com.sun.tools.javac.comp.Attr$1.visitYield(Attr.java:1637)
              at jdk.compiler/com.sun.tools.javac.tree.JCTree$JCYield.accept(JCTree.java:1677)
              at jdk.compiler/com.sun.tools.javac.tree.TreeScanner.scan(TreeScanner.java:50)
              at jdk.compiler/com.sun.tools.javac.tree.TreeScanner.scan(TreeScanner.java:58)
              at jdk.compiler/com.sun.tools.javac.comp.Attr.lambda$visitSwitchExpression$7(Attr.java:1644)
              at jdk.compiler/com.sun.tools.javac.comp.Attr.handleSwitch(Attr.java:1843)
              at jdk.compiler/com.sun.tools.javac.comp.Attr.visitSwitchExpression(Attr.java:1629)
              at jdk.compiler/com.sun.tools.javac.tree.JCTree$JCSwitchExpression.accept(JCTree.java:1399)
              at jdk.compiler/com.sun.tools.javac.comp.Attr.attribTree(Attr.java:662)
              at jdk.compiler/com.sun.tools.javac.comp.Attr.visitReturn(Attr.java:2468)
              at jdk.compiler/com.sun.tools.javac.tree.JCTree$JCReturn.accept(JCTree.java:1728)
              at jdk.compiler/com.sun.tools.javac.comp.Attr.attribTree(Attr.java:662)
              at jdk.compiler/com.sun.tools.javac.comp.Attr.attribStat(Attr.java:736)
              at jdk.compiler/com.sun.tools.javac.comp.Attr.attribStats(Attr.java:755)
              at jdk.compiler/com.sun.tools.javac.comp.Attr.visitBlock(Attr.java:1439)
              at jdk.compiler/com.sun.tools.javac.tree.JCTree$JCBlock.accept(JCTree.java:1092)
              at jdk.compiler/com.sun.tools.javac.comp.Attr.attribTree(Attr.java:662)
              at jdk.compiler/com.sun.tools.javac.comp.Attr.attribStat(Attr.java:736)
              at jdk.compiler/com.sun.tools.javac.comp.Attr.visitMethodDef(Attr.java:1229)
              at jdk.compiler/com.sun.tools.javac.tree.JCTree$JCMethodDecl.accept(JCTree.java:916)
              at jdk.compiler/com.sun.tools.javac.comp.Attr.attribTree(Attr.java:662)
              at jdk.compiler/com.sun.tools.javac.comp.Attr.attribStat(Attr.java:736)
              at jdk.compiler/com.sun.tools.javac.comp.Attr.attribClassBody(Attr.java:5648)
              at jdk.compiler/com.sun.tools.javac.comp.Attr.attribClass(Attr.java:5536)
              at jdk.compiler/com.sun.tools.javac.comp.Attr.attribClass(Attr.java:5360)
              at jdk.compiler/com.sun.tools.javac.comp.Attr.attrib(Attr.java:5299)
              at jdk.compiler/com.sun.tools.javac.main.JavaCompiler.attribute(JavaCompiler.java:1358)
              at jdk.compiler/com.sun.tools.javac.main.JavaCompiler.attribute(JavaCompiler.java:1331)
              at jdk.compiler/com.sun.tools.javac.api.JavacTaskImpl.analyze(JavacTaskImpl.java:404)
              at jdk.compiler/com.sun.tools.javac.api.JavacTaskImpl.lambda$analyze$1(JavacTaskImpl.java:379)
              at jdk.compiler/com.sun.tools.javac.api.JavacTaskImpl.invocationHelper(JavacTaskImpl.java:152)
              at jdk.compiler/com.sun.tools.javac.api.JavacTaskImpl.analyze(JavacTaskImpl.java:379)
              ... 19 more

      Attachments

        Issue Links

          Activity

            People

              hgreule Hannes Greule
              hgreule Hannes Greule
              Votes:
              0 Vote for this issue
              Watchers:
              4 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved: