Repository navigation
Description
NullAway crashes with IllegalStateException: null filterNullStore for tree when it checks a map callback that follows a filter whose predicate NullAway does not check. The predicate goes unchecked when it is an anonymous class whose test method is annotated @NullUnmarked or @SuppressWarnings("NullAway"). Error Prone reports the crash as An unhandled exception was thrown by the Error Prone static analysis plugin. on the dereference inside the map callback, and compilation fails.
The same happens for java.util.stream.Stream and for RxJava 2 io.reactivex.Observable (filter(new Predicate<Box>() { @NullUnmarked ... }).map(new Function<Box, Integer>() { ... }), adapted from FrameworkTests#rxSupportNegativeCases). It was found by mutating sources from NullAway's own test suite.
Versions
- NullAway:
masterat a03b7bb (0.14.3-SNAPSHOT).StreamNullabilityPropagator.javahas not changed sincev0.14.2, but I did not run the reproducer against the0.14.2release. - Error Prone: 2.50.0
- JDK: 21 (
./gradlew :nullaway:test) and 27 (./gradlew :nullaway:testJdk27) - Options:
-XepOpt:NullAway:AnnotatedPackages=com.uber
Reproducer
A test in nullaway/src/test/java/com/uber/nullaway/:
package com.uber.nullaway;
import java.util.List;
import org.junit.Test;
public class ScratchReproTest extends NullAwayTestsBase {
@Test
public void nullUnmarkedFilterPredicate() {
makeTestHelperWithArgs(List.of("-XepOpt:NullAway:AnnotatedPackages=com.uber"))
.addSourceLines(
"com/uber/Test.java",
"""
package com.uber;
import java.util.function.Predicate;
import java.util.stream.Stream;
import org.jspecify.annotations.NullUnmarked;
class Test {
Stream<Integer> f(Stream<String> s) {
return s.filter(
new Predicate<String>() {
@NullUnmarked
@Override
public boolean test(String x) {
return true;
}
})
.map(x -> x.length());
}
}
""")
.doTest();
}
}./gradlew :nullaway:test --tests 'com.uber.nullaway.ScratchReproTest'Removing @NullUnmarked makes the test pass with no diagnostics. Replacing @NullUnmarked with @SuppressWarnings("NullAway") crashes the same way.
Actual
/com/uber/Test.java:15: error: An unhandled exception was thrown by the Error Prone static analysis plugin.
.map(x -> x.length());
^
error-prone version: 2.50.0
BugPattern: NullAway
Stack Trace:
org.checkerframework.nullaway.javacutil.BugInCF: Problem with initial store for CFGLambda(
(x)->x.length()
), parameters=[x]
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.resultForExpr(DataFlow.java:304)
at com.uber.nullaway.dataflow.DataFlow.expressionDataflow(DataFlow.java:227)
at com.uber.nullaway.dataflow.AccessPathNullnessAnalysis.getNullness(AccessPathNullnessAnalysis.java:119)
at com.uber.nullaway.NullAway.nullnessFromDataflow(NullAway.java:3033)
at com.uber.nullaway.NullAway.mayBeNullExpr(NullAway.java:3001)
at com.uber.nullaway.NullAway.matchDereference(NullAway.java:3071)
at com.uber.nullaway.NullAway.matchMemberSelect(NullAway.java:629)
...
Caused by: java.lang.IllegalStateException: null filterNullStore for tree
at com.uber.nullaway.handlers.StreamNullabilityPropagator.onDataflowInitialStore(StreamNullabilityPropagator.java:678)
at com.uber.nullaway.handlers.CompositeHandler.onDataflowInitialStore(CompositeHandler.java:181)
at com.uber.nullaway.dataflow.CoreNullnessStoreInitializer.lambdaInitialStore(CoreNullnessStoreInitializer.java:184)
at com.uber.nullaway.dataflow.CoreNullnessStoreInitializer.getInitialStore(CoreNullnessStoreInitializer.java:54)
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)
... 142 more
With the RxJava reproducer and an anonymous Function as the map callback, the Caused by exception and its top two frames are the same, and the initial store is built through CoreNullnessStoreInitializer.methodInitialStore instead of lambdaInitialStore.
Expected
NullAway checks the map callback without facts from the predicate and reports no error, as it does for the same code without @NullUnmarked.
Possible cause (a guess; the report stands without it)
StreamNullabilityPropagator fills filterToNSMap from onMatchReturn, which NullAway does not call inside unmarked or suppressed code, and onDataflowInitialStore throws when the predicate has no entry instead of contributing no facts.
Duplicates searched
Issues and pull requests, open and closed, for filterNullStore, filterToNSMap, StreamNullabilityPropagator, onDataflowInitialStore, NullUnmarked stream, NullUnmarked rx, NullUnmarked filter, SuppressWarnings stream, and Problem with initial store. The nearest hit is #697, a feature request to propagate facts about closure variables between stream callbacks; it reports no crash.
Activity
Fix crash in map callbacks after an unmarked or suppressed filter pre…
Run crash and metamorphic oracles over NullAway's test sources on master