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

[local-methods] ClassCastException while compiling local method with new instance creation

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Unresolved
    • Icon: P4 P4
    • repo-amber
    • repo-amber
    • tools
    • generic
    • generic

      Compiling this code:

      public class X {
          public class Y {
          }
          Y foo() {
              Y goo() {
                  return new Y();
              }
              return goo();
          }
          public static void main(String [] args) {
              Y y = new X().foo();
              System.out.println("y = " + y);
          }
      }

      results in:

      java.lang.ClassCastException: class com.sun.tools.javac.comp.LambdaToMethod$LambdaAnalyzerPreprocessor$LocalMethodTranslationContext cannot be cast to class com.sun.tools.javac.comp.LambdaToMethod$LambdaAnalyzerPreprocessor$LambdaTranslationContext (com.sun.tools.javac.comp.LambdaToMethod$LambdaAnalyzerPreprocessor$LocalMethodTranslationContext and com.sun.tools.javac.comp.LambdaToMethod$LambdaAnalyzerPreprocessor$LambdaTranslationContext are in module jdk.compiler of loader 'app')
      at jdk.compiler/com.sun.tools.javac.comp.LambdaToMethod.visitNewClass(LambdaToMethod.java:657)
      at jdk.compiler/com.sun.tools.javac.tree.JCTree$JCNewClass.accept(JCTree.java:1791)
      at jdk.compiler/com.sun.tools.javac.tree.TreeTranslator.translate(TreeTranslator.java:58)
      at jdk.compiler/com.sun.tools.javac.comp.LambdaToMethod.translate(LambdaToMethod.java:262)
      at jdk.compiler/com.sun.tools.javac.comp.LambdaToMethod.translate(LambdaToMethod.java:255)
      at jdk.compiler/com.sun.tools.javac.tree.TreeTranslator.visitReturn(TreeTranslator.java:274)
      at jdk.compiler/com.sun.tools.javac.tree.JCTree$JCReturn.accept(JCTree.java:1648)
      at jdk.compiler/com.sun.tools.javac.tree.TreeTranslator.translate(TreeTranslator.java:58)
      at jdk.compiler/com.sun.tools.javac.comp.LambdaToMethod.translate(LambdaToMethod.java:262)
      at jdk.compiler/com.sun.tools.javac.comp.LambdaToMethod.translate(LambdaToMethod.java:255)
      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:1029)
      at jdk.compiler/com.sun.tools.javac.tree.TreeTranslator.translate(TreeTranslator.java:58)
      at jdk.compiler/com.sun.tools.javac.comp.LambdaToMethod.translate(LambdaToMethod.java:262)
      at jdk.compiler/com.sun.tools.javac.comp.LambdaToMethod.translate(LambdaToMethod.java:255)
      at jdk.compiler/com.sun.tools.javac.comp.LambdaToMethod.visitMethodDef(LambdaToMethod.java:492)
      at jdk.compiler/com.sun.tools.javac.tree.JCTree$JCMethodDecl.accept(JCTree.java:875)
      at jdk.compiler/com.sun.tools.javac.tree.TreeTranslator.translate(TreeTranslator.java:58)
      at jdk.compiler/com.sun.tools.javac.comp.LambdaToMethod.translate(LambdaToMethod.java:262)
      at jdk.compiler/com.sun.tools.javac.comp.LambdaToMethod.translate(LambdaToMethod.java:255)
      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:1029)
      at jdk.compiler/com.sun.tools.javac.tree.TreeTranslator.translate(TreeTranslator.java:58)
      at jdk.compiler/com.sun.tools.javac.comp.LambdaToMethod.translate(LambdaToMethod.java:262)
      at jdk.compiler/com.sun.tools.javac.comp.LambdaToMethod.translate(LambdaToMethod.java:255)
      at jdk.compiler/com.sun.tools.javac.tree.TreeTranslator.visitMethodDef(TreeTranslator.java:150)
      at jdk.compiler/com.sun.tools.javac.comp.LambdaToMethod.visitMethodDef(LambdaToMethod.java:500)
      at jdk.compiler/com.sun.tools.javac.tree.JCTree$JCMethodDecl.accept(JCTree.java:875)
      at jdk.compiler/com.sun.tools.javac.tree.TreeTranslator.translate(TreeTranslator.java:58)
      at jdk.compiler/com.sun.tools.javac.comp.LambdaToMethod.translate(LambdaToMethod.java:262)
      at jdk.compiler/com.sun.tools.javac.comp.LambdaToMethod.translate(LambdaToMethod.java:255)
      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.LambdaToMethod.visitClassDef(LambdaToMethod.java:302)
      at jdk.compiler/com.sun.tools.javac.tree.JCTree$JCClassDecl.accept(JCTree.java:783)
      at jdk.compiler/com.sun.tools.javac.tree.TreeTranslator.translate(TreeTranslator.java:58)
      at jdk.compiler/com.sun.tools.javac.comp.LambdaToMethod.translate(LambdaToMethod.java:262)
      at jdk.compiler/com.sun.tools.javac.comp.LambdaToMethod.translate(LambdaToMethod.java:255)
      at jdk.compiler/com.sun.tools.javac.comp.LambdaToMethod.translateTopLevelClass(LambdaToMethod.java:282)
      at jdk.compiler/com.sun.tools.javac.main.JavaCompiler.desugar(JavaCompiler.java:1602)
      at jdk.compiler/com.sun.tools.javac.main.JavaCompiler.desugar(JavaCompiler.java:1438)
      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:318)
      at jdk.compiler/com.sun.tools.javac.main.Main.compile(Main.java:176)
      at jdk.compiler/com.sun.tools.javac.Main.compile(Main.java:57)
      at jdk.compiler/com.sun.tools.javac.Main.main(Main.java:43)

            vromero Vicente Arturo Romero Zaldivar
            sadayapalam Srikanth Adayapalam (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

              Created:
              Updated: