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

Compiling a SimpleTypeVisitor8 anonymous class inside a lambda crashes javac

    XMLWordPrintable

    Details

    • Type: Bug
    • Status: Closed
    • Priority: P4
    • Resolution: Duplicate
    • Affects Version/s: 16, 17, 18
    • Fix Version/s: None
    • Component/s: tools
    • Subcomponent:
    • CPU:
      generic
    • OS:
      generic

      Description

      ADDITIONAL SYSTEM INFORMATION :
      - Windows 10 (20H2, 19042.1165)
      - OpenJDK 16.0.2 (Temurin build 16.0.2+7)

      A DESCRIPTION OF THE PROBLEM :
      Compiling a source file with a SimpleTypeVisitor8 anonymous class used in Stream.filter crashes javac. This seems to also require a following Stream.map call (other stream methods might trigger this too), as well as passing this stream call chain to a method as a parameter.

      This also happens with a more complex stream chain with a terminal operation at the end, but I stripped the source code into a minimal example.

      STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
      1) Put the source in a file named Broken.java
      2) Compile the file with "javac Broken.java"

      EXPECTED VERSUS ACTUAL BEHAVIOR :
      EXPECTED -
      The code compiles successfully.
      ACTUAL -
      The compilation fails with the following error diagnostic:

      An exception has occurred in the compiler (16.0.2). 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, the following diagnostic, and the parameters passed to the Java compiler in your report. Thank you.
      java.lang.AssertionError: Incorrect number of arguments; expected 2, found 0
              at jdk.compiler/com.sun.tools.javac.util.Assert.error(Assert.java:162)
              at jdk.compiler/com.sun.tools.javac.comp.TransTypes.visitApply(TransTypes.java:666)
              at jdk.compiler/com.sun.tools.javac.tree.JCTree$JCMethodInvocation.accept(JCTree.java:1745)
              at jdk.compiler/com.sun.tools.javac.tree.TreeTranslator.translate(TreeTranslator.java:58)
              at jdk.compiler/com.sun.tools.javac.comp.TransTypes.translate(TransTypes.java:455)
              at jdk.compiler/com.sun.tools.javac.comp.TransTypes.visitLambda(TransTypes.java:541)
              at jdk.compiler/com.sun.tools.javac.tree.JCTree$JCLambda.accept(JCTree.java:1922)
              at jdk.compiler/com.sun.tools.javac.tree.TreeTranslator.translate(TreeTranslator.java:58)
              at jdk.compiler/com.sun.tools.javac.comp.TransTypes.translate(TransTypes.java:455)
              at jdk.compiler/com.sun.tools.javac.comp.TransTypes.translateArgs(TransTypes.java:213)
              at jdk.compiler/com.sun.tools.javac.comp.TransTypes.visitApply(TransTypes.java:669)
              at jdk.compiler/com.sun.tools.javac.tree.JCTree$JCMethodInvocation.accept(JCTree.java:1745)
              at jdk.compiler/com.sun.tools.javac.tree.TreeTranslator.translate(TreeTranslator.java:58)
              at jdk.compiler/com.sun.tools.javac.comp.TransTypes.translate(TransTypes.java:455)
              at jdk.compiler/com.sun.tools.javac.comp.TransTypes.visitSelect(TransTypes.java:834)
              at jdk.compiler/com.sun.tools.javac.tree.JCTree$JCFieldAccess.accept(JCTree.java:2273)
              at jdk.compiler/com.sun.tools.javac.tree.TreeTranslator.translate(TreeTranslator.java:58)
              at jdk.compiler/com.sun.tools.javac.comp.TransTypes.translate(TransTypes.java:455)
              at jdk.compiler/com.sun.tools.javac.comp.TransTypes.visitApply(TransTypes.java:652)
              at jdk.compiler/com.sun.tools.javac.tree.JCTree$JCMethodInvocation.accept(JCTree.java:1745)
              at jdk.compiler/com.sun.tools.javac.tree.TreeTranslator.translate(TreeTranslator.java:58)
              at jdk.compiler/com.sun.tools.javac.comp.TransTypes.translate(TransTypes.java:455)
              at jdk.compiler/com.sun.tools.javac.comp.TransTypes.translateArgs(TransTypes.java:213)
              at jdk.compiler/com.sun.tools.javac.comp.TransTypes.visitApply(TransTypes.java:669)
              at jdk.compiler/com.sun.tools.javac.tree.JCTree$JCMethodInvocation.accept(JCTree.java:1745)
              at jdk.compiler/com.sun.tools.javac.tree.TreeTranslator.translate(TreeTranslator.java:58)
              at jdk.compiler/com.sun.tools.javac.comp.TransTypes.translate(TransTypes.java:455)
              at jdk.compiler/com.sun.tools.javac.comp.TransTypes.visitExec(TransTypes.java:616)
              at jdk.compiler/com.sun.tools.javac.tree.JCTree$JCExpressionStatement.accept(JCTree.java:1532)
              at jdk.compiler/com.sun.tools.javac.tree.TreeTranslator.translate(TreeTranslator.java:58)
              at jdk.compiler/com.sun.tools.javac.tree.TreeTranslator.translate(TreeTranslator.java:70)
              at jdk.compiler/com.sun.tools.javac.tree.TreeTranslator.visitBlock(TreeTranslator.java:167)
              at jdk.compiler/com.sun.tools.javac.tree.JCTree$JCBlock.accept(JCTree.java:1047)
              at jdk.compiler/com.sun.tools.javac.tree.TreeTranslator.translate(TreeTranslator.java:58)
              at jdk.compiler/com.sun.tools.javac.comp.TransTypes.translate(TransTypes.java:455)
              at jdk.compiler/com.sun.tools.javac.comp.TransTypes.visitMethodDef(TransTypes.java:490)
              at jdk.compiler/com.sun.tools.javac.tree.JCTree$JCMethodDecl.accept(JCTree.java:893)
              at jdk.compiler/com.sun.tools.javac.tree.TreeTranslator.translate(TreeTranslator.java:58)
              at jdk.compiler/com.sun.tools.javac.tree.TreeTranslator.translate(TreeTranslator.java:70)
              at jdk.compiler/com.sun.tools.javac.tree.TreeTranslator.visitClassDef(TreeTranslator.java:139)
              at jdk.compiler/com.sun.tools.javac.comp.TransTypes.translateClass(TransTypes.java:948)
              at jdk.compiler/com.sun.tools.javac.comp.TransTypes.visitClassDef(TransTypes.java:476)
              at jdk.compiler/com.sun.tools.javac.tree.JCTree$JCClassDecl.accept(JCTree.java:790)
              at jdk.compiler/com.sun.tools.javac.tree.TreeTranslator.translate(TreeTranslator.java:58)
              at jdk.compiler/com.sun.tools.javac.comp.TransTypes.translate(TransTypes.java:455)
              at jdk.compiler/com.sun.tools.javac.comp.TransTypes.translateTopLevelClass(TransTypes.java:972)
              at jdk.compiler/com.sun.tools.javac.main.JavaCompiler.desugar(JavaCompiler.java:1556)
              at jdk.compiler/com.sun.tools.javac.main.JavaCompiler.desugar(JavaCompiler.java:1435)
              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:317)
              at jdk.compiler/com.sun.tools.javac.main.Main.compile(Main.java:176)
              at jdk.compiler/com.sun.tools.javac.Main.compile(Main.java:64)
              at jdk.compiler/com.sun.tools.javac.Main.main(Main.java:50)

      ---------- BEGIN SOURCE ----------
      import java.util.stream.Stream;
      import javax.lang.model.element.ExecutableElement;
      import javax.lang.model.util.SimpleTypeVisitor8;

      class Broken {
      void broken() {
      new StringBuilder().append(Stream.<ExecutableElement>empty()
      .filter(el -> el.getReturnType().accept(new SimpleTypeVisitor8<>(false) {}, null))
      .map(el -> el));
      }
      }

      ---------- END SOURCE ----------

      CUSTOMER SUBMITTED WORKAROUND :
      Replacing the anonymous class with a named class (a nested one, for example)

      FREQUENCY : always


        Attachments

          Issue Links

            Activity

              People

              Assignee:
              Unassigned Unassigned
              Reporter:
              webbuggrp Webbug Group
              Votes:
              0 Vote for this issue
              Watchers:
              3 Start watching this issue

                Dates

                Created:
                Updated:
                Resolved: