JDK-8177436 : Elements#getTypeElement ignores CompletionFailure, causing CCE in TransTypes#visitApply
  • Type: Bug
  • Component: tools
  • Sub-Component: javac
  • Affected Version: 9
  • Priority: P3
  • Status: Resolved
  • Resolution: Duplicate
  • Submitted: 2017-03-23
  • Updated: 2018-03-16
  • Resolved: 2018-03-16
The Version table provides details related to the release that this issue/RFE will be addressed.

Unresolved : Release in which this issue/RFE will be addressed.
Resolved: Release in which this issue/RFE has been resolved.
Fixed : Release in which this issue/RFE has been fixed. The release containing this fix may be available for download as an Early Access Release or a General Availability Release.

To download the current JDK release, click here.
JDK 11
11Resolved
Related Reports
Relates :  
Relates :  
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)
Comments
Should be fixed by the fix for JDK-8187950.
16-03-2018