@MonotonicNonNull Should Consider Field non-null When Lambda is Assigned to It
Example:
@NullMarked
class Foo {
@MonotonicNonNull Runnable mRunnable;
void foo() {
mRunnable = () -> {
// This should not warn about mRunnable being null.
mRunnable.run();
};
}
}
Interesting! How often does this come up in your code base? The bug is that we use the environment from the program point just before the lambda is created to reason about what will be non-null in the body. But here, NullAway only concludes that mRunnable is non-null at the point immediately after the assignment is completed. A general fix for this kind of thing would be rather involved. If this comes up a lot for you all we could consider a bit of a one-off hack to fix it.
This is the first time so far, I reported it because I thought it was kind of fun :). I figure this is only worth supporting if there's an easy way to check for the exact case of "lambda is directly assigned to the field".