Model Map.remove as nullable#1623
Conversation
|
Note Reviews pausedIt looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the Use the following commands to manage reviews:
Use the checkboxes below for quick actions:
Walkthrough
Suggested reviewers
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
ba9e9b7 to
504e5aa
Compare
Signed-off-by: Vinod Kumar <codingkiddo@gmail.com>
504e5aa to
3d2ca84
Compare
subhramit
left a comment
There was a problem hiding this comment.
@codingkiddo your commits will be squashed anyway at the time of merge, so you can avoid force-pushing. Incremental changes are easier to track via non-squashed commits.
Signed-off-by: Vinod Kumar <codingkiddo@gmail.com>
|
Thanks for this change! While I agree the change is correct, it is going to be a bit disruptive in terms of generating new errors for users (see the failed integration tests). I think at the least, we need Some of the relevant code in NullAway for this support is: NullAway/nullaway/src/main/java/com/uber/nullaway/dataflow/AccessPath.java Lines 188 to 191 in f40a9fa I think basically, we want to handle (Aside: with JSpecify mode, we'll want to separately reason about maps with a |
Signed-off-by: Vinod Kumar <codingkiddo@gmail.com>
Thanks for the detailed pointers. I updated the PR so I also added regression tests for the |
|
@codingkiddo thanks for the updates! I've made some further changes (with help of Codex) to handle cases like: if (map.containsKey(key)) {
map.remove(key).toString(); // intended to be safe
map.remove(key).toString(); // should warn: key was removed
map.get(key).toString(); // should warn: key was removed
}This required slightly more involved changes than what you did. I've gone through the failures in the integration tests and the warnings look valid and should be fairly easy to fix. So, I will likely land this, and then we'll try to cut a release soonish for users. |
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## master #1623 +/- ##
=========================================
Coverage 88.10% 88.10%
- Complexity 3046 3050 +4
=========================================
Files 105 105
Lines 10181 10192 +11
Branches 2062 2066 +4
=========================================
+ Hits 8970 8980 +10
Misses 572 572
- Partials 639 640 +1 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
Thanks for the follow-up and for handling the more involved dataflow cases. That makes sense — after Glad the remaining integration-test warnings look valid. Thanks for moving this forward! |
Fixes #1591.
This PR models
java.util.Map.remove(Object)as returning nullable, similar to the existing model forMap.get(Object).Map.remove(Object)can returnnullwhen there is no mapping for the key, so dereferencing its result should produce a NullAway warning.Changes:
java.util.Map.remove(Object)to the always-nullable library return modelsmap.remove(key)Tested with:
./gradlew :nullaway:test --tests "com.uber.nullaway.FrameworkTests.defaultLibraryModelsMapRemove"./gradlew spotlessCheckSummary by CodeRabbit
Map.remove(...)so its return value is treated as potentiallynull, helping prevent unsafe dereferences after removing entries.map.remove(...).toString()and verifies the expected null-safety diagnostic.