JDK-8274626 : NPE: Cannot invoke "com.sun.tools.javac.code.Type.getThrownTypes()" because "tree.meth.type" is null
  • Type: Bug
  • Component: tools
  • Sub-Component: javac
  • Affected Version: 17
  • Priority: P4
  • Status: Closed
  • Resolution: Duplicate
  • OS: generic
  • CPU: generic
  • Submitted: 2021-09-28
  • Updated: 2022-02-03
  • Resolved: 2021-10-19
Related Reports
Duplicate :  
Description
ADDITIONAL SYSTEM INFORMATION :
Arch Linux

openjdk version "17" 2021-09-14
OpenJDK Runtime Environment Temurin-17+35 (build 17+35)
OpenJDK 64-Bit Server VM Temurin-17+35 (build 17+35, mixed mode, sharing)


A DESCRIPTION OF THE PROBLEM :
Compiler crashes on trivial code with type inference. I minimized reproducer as much as i could.
It only crashes when i use TypeRef<T> from specific library. If i copy-paste class, it doesn't crash.

java: An exception has occurred in the compiler (17). Please file a bug against the Java compiler via the Java bug reporting page (http://bugreport.java.com) after checking the Bug Database (http://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: java.lang.NullPointerException: Cannot invoke "com.sun.tools.javac.code.Type.getThrownTypes()" because "tree.meth.type" is null
java: 	at jdk.compiler/com.sun.tools.javac.comp.Flow$FlowAnalyzer.visitApply(Flow.java:1439)
java: 	at jdk.compiler/com.sun.tools.javac.tree.JCTree$JCMethodInvocation.accept(JCTree.java:1797)
java: 	at jdk.compiler/com.sun.tools.javac.tree.TreeScanner.scan(TreeScanner.java:49)
java: 	at jdk.compiler/com.sun.tools.javac.comp.Flow$BaseAnalyzer.scan(Flow.java:444)
java: 	at jdk.compiler/com.sun.tools.javac.tree.TreeScanner.scan(TreeScanner.java:57)
java: 	at jdk.compiler/com.sun.tools.javac.comp.Flow$FlowAnalyzer.visitApply(Flow.java:1438)
java: 	at jdk.compiler/com.sun.tools.javac.comp.Flow$FlowAnalyzer.visitVarDef(Flow.java:1180)
java: 	at jdk.compiler/com.sun.tools.javac.tree.JCTree$JCVariableDecl.accept(JCTree.java:1027)
java: 	at jdk.compiler/com.sun.tools.javac.comp.Flow$FlowAnalyzer.visitBlock(Flow.java:1188)
java: 	at jdk.compiler/com.sun.tools.javac.tree.JCTree$JCBlock.accept(JCTree.java:1091)
java: 	at jdk.compiler/com.sun.tools.javac.comp.Flow$FlowAnalyzer.visitMethodDef(Flow.java:1154)
java: 	at jdk.compiler/com.sun.tools.javac.tree.JCTree$JCMethodDecl.accept(JCTree.java:921)
java: 	at jdk.compiler/com.sun.tools.javac.comp.Flow$FlowAnalyzer.visitClassDef(Flow.java:1117)
java: 	at jdk.compiler/com.sun.tools.javac.tree.JCTree$JCClassDecl.accept(JCTree.java:819)
java: 	at jdk.compiler/com.sun.tools.javac.comp.Flow$FlowAnalyzer.analyzeTree(Flow.java:1532)
java: 	at jdk.compiler/com.sun.tools.javac.comp.Flow$FlowAnalyzer.analyzeTree(Flow.java:1522)
java: 	at jdk.compiler/com.sun.tools.javac.comp.Flow.analyzeTree(Flow.java:222)
java: 	at jdk.compiler/com.sun.tools.javac.main.JavaCompiler.flow(JavaCompiler.java:1377)
java: 	at jdk.compiler/com.sun.tools.javac.main.JavaCompiler.flow(JavaCompiler.java:1351)
java: 	at jdk.compiler/com.sun.tools.javac.main.JavaCompiler.compile(JavaCompiler.java:946)
java: 	at jdk.compiler/com.sun.tools.javac.api.JavacTaskImpl.lambda$doCall$0(JavacTaskImpl.java:104)
java: 	at jdk.compiler/com.sun.tools.javac.api.JavacTaskImpl.invocationHelper(JavacTaskImpl.java:152)
java: 	at jdk.compiler/com.sun.tools.javac.api.JavacTaskImpl.doCall(JavacTaskImpl.java:100)
java: 	at jdk.compiler/com.sun.tools.javac.api.JavacTaskImpl.call(JavacTaskImpl.java:94)
java: 	at org.jetbrains.jps.javac.JavacMain.compile(JavacMain.java:231)
java: 	at org.jetbrains.jps.incremental.java.JavaBuilder.lambda$compileJava$2(JavaBuilder.java:514)
java: 	at org.jetbrains.jps.incremental.java.JavaBuilder.invokeJavac(JavaBuilder.java:560)
java: 	at org.jetbrains.jps.incremental.java.JavaBuilder.compileJava(JavaBuilder.java:512)
java: 	at org.jetbrains.jps.incremental.java.JavaBuilder.compile(JavaBuilder.java:355)
java: 	at org.jetbrains.jps.incremental.java.JavaBuilder.doBuild(JavaBuilder.java:280)
java: 	at org.jetbrains.jps.incremental.java.JavaBuilder.build(JavaBuilder.java:234)
java: 	at org.jetbrains.jps.incremental.IncProjectBuilder.runModuleLevelBuilders(IncProjectBuilder.java:1464)
java: 	at org.jetbrains.jps.incremental.IncProjectBuilder.runBuildersForChunk(IncProjectBuilder.java:1101)
java: 	at org.jetbrains.jps.incremental.IncProjectBuilder.buildTargetsChunk(IncProjectBuilder.java:1247)
java: 	at org.jetbrains.jps.incremental.IncProjectBuilder.buildChunkIfAffected(IncProjectBuilder.java:1066)
java: 	at org.jetbrains.jps.incremental.IncProjectBuilder.buildChunks(IncProjectBuilder.java:832)
java: 	at org.jetbrains.jps.incremental.IncProjectBuilder.runBuild(IncProjectBuilder.java:419)
java: 	at org.jetbrains.jps.incremental.IncProjectBuilder.build(IncProjectBuilder.java:183)
java: 	at org.jetbrains.jps.cmdline.BuildRunner.runBuild(BuildRunner.java:132)
java: 	at org.jetbrains.jps.cmdline.BuildSession.runBuild(BuildSession.java:301)
java: 	at org.jetbrains.jps.cmdline.BuildSession.run(BuildSession.java:132)
java: 	at org.jetbrains.jps.cmdline.BuildMain$MyMessageHandler.lambda$channelRead0$0(BuildMain.java:219)
java: 	at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1136)
java: 	at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:635)
java: 	at java.base/java.lang.Thread.run(Thread.java:833)
java: Compilation failed: internal java compiler error

STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
1. Clone this: https://gitlab.com/Xakep_SDK/java-compiler-bug
2. Run mvn package
For unknown reasons this only happens if `TypeRef` was from maven repo. If i copy-paste class source code and try to reproduce with it, it does not crash.

EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
Main class compiles
ACTUAL -
Man class does not compile

---------- BEGIN SOURCE ----------
package dk.xakeps.compilerbug;

import com.github.mizosoft.methanol.TypeRef;

import java.util.List;

public class Main {
    public static void main(String[] args) {
    }

    public void crash() {
        // crashes
        List<String> response = wrap(ofObject(new TypeRef<>() {}));

        // does not crash
        List<String> response2 = wrap(ofObject(new TypeRef<List<String>>() {}));

        // does not crash
        List<String> response3 = ofObject(new TypeRef<>() {});
    }

    public static <T> T ofObject(TypeRef<T> type) {
        throw new RuntimeException();
    }

    public <T> T wrap(T arg) {
        throw new RuntimeException();
    }
}
---------- END SOURCE ----------

CUSTOMER SUBMITTED WORKAROUND :
Do not use type inference


Comments
It is not reproducible with JDK 18 b13 anymore
01-10-2021

This is a duplicate of https://bugs.openjdk.java.net/browse/JDK-8262095. The issue is fixed in JDK 18 b13
01-10-2021