Repository navigation
Description
I believe #1328 introduces a bug because it doesn't keep its caches in sync.
In an internal repo, we were getting the following error messages when running NullAway 0.12.12:
BugPattern: NullAway
Stack Trace:
java.lang.NullPointerException: Cannot invoke "org.checkerframework.nullaway.dataflow.cfg.ControlFlowGraph.getTreeLookup()" because "this.cfg" is null
at org.checkerframework.nullaway.dataflow.analysis.AbstractAnalysis.getResult(AbstractAnalysis.java:180)
at com.uber.nullaway.dataflow.DataFlow.resultFor(DataFlow.java:318)
at com.uber.nullaway.dataflow.DataFlow.resultForExpr(DataFlow.java:296)
at com.uber.nullaway.dataflow.DataFlow.expressionDataflow(DataFlow.java:241)
at com.uber.nullaway.dataflow.AccessPathNullnessAnalysis.getNullness(AccessPathNullnessAnalysis.java:115)
at com.uber.nullaway.NullAway.nullnessFromDataflow(NullAway.java:2746)
at com.uber.nullaway.NullAway.mayBeNullExpr(NullAway.java:2712)
at com.uber.nullaway.NullAway.lambda$handleInvocation$1(NullAway.java:2047)
at com.uber.nullaway.InvocationArguments.forEach(InvocationArguments.java:86)
at com.uber.nullaway.NullAway.handleInvocation(NullAway.java:2014)
at com.uber.nullaway.NullAway.matchMethodInvocation(NullAway.java:444)
at com.google.errorprone.scanner.ErrorProneScanner.processMatchers(ErrorProneScanner.java:509)
...
In the following block:
ControlFlowGraph cfg = cfgCache.getUnchecked(CfgParams.create(path, env));
AnalysisParams aparams = AnalysisParams.create(transfer, cfg);
@SuppressWarnings("unchecked")
Analysis<A, S, T> analysis = (Analysis<A, S, T>) analysisCache.getUnchecked(aparams);
if (performAnalysis && !alreadyRunAnalyses.contains(aparams)) {
analysis.performAnalysis(cfg);
alreadyRunAnalyses.add(aparams);
}What I think happens is that:
Dataflow#analysisCachewill evict an analysis, but it won't clear it fromalreadyRunAnalyses- When we see the same path again, we will create new analyses, but because the
aparamscompleted before at some point, the if condition will fail as it already contains the particularaparams. - It will therefore not run
analysis.performAnalysis(cfg)which initialises the fields we care aboutcfg - The analysis you get back will be malformed and you will get the
NullPointerException.
The fix is probably along the lines of adding a removal listener to analysisCache that will also remove the key from aparams, keeping the two caches in sync.
What was a bit confusing to me was that it was non-deterministic in that some builds would pass, others would fail. However, when it failed, it would consistently fail at the same point. So perhaps it's some sort of ordering issue when Errorprone/Nullaway is processing the files. This has made it a bit difficult to get a reliable reproduction, but I believe the above steps is the only way to get a malformed Analysis object back.
I'm new to the NullAway repository, so I'm not sure about all the different lifecycles, but how I think this manifests is when you have a
class with lots of different method invocations, but you return to one previously handled
Activity
msridhar commentedon Nov 25, 2025
Thanks for this report! Your explanation makes a lot of sense. I did do a further change to this code in #1334 that might fix the issue you are seeing. I don't know how easy it is for you to try to make a local snapshot build (instructions here) and use that to test. I'd like to think about this a bit more, though, and try to make sure we have a more ironclad guarantee that these caches are consistent.
felixdesouza commentedon Nov 26, 2025
I think that may do it?
My thought - if you're open to it - would be to forego the two caches, and just have an analysis that's keeps track of whether it's been performed or not.
What if you have a
MemoizingAnalysis- please pick a better name 😅 - where it extendsAnalysis, and takes in the analysis as a delegate.performAnalysiswill only return the first result => gets us the desired behaviour.getResultwhen you haven't done any analysis.I initially had an idea for having a type like
CompletableAnalysisthat didn't extendAnalysisbut would keep track of whether the analysis has been performed yet, but you'd need to return the underlying analysis, so you could potentially get out of sync that way.msridhar commentedon Nov 26, 2025
That's a great idea! I gave it a shot in #1353. It's running through benchmarking / CI now; let's see how it goes 🙂
felixdesouza commentedon Nov 26, 2025
Hello again!
I built a snapshot of #1353 and ran a build 10 times in a row for one of the failing repos. 100% pass rate 🎉 .
Ran a similar test (10 in a row) but for
0.12.12and 40% builds failed and similarly all at the same point. 😬Mostly for my curiosity, I'd love to know where the non-determinism comes from here, I wouldn't have thought gradle would be calling the compiler with an arbitrary order of source files but idk.
msridhar commentedon Nov 26, 2025
Thanks for confirming! We'll try to get the fix landed and a new release cut soon. And yeah I'm not sure about the non-determinism; would be good to track down but might take some work.
Better fix for dataflow analysis caching (#1353)
felixdesouza commentedon Nov 28, 2025
Thanks for merging this! Do you have a rough idea of when you might cut a release?
msridhar commentedon Nov 28, 2025
We're aiming to cut a release early next week @felixdesouza. Thanks!
msridhar commentedon Dec 1, 2025
@felixdesouza NullAway 0.12.13 is released with this fix
felixdesouza commentedon Dec 1, 2025
fantastic! thanks so much!