JDK-8268592 : JDK-8262891 causes an NPE in Lint.augment
  • Type: Bug
  • Component: tools
  • Sub-Component: javac
  • Affected Version: 17
  • Priority: P2
  • Status: Resolved
  • Resolution: Fixed
  • Submitted: 2021-06-11
  • Updated: 2021-07-15
  • Resolved: 2021-07-01
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 b30Fixed 18Fixed
Related Reports
Relates :  
Relates :  
Description
This crash bisects to JDK-8262891: earlier versions accept this code as valid, after that commit it causes an NPE.

The Lint.augment stack trace is similar to JDK-8181464, where mcimadamore noted:

> this problem of javac crashing because of a 'null' Lint happens very frequently - and in cases where, if attribution could run its course, a regular error message would be displayed. So perhaps it's time we address this by having a 'dummy' Lint object which doesn't do anything instead of 'null' - that would let execution flow even in exceptional cases like this one.

Repro:

===
import java.util.Collection;
import java.util.function.Function;
import java.util.function.Supplier;

abstract class T {

  abstract <T> T r(Function<String, Supplier<T>> x);

  enum E {
    ONE
  }

  abstract <T> Supplier<T> f(Function<T, Supplier<T>> x);

  public void updateAcl(E e, Supplier<Void> v) {
    r(
        (String t) -> {
          switch (e) {
            case ONE:
              return f(
                  a -> {
                    Collection<String> m = null;
                    return v;
                  });
            default:
              return v;
          }
        });
  }
}
===

$ javac T.java
java.lang.NullPointerException: Cannot invoke "com.sun.tools.javac.code.Symbol.getDeclarationAttributes()" because "sym" is null
        at jdk.compiler/com.sun.tools.javac.code.Lint.augment(Lint.java:75)
        at jdk.compiler/com.sun.tools.javac.comp.Flow$AliveAnalyzer.visitVarDef(Flow.java:595)
        at jdk.compiler/com.sun.tools.javac.tree.JCTree$JCVariableDecl.accept(JCTree.java:1028)
        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:445)
        at jdk.compiler/com.sun.tools.javac.comp.Flow$AliveAnalyzer.scanStat(Flow.java:505)
        at jdk.compiler/com.sun.tools.javac.comp.Flow$AliveAnalyzer.scanStats(Flow.java:513)
        at jdk.compiler/com.sun.tools.javac.comp.Flow$AliveAnalyzer.visitBlock(Flow.java:605)
        at jdk.compiler/com.sun.tools.javac.tree.JCTree$JCBlock.accept(JCTree.java:1092)
        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:445)
        at jdk.compiler/com.sun.tools.javac.comp.Flow$AliveAnalyzer.scanStat(Flow.java:505)
        at jdk.compiler/com.sun.tools.javac.comp.Flow$AliveAnalyzer.visitLambda(Flow.java:879)
        at jdk.compiler/com.sun.tools.javac.tree.JCTree$JCLambda.accept(JCTree.java:1975)
        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:445)
        at jdk.compiler/com.sun.tools.javac.tree.TreeScanner.scan(TreeScanner.java:57)
        at jdk.compiler/com.sun.tools.javac.comp.Flow$AliveAnalyzer.visitApply(Flow.java:856)
        at jdk.compiler/com.sun.tools.javac.tree.JCTree$JCMethodInvocation.accept(JCTree.java:1798)
        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:445)
        at jdk.compiler/com.sun.tools.javac.comp.Flow$AliveAnalyzer.visitReturn(Flow.java:845)
        at jdk.compiler/com.sun.tools.javac.tree.JCTree$JCReturn.accept(JCTree.java:1710)
        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:445)
        at jdk.compiler/com.sun.tools.javac.tree.TreeScanner.scan(TreeScanner.java:57)
        at jdk.compiler/com.sun.tools.javac.tree.TreeScanner.visitCase(TreeScanner.java:181)
        at jdk.compiler/com.sun.tools.javac.tree.JCTree$JCCase.accept(JCTree.java:1336)
        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:445)
        at jdk.compiler/com.sun.tools.javac.comp.Flow$AliveAnalyzer.analyzeTree(Flow.java:907)
        at jdk.compiler/com.sun.tools.javac.comp.Flow.aliveAfter(Flow.java:274)
        at jdk.compiler/com.sun.tools.javac.comp.Attr.handleSwitch(Attr.java:1794)
        at jdk.compiler/com.sun.tools.javac.comp.Attr.visitSwitch(Attr.java:1580)
        at jdk.compiler/com.sun.tools.javac.tree.JCTree$JCSwitch.accept(JCTree.java:1295)
        at jdk.compiler/com.sun.tools.javac.comp.Attr.attribTree(Attr.java:668)
        at jdk.compiler/com.sun.tools.javac.comp.Attr.attribStat(Attr.java:742)
        at jdk.compiler/com.sun.tools.javac.comp.Attr.attribStats(Attr.java:761)
        at jdk.compiler/com.sun.tools.javac.comp.Attr.visitBlock(Attr.java:1439)
        at jdk.compiler/com.sun.tools.javac.tree.JCTree$JCBlock.accept(JCTree.java:1092)
        at jdk.compiler/com.sun.tools.javac.comp.Attr.attribTree(Attr.java:668)
        at jdk.compiler/com.sun.tools.javac.comp.Attr.attribStat(Attr.java:742)
        at jdk.compiler/com.sun.tools.javac.comp.Attr.attribStats(Attr.java:761)
        at jdk.compiler/com.sun.tools.javac.comp.Attr.visitBlock(Attr.java:1439)
        at jdk.compiler/com.sun.tools.javac.tree.JCTree$JCBlock.accept(JCTree.java:1092)
        at jdk.compiler/com.sun.tools.javac.comp.ArgumentAttr.visitTree(ArgumentAttr.java:207)
        at jdk.compiler/com.sun.tools.javac.tree.JCTree$Visitor.visitBlock(JCTree.java:3413)
        at jdk.compiler/com.sun.tools.javac.tree.JCTree$JCBlock.accept(JCTree.java:1092)
        at jdk.compiler/com.sun.tools.javac.comp.ArgumentAttr.attribArg(ArgumentAttr.java:197)
        at jdk.compiler/com.sun.tools.javac.comp.Attr.attribTree(Attr.java:666)
        at jdk.compiler/com.sun.tools.javac.comp.DeferredAttr.attribSpeculative(DeferredAttr.java:500)
        at jdk.compiler/com.sun.tools.javac.comp.DeferredAttr.attribSpeculative(DeferredAttr.java:480)
        at jdk.compiler/com.sun.tools.javac.comp.DeferredAttr.attribSpeculative(DeferredAttr.java:467)
        at jdk.compiler/com.sun.tools.javac.comp.DeferredAttr.attribSpeculativeLambda(DeferredAttr.java:442)
        at jdk.compiler/com.sun.tools.javac.comp.ArgumentAttr.lambda$visitLambda$4(ArgumentAttr.java:301)
        at jdk.compiler/com.sun.tools.javac.comp.ArgumentAttr.processArg(ArgumentAttr.java:242)
        at jdk.compiler/com.sun.tools.javac.comp.ArgumentAttr.visitLambda(ArgumentAttr.java:299)
        at jdk.compiler/com.sun.tools.javac.tree.JCTree$JCLambda.accept(JCTree.java:1975)
        at jdk.compiler/com.sun.tools.javac.comp.ArgumentAttr.attribArg(ArgumentAttr.java:197)
        at jdk.compiler/com.sun.tools.javac.comp.Attr.attribTree(Attr.java:666)
        at jdk.compiler/com.sun.tools.javac.comp.Attr.attribArgs(Attr.java:769)
        at jdk.compiler/com.sun.tools.javac.comp.Attr.visitApply(Attr.java:2554)
        at jdk.compiler/com.sun.tools.javac.tree.JCTree$JCMethodInvocation.accept(JCTree.java:1798)
        at jdk.compiler/com.sun.tools.javac.comp.Attr.attribTree(Attr.java:668)
        at jdk.compiler/com.sun.tools.javac.comp.Attr.attribExpr(Attr.java:721)
        at jdk.compiler/com.sun.tools.javac.comp.Attr.visitExec(Attr.java:2272)
        at jdk.compiler/com.sun.tools.javac.tree.JCTree$JCExpressionStatement.accept(JCTree.java:1585)
        at jdk.compiler/com.sun.tools.javac.comp.Attr.attribTree(Attr.java:668)
        at jdk.compiler/com.sun.tools.javac.comp.Attr.attribStat(Attr.java:742)
        at jdk.compiler/com.sun.tools.javac.comp.Attr.attribStats(Attr.java:761)
        at jdk.compiler/com.sun.tools.javac.comp.Attr.visitBlock(Attr.java:1439)
        at jdk.compiler/com.sun.tools.javac.tree.JCTree$JCBlock.accept(JCTree.java:1092)
        at jdk.compiler/com.sun.tools.javac.comp.Attr.attribTree(Attr.java:668)
        at jdk.compiler/com.sun.tools.javac.comp.Attr.attribStat(Attr.java:742)
        at jdk.compiler/com.sun.tools.javac.comp.Attr.visitMethodDef(Attr.java:1229)
        at jdk.compiler/com.sun.tools.javac.tree.JCTree$JCMethodDecl.accept(JCTree.java:922)
        at jdk.compiler/com.sun.tools.javac.comp.Attr.attribTree(Attr.java:668)
        at jdk.compiler/com.sun.tools.javac.comp.Attr.attribStat(Attr.java:742)
        at jdk.compiler/com.sun.tools.javac.comp.Attr.attribClassBody(Attr.java:5478)
        at jdk.compiler/com.sun.tools.javac.comp.Attr.attribClass(Attr.java:5369)
        at jdk.compiler/com.sun.tools.javac.comp.Attr.attribClass(Attr.java:5200)
        at jdk.compiler/com.sun.tools.javac.comp.Attr.attrib(Attr.java:5145)
        at jdk.compiler/com.sun.tools.javac.main.JavaCompiler.attribute(JavaCompiler.java:1317)
        at jdk.compiler/com.sun.tools.javac.main.JavaCompiler.compile(JavaCompiler.java:946)
        at jdk.compiler/com.sun.tools.javac.main.Main.compile(Main.java:317)
        at jdk.compiler/com.sun.tools.javac.main.Main.compile(Main.java:176)
        at jdk.compiler/com.sun.tools.javac.Main.compile(Main.java:64)
        at jdk.compiler/com.sun.tools.javac.Main.main(Main.java:50)
Comments
Changeset: 4930ae96 Author: Liam Miller-Cushon <cushon@openjdk.org> Date: 2021-07-01 00:16:23 +0000 URL: https://git.openjdk.java.net/jdk17/commit/4930ae96d8083070482f6ac78faed9ae9dda2df7
01-07-2021

I realized this has different symptoms than JDK-8181464--here the sym being passed in is null, the state of the Lint itself seems fine. The change here seems to be the use of flow.aliveAfter, and that the variable declaration in the nested lambda hasn't been attributed at that point.
14-06-2021