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

Elements#getTypeElement ignores CompletionFailure, causing CCE in TransTypes#visitApply

    Details

    • Type: Bug
    • Status: Resolved
    • Priority: P3
    • Resolution: Duplicate
    • Affects Version/s: 9
    • Fix Version/s: 11
    • Component/s: tools
    • Labels:

      Description

      The repro involves an incomplete classpath and a javac plugin that uses Elements#getTypeElement to complete the missing symbol. Since javac never sees the CompletionFailure it fails to emit an error for the missing classfile, and instead crashes.

      I reproduced with 9-ea+161.

      === ./A.java
      class A<T> {
        T g(T t) {
          return t;
        }
      }
      === ./B.java
      class B {
        A<String> f() {
          return null;
        }
      }
      === ./C.java
      class C {
        void m(B b) {
          b.f().g(null);
        }
      }
      === ./plugin/module-info.java
      module repro {
        requires transitive jdk.compiler;
        provides com.sun.source.util.Plugin with repro.ReproPlugin;
      }
      === ./plugin/repro/ReproPlugin.java
      package repro;
      import com.sun.source.util.*;
      public class ReproPlugin implements Plugin {
        @Override
        public String getName() {
          return "Repro";
        }

        @Override
        public void init(JavacTask javacTask, String... args) {
          javacTask.addTaskListener(new TaskListener() {
            public void started(TaskEvent e) {}
            public void finished(TaskEvent e) {
              if (e.getKind() == TaskEvent.Kind.ENTER) {
                System.err.println(javacTask.getElements().getTypeElement("A"));
              }
            }
          });
        }
      }
      ===

      $ javac plugin/module-info.java plugin/repro/ReproPlugin.java *.java
      $ rm A.class
      $ javac --processor-module-path plugin -Xplugin:Repro C.java -sourcepath :
      ...
      java.lang.ClassCastException: jdk.compiler/com.sun.tools.javac.code.Symbol$ClassSymbol cannot be cast to jdk.compiler/com.sun.tools.javac.code.Symbol$MethodSymbol
      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:1628)
      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:491)
      at jdk.compiler/com.sun.tools.javac.comp.TransTypes.visitExec(TransTypes.java:643)
      at jdk.compiler/com.sun.tools.javac.tree.JCTree$JCExpressionStatement.accept(JCTree.java:1446)
      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:1014)
      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:491)
      at jdk.compiler/com.sun.tools.javac.comp.TransTypes.visitMethodDef(TransTypes.java:526)
      at jdk.compiler/com.sun.tools.javac.tree.JCTree$JCMethodDecl.accept(JCTree.java:866)
      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:953)
      at jdk.compiler/com.sun.tools.javac.comp.TransTypes.visitClassDef(TransTypes.java:512)
      at jdk.compiler/com.sun.tools.javac.tree.JCTree$JCClassDecl.accept(JCTree.java:774)
      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:491)
      at jdk.compiler/com.sun.tools.javac.comp.TransTypes.translateTopLevelClass(TransTypes.java:977)
      at jdk.compiler/com.sun.tools.javac.main.JavaCompiler.desugar(JavaCompiler.java:1560)
      at jdk.compiler/com.sun.tools.javac.main.JavaCompiler.desugar(JavaCompiler.java:1439)
      at jdk.compiler/com.sun.tools.javac.main.JavaCompiler.compile(JavaCompiler.java:980)
      at jdk.compiler/com.sun.tools.javac.main.Main.compile(Main.java:302)
      at jdk.compiler/com.sun.tools.javac.main.Main.compile(Main.java:162)
      at jdk.compiler/com.sun.tools.javac.Main.compile(Main.java:55)
      at jdk.compiler/com.sun.tools.javac.Main.main(Main.java:41)

        Attachments

          Issue Links

            Activity

              People

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

                Dates

                • Created:
                  Updated:
                  Resolved: