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

ClassCastException from Symbol$ClassSymbol to Symbol$MethodSymbol

    XMLWordPrintable

    Details

      Description

      Compiling the following program:

      public class Tmp {
          void test() {
              new Object() {
      Runnable r = ()->{};
      };

              class X {
      Runnable r = ()->{};
      }
          }
      }

      Results in the following error on b105:

      An exception has occurred in the compiler (1.8.0-ea). Please file a bug at the Java Developer Connection (http://java.sun.com/webapps/bugreport) after checking the Bug Parade for duplicates. Include your program and the following diagnostic in your report. Thank you.
      java.lang.ClassCastException: com.sun.tools.javac.code.Symbol$ClassSymbol cannot be cast to com.sun.tools.javac.code.Symbol$MethodSymbol
      at com.sun.tools.javac.comp.LambdaToMethod.visitLambda(LambdaToMethod.java:252)
      at com.sun.tools.javac.tree.JCTree$JCLambda.accept(JCTree.java:1619)
      at com.sun.tools.javac.tree.TreeTranslator.translate(TreeTranslator.java:58)
      at com.sun.tools.javac.comp.LambdaToMethod.translate(LambdaToMethod.java:183)
      at com.sun.tools.javac.comp.LambdaToMethod.translate(LambdaToMethod.java:176)
      at com.sun.tools.javac.tree.TreeTranslator.visitVarDef(TreeTranslator.java:153)
      at com.sun.tools.javac.comp.LambdaToMethod.visitVarDef(LambdaToMethod.java:441)
      at com.sun.tools.javac.tree.JCTree$JCVariableDecl.accept(JCTree.java:846)
      at com.sun.tools.javac.tree.TreeTranslator.translate(TreeTranslator.java:58)
      at com.sun.tools.javac.comp.LambdaToMethod.translate(LambdaToMethod.java:183)
      at com.sun.tools.javac.comp.LambdaToMethod.translate(LambdaToMethod.java:176)
      at com.sun.tools.javac.tree.TreeTranslator.translate(TreeTranslator.java:70)
      at com.sun.tools.javac.tree.TreeTranslator.visitClassDef(TreeTranslator.java:134)
      at com.sun.tools.javac.comp.LambdaToMethod.visitClassDef(LambdaToMethod.java:223)
      at com.sun.tools.javac.tree.JCTree$JCClassDecl.accept(JCTree.java:687)
      at com.sun.tools.javac.tree.TreeTranslator.translate(TreeTranslator.java:58)
      at com.sun.tools.javac.comp.LambdaToMethod.translate(LambdaToMethod.java:183)
      at com.sun.tools.javac.comp.LambdaToMethod.translate(LambdaToMethod.java:176)
      at com.sun.tools.javac.tree.TreeTranslator.visitNewClass(TreeTranslator.java:283)
      at com.sun.tools.javac.tree.JCTree$JCNewClass.accept(JCTree.java:1510)
      at com.sun.tools.javac.tree.TreeTranslator.translate(TreeTranslator.java:58)
      at com.sun.tools.javac.comp.LambdaToMethod.translate(LambdaToMethod.java:183)
      at com.sun.tools.javac.comp.LambdaToMethod.translate(LambdaToMethod.java:176)
      at com.sun.tools.javac.tree.TreeTranslator.visitExec(TreeTranslator.java:245)
      at com.sun.tools.javac.tree.JCTree$JCExpressionStatement.accept(JCTree.java:1290)
      at com.sun.tools.javac.tree.TreeTranslator.translate(TreeTranslator.java:58)
      at com.sun.tools.javac.comp.LambdaToMethod.translate(LambdaToMethod.java:183)
      at com.sun.tools.javac.comp.LambdaToMethod.translate(LambdaToMethod.java:176)
      at com.sun.tools.javac.tree.TreeTranslator.translate(TreeTranslator.java:70)
      at com.sun.tools.javac.tree.TreeTranslator.visitBlock(TreeTranslator.java:162)
      at com.sun.tools.javac.tree.JCTree$JCBlock.accept(JCTree.java:903)
      at com.sun.tools.javac.tree.TreeTranslator.translate(TreeTranslator.java:58)
      at com.sun.tools.javac.comp.LambdaToMethod.translate(LambdaToMethod.java:183)
      at com.sun.tools.javac.comp.LambdaToMethod.translate(LambdaToMethod.java:176)
      at com.sun.tools.javac.tree.TreeTranslator.visitMethodDef(TreeTranslator.java:145)
      at com.sun.tools.javac.tree.JCTree$JCMethodDecl.accept(JCTree.java:772)
      at com.sun.tools.javac.tree.TreeTranslator.translate(TreeTranslator.java:58)
      at com.sun.tools.javac.comp.LambdaToMethod.translate(LambdaToMethod.java:183)
      at com.sun.tools.javac.comp.LambdaToMethod.translate(LambdaToMethod.java:176)
      at com.sun.tools.javac.tree.TreeTranslator.translate(TreeTranslator.java:70)
      at com.sun.tools.javac.tree.TreeTranslator.visitClassDef(TreeTranslator.java:134)
      at com.sun.tools.javac.comp.LambdaToMethod.visitClassDef(LambdaToMethod.java:223)
      at com.sun.tools.javac.tree.JCTree$JCClassDecl.accept(JCTree.java:687)
      at com.sun.tools.javac.tree.TreeTranslator.translate(TreeTranslator.java:58)
      at com.sun.tools.javac.comp.LambdaToMethod.translate(LambdaToMethod.java:183)
      at com.sun.tools.javac.comp.LambdaToMethod.translate(LambdaToMethod.java:176)
      at com.sun.tools.javac.comp.LambdaToMethod.translateTopLevelClass(LambdaToMethod.java:203)
      at com.sun.tools.javac.main.JavaCompiler.desugar(JavaCompiler.java:1465)
      at com.sun.tools.javac.main.JavaCompiler.desugar(JavaCompiler.java:1350)
      at com.sun.tools.javac.main.JavaCompiler.compile2(JavaCompiler.java:900)
      at com.sun.tools.javac.main.JavaCompiler.compile(JavaCompiler.java:859)
      at com.sun.tools.javac.main.Main.compile(Main.java:523)
      at com.sun.tools.javac.main.Main.compile(Main.java:381)
      at com.sun.tools.javac.main.Main.compile(Main.java:370)
      at com.sun.tools.javac.main.Main.compile(Main.java:361)
      at com.sun.tools.javac.Main.compile(Main.java:64)
      at com.sun.tools.javac.Main.main(Main.java:50)

      However, the compilation succeeds using b106.

      ----------

      Originally reported by Zhong Yu on lambda-dev:

      http://mail.openjdk.java.net/pipermail/lambda-dev/2013-September/010927.html

        Attachments

          Issue Links

            Activity

              People

              Assignee:
              jjg Jonathan Gibbons
              Reporter:
              smarks Stuart Marks
              Votes:
              0 Vote for this issue
              Watchers:
              4 Start watching this issue

                Dates

                Created:
                Updated:
                Resolved: