JDK-8262095 : NPE in Flow$FlowAnalyzer.visitApply: Cannot invoke getThrownTypes because tree.meth.type is null
  • Type: Bug
  • Component: tools
  • Sub-Component: javac
  • Affected Version: 13,15,16,17
  • Priority: P3
  • Status: Resolved
  • Resolution: Fixed
  • Submitted: 2021-02-21
  • Updated: 2022-02-21
  • Resolved: 2021-08-31
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 17 JDK 18
17.0.2Fixed 18 b13Fixed
Related Reports
Duplicate :  
Duplicate :  
Duplicate :  
Duplicate :  
Relates :  
Relates :  
Description
There have been a handful of other bugs involving NPEs in Flow$FlowAnalyzer.visitApply, but this appears to be a distinct issue that still reproduces with the latest JDK 16 EA:

```
import static java.util.Map.Entry.comparingByKey;

import java.util.List;
import java.util.Map;
import java.util.stream.Stream;

public class T {

  void f(Stream<Map.Entry<Long, List<String>>> stream) {
    stream
        .sorted(
            comparingByKey()
                .thenComparing((Map.Entry<Long, List<String>> e) -> e.getValue().hashCode()))
        .count();
  }
}
```

```
javac -fullversion T.java
javac full version "16-ea+34-2216"
An exception has occurred in the compiler (16-ea). 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.lang.NullPointerException: Cannot invoke "com.sun.tools.javac.code.Type.getThrownTypes()" because "tree.meth.type" is null
        at jdk.compiler/com.sun.tools.javac.comp.Flow$FlowAnalyzer.visitApply(Flow.java:1383)
        at jdk.compiler/com.sun.tools.javac.tree.JCTree$JCMethodInvocation.accept(JCTree.java:1745)
        at jdk.compiler/com.sun.tools.javac.tree.TreeScanner.scan(TreeScanner.java:49)
        at jdk.compiler/com.sun.tools.javac.comp.Flow$BaseAnalyzer.scan(Flow.java:440)
        at jdk.compiler/com.sun.tools.javac.tree.TreeScanner.visitSelect(TreeScanner.java:316)
        at jdk.compiler/com.sun.tools.javac.tree.JCTree$JCFieldAccess.accept(JCTree.java:2273)
        at jdk.compiler/com.sun.tools.javac.tree.TreeScanner.scan(TreeScanner.java:49)
        at jdk.compiler/com.sun.tools.javac.comp.Flow$BaseAnalyzer.scan(Flow.java:440)
        at jdk.compiler/com.sun.tools.javac.comp.Flow$FlowAnalyzer.visitApply(Flow.java:1381)
        at jdk.compiler/com.sun.tools.javac.tree.JCTree$JCMethodInvocation.accept(JCTree.java:1745)
        at jdk.compiler/com.sun.tools.javac.tree.TreeScanner.scan(TreeScanner.java:49)
        at jdk.compiler/com.sun.tools.javac.comp.Flow$BaseAnalyzer.scan(Flow.java:440)
        at jdk.compiler/com.sun.tools.javac.tree.TreeScanner.visitExec(TreeScanner.java:219)
```
Comments
Fix Request (17u) I'd like to backport this fix to 17u. It prevents NPE in javac. The patch applies cleanly. Tested with langtools tests, new test fails without the patch, passes with it.
05-10-2021

Changeset: 75d987a0 Author: Vicente Romero <vromero@openjdk.org> Date: 2021-08-31 15:40:17 +0000 URL: https://git.openjdk.java.net/jdk/commit/75d987a0dd6f8cc41808f7ba566e914817e465dc
31-08-2021

this issue seems to have been caused by the fix for: JDK-8205418
25-08-2021

javac was able to issue an error in 8-pool, 9, 10, 11
25-08-2021

this code works: import static java.util.Map.Entry.comparingByKey; import java.util.List; import java.util.Map; import java.util.stream.Stream; public class Test_8262095 { void f(Stream<Map.Entry<Long, List<String>>> stream) { stream .sorted( Map.Entry.<Long, List<String>>comparingByKey() .thenComparing((Map.Entry<Long, List<String>> e) -> e.getValue().hashCode())) .count(); } } so here javac basically don't have enough info to determine the bounds for type variable `V` in Map.Entry, this is because comparingByKey() needs to be attributed as a standalone expression. Still javac should fail nicely with a compiler error.
24-08-2021

similar to JDK-8233655
15-06-2021

See another report with a similar stack trace here: https://mail.openjdk.java.net/pipermail/compiler-dev/2021-June/017227.html
11-06-2021