-
Notifications
You must be signed in to change notification settings - Fork 301
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Feature Request: Use an annotation like @MonotonicNonNull
for better reasoning about field nullability inside lambdas
#1148
Comments
Within a single method, we already have this level of reasoning, and it could be extended to callee methods via
In the example the code is safe because of the Does the real code use a |
Here's the most recent example: https://chromium-review.googlesource.com/c/chromium/src/+/6264464/6/components/messages/android/java/src/org/chromium/components/messages/MessageWrapper.java#140 I think all of the real examples are for code that is run asynchronously, which I guess makes this different from streams. I don't love it, but maybe could use a new annotation to remove the need for global reasoning. E.g. I thought this one might be hard :P. It's certainly something we can live without. |
Thinking more this seems like it could be handled if we had better support for checking a |
@MonotonicNonNull
for better reasoning about field nullability inside lambdas
Well that's a much better name than I came up with :P. I'm sure we'd use it if support were added. |
Fixes #1148 We add explicit support for any annotation named `@MonotonicNonNull` and add our own version of the annotation to our annotations package. The main additional support is that we now reason that once assigned a non-null value, `@MonotonicNull` fields remain non-null when accessed from subsequent lambdas, even if the lambdas are invoked asynchronously.
Wow, great stuff! Looking forward to trying this out! |
We should have a new release out soon! |
@agrieve NullAway 0.12.4 is now released with this fix |
Includes fixes to warnings introduced by the change. Main fixes are: uber/NullAway#1126 uber/NullAway#1139 uber/NullAway#1148 uber/NullAway#1151 No-try due to flaky optional windows bot. No-Try: true Bug: 389129271 Change-Id: Ia2abd8482ffabba7885b616048996f97da856b9a Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/6325293 Reviewed-by: Mohamed Heikal <mheikal@chromium.org> Commit-Queue: Andrew Grieve <agrieve@chromium.org> Owners-Override: Andrew Grieve <agrieve@chromium.org> Cr-Commit-Position: refs/heads/main@{#1429012}
Includes fixes to warnings introduced by the change. Main fixes are: uber/NullAway#1126 uber/NullAway#1139 uber/NullAway#1148 uber/NullAway#1151 No-try due to flaky optional windows bot. No-Try: true Bug: 389129271 Change-Id: Ia2abd8482ffabba7885b616048996f97da856b9a Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/6325293 Reviewed-by: Mohamed Heikal <mheikal@chromium.org> Commit-Queue: Andrew Grieve <agrieve@chromium.org> Owners-Override: Andrew Grieve <agrieve@chromium.org> Cr-Commit-Position: refs/heads/main@{#1429012} NOKEYCHECK=True GitOrigin-RevId: 4c17934359abc12d6cf5aef20a073285a25a2d50
Just tried this out. Working great for non-static fields, but it looks like it's treated the same as |
Support for this annotation was recently added to NullAway. It removes some uses of assumeNonNull(). Note: It does not yet work with static fields. Reported here: uber/NullAway#1148 (comment) Bug: 389129271 Change-Id: I1c24769b48cb381ba6a5974b24d04f2c772d226d Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/6334458 Owners-Override: Andrew Grieve <agrieve@chromium.org> Auto-Submit: Andrew Grieve <agrieve@chromium.org> Reviewed-by: Henrique Nakashima <hnakashima@chromium.org> Commit-Queue: Andrew Grieve <agrieve@chromium.org> Cr-Commit-Position: refs/heads/main@{#1429766}
@agrieve sorry I didn't test static fields. I think I know what needs to be done though. Can you open a separate issue to make it easier to track? |
Similar to #570, but not stream-specific.
We've hit this scenario 3 or 4 times in chrome so far:
The text was updated successfully, but these errors were encountered: