Lokasi ngalangkungan proxy:   [ UP ]  
[Ngawartoskeun bug]   [Panyetelan cookie]                
Skip to content

NullPointerException in getEnvNullnessStoreForClass for a @NullMarked local class inside a method of an unmarked local or anonymous class #2004

Closed

Description

@vlsi

When a @NullMarked local class is declared inside a method of a local or anonymous class that is not null-marked, NullAway crashes with BugInCF: Problem with initial store, caused by a NullPointerException from Objects.requireNonNull in NullnessStoreInitializer.getEnvNullnessStoreForClass. The @NullMarked class needs no members.

Versions: NullAway master at 5ba2b54, Error Prone 2.50.0; the same crash on JDK 21.0.9 and on Zulu JDK 27 (27.28.103).

Options: -XepOpt:NullAway:OnlyNullMarked=true. JSpecify mode is not needed.

package com.foo;
import org.jspecify.annotations.NullMarked;
class Test {
  void test() {
    class A {
      void m() {
        @NullMarked
        class B {}
      }
    }
  }
}

Actual, from the first NullAway frame:

/Test.java:8: error: An unhandled exception was thrown by the Error Prone static analysis plugin.
        class B {}
        ^
     error-prone version: 2.50.0
     BugPattern: NullAway
     Stack Trace:
     org.checkerframework.nullaway.javacutil.BugInCF: Problem with initial store for CFGMethod(
  void m() {
      @NullMarked
      class B {
          B() {
              super();
          }
      }
  }
  ), parameters=[]
  	at org.checkerframework.nullaway.dataflow.analysis.ForwardAnalysisImpl.initInitialInputs(ForwardAnalysisImpl.java:339)
  	at org.checkerframework.nullaway.dataflow.analysis.AbstractAnalysis.init(AbstractAnalysis.java:519)
  	at org.checkerframework.nullaway.dataflow.analysis.ForwardAnalysisImpl.performAnalysis(ForwardAnalysisImpl.java:102)
  	at com.uber.nullaway.dataflow.RunOnceForwardAnalysisImpl.performAnalysis(RunOnceForwardAnalysisImpl.java:31)
  	at com.uber.nullaway.dataflow.DataFlow.dataflow(DataFlow.java:160)
  	at com.uber.nullaway.dataflow.DataFlow.resultFor(DataFlow.java:326)
  	at com.uber.nullaway.dataflow.DataFlow.resultBefore(DataFlow.java:270)
  	at com.uber.nullaway.dataflow.AccessPathNullnessAnalysis.getNullnessInfoBeforeNestedMethodNode(AccessPathNullnessAnalysis.java:219)
  	at com.uber.nullaway.NullAway.updateEnvironmentMapping(NullAway.java:491)
  	at com.uber.nullaway.NullAway.matchClass(NullAway.java:1980)
  	...
  Caused by: java.lang.NullPointerException
  	at java.base/java.util.Objects.requireNonNull(Objects.java:233)
  	at com.uber.nullaway.dataflow.NullnessStoreInitializer.getEnvNullnessStoreForClass(NullnessStoreInitializer.java:59)
  	at com.uber.nullaway.dataflow.CoreNullnessStoreInitializer.methodInitialStore(CoreNullnessStoreInitializer.java:75)
  	at com.uber.nullaway.dataflow.CoreNullnessStoreInitializer.getInitialStore(CoreNullnessStoreInitializer.java:63)
  	at com.uber.nullaway.dataflow.AccessPathNullnessPropagation.initialStore(AccessPathNullnessPropagation.java:280)
  	at com.uber.nullaway.dataflow.AccessPathNullnessPropagation.initialStore(AccessPathNullnessPropagation.java:154)
  	at org.checkerframework.nullaway.dataflow.analysis.ForwardAnalysisImpl.initInitialInputs(ForwardAnalysisImpl.java:337)
  	... 133 more

Expected: no crash and no diagnostic, since the source has no dereference and no null.

The same crash occurs in these variants:

  • A replaced by an anonymous class, Runnable r = new Runnable() { public void run() { @NullMarked class B {} } };, with the same options.
  • package com.uber;, -XepOpt:NullAway:AnnotatedPackages=com.uber, and @NullUnmarked on test(), which is how the crash first appeared.

Negative control: with @NullMarked class B {} declared directly in a method of Test, without the enclosing class A, NullAway reports nothing and does not crash.

Nearest reports: #711 and #1184, both closed, are NullPointerException: no environment stored for lambda, the same kind of missing environment entry for a lambda rather than a local class. Searched issues and pull requests for getEnvNullnessStoreForClass, getEnvironmentMapping, EnclosingEnvironmentNullness, updateEnvironmentMapping, NullnessStoreInitializer, Problem with initial store, BugInCF, no environment stored, local class, and NullUnmarked anonymous class.

Suspected cause (a guess; the report stands without it): NullAway.matchClass records an environment entry for a local or anonymous class only inside if (withinAnnotatedCode(state)) (nullaway/src/main/java/com/uber/nullaway/NullAway.java:1976), so A gets none. When it reaches the null-marked B, updateEnvironmentMapping runs dataflow over A.m(), and the initial store for that method looks up the entry for A with Objects.requireNonNull (nullaway/src/main/java/com/uber/nullaway/dataflow/NullnessStoreInitializer.java:59).

I found this by mutating sources from NullAway's own test suite (seed: SerializationTest#errorSerializationTestLocalTypesNested with @NullMarked added on the inner local class and @NullUnmarked on the method).

Activity

  1. added a commit that references this issue on Oct 21, 2026
    877c42e
  2. added a commit that references this issue on Oct 22, 2026
    27f78a1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions