-
Notifications
You must be signed in to change notification settings - Fork 331
Invalidate dataflow cache for lambdas inside loops #1381
Copy link
Copy link
Closed
Description
Context
Follow-up from PR #1375 (comment: #1375 (comment))
In nullaway/src/main/java/com/uber/nullaway/generics/GenericsChecks.java around lines 1001-1002, there is a TODO noting that dataflow results for lambdas inside loops should be invalidated to avoid caching incomplete results from earlier loop iterations.
Problem
Without this invalidation, the analysis could cache dataflow facts from an incomplete loop iteration, leading to incorrect nullness conclusions on subsequent iterations. This is a correctness concern.
Proposed Solution
Implement invalidation by:
- Detecting when a lambda AST node is located within a loop construct (for/while/do/foreach)
- When performing dataflow analysis for that lambda, either:
- (a) Mark the lambda's dataflow result as non-cacheable, OR
- (b) Explicitly remove/clear its entry from the analysis cache immediately after analysis completes
- Add unit tests that exercise a lambda within a loop to ensure subsequent iterations do not reuse stale cached facts
- Add a brief comment referencing this issue for future reasoning
Related Code
The TODO is in the refineArgumentTypeWithDataflow method:
// TODO if we did the dataflow analysis for a lambda, always remove the analysis result from the
// cache for safetyReactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels