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

ClassCastException in com.sun.tools.javac.comp.AttrRecover.doRecovery

    XMLWordPrintable

Details

    • Bug
    • Resolution: Fixed
    • P2
    • 20
    • 20
    • tools
    • b27
    • Verified

    Description

      Compiling the following program causes a crash in javac.

      The input is invalid, but it shouldn't crash.

      The crash bisects to a range between 16-ea+15-631 and 16-ea+16-712. Earlier versions report an error.

      ```
      import java.util.function.Function;

      abstract class T {

        interface I {}
        interface F {}

        abstract F g(I i);
        abstract F w(F f);
        abstract F t(F i, Function<?, ?> f, String e);

        F f(F f) {
          return t(g(w(f)), v -> f);
        }
      }
      ```

      $ javac -fullversion T.java
      javac full version "20-ea+25-1926"
      An exception has occurred in the compiler (20-ea). Please file a bug against the Java compiler via the Java bug reporting page (https://bugreport.java.com) after checking the Bug Database (https://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.ClassCastException: class com.sun.tools.javac.tree.JCTree$JCIdent cannot be cast to class com.sun.tools.javac.tree.JCTree$JCBlock (com.sun.tools.javac.tree.JCTree$JCIdent and com.sun.tools.javac.tree.JCTree$JCBlock are in module jdk.compiler of loader 'app')
      at jdk.compiler/com.sun.tools.javac.comp.AttrRecover.doRecovery(AttrRecover.java:161)
      at jdk.compiler/com.sun.tools.javac.comp.Attr.attribStat(Attr.java:738)
      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:1082)
      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:912)
      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:5573)
      at jdk.compiler/com.sun.tools.javac.comp.Attr.attribClass(Attr.java:5466)
      at jdk.compiler/com.sun.tools.javac.comp.Attr.attribClass(Attr.java:5290)
      at jdk.compiler/com.sun.tools.javac.comp.Attr.attrib(Attr.java:5229)
      at jdk.compiler/com.sun.tools.javac.main.JavaCompiler.attribute(JavaCompiler.java:1318)
      at jdk.compiler/com.sun.tools.javac.main.JavaCompiler.compile(JavaCompiler.java:947)
      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)

      $ javac -fullversion T.java
      javac full version "16-ea+15-631"
      T.java:13: error: incompatible types: F cannot be converted to I
          return t(g(w(f)), v -> f);
                      ^
      Note: Some messages have been simplified; recompile with -Xdiags:verbose to get full output
      1 error

      Attachments

        Issue Links

          Activity

            People

              jlahoda Jan Lahoda
              cushon Liam Miller-Cushon
              Votes:
              0 Vote for this issue
              Watchers:
              3 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved: