Skip to content
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

Field with @RequiresNonNull + @MonotonicNonNull is treated as nullable inside lambda #6595

Open
cushon opened this issue May 13, 2024 · 0 comments

Comments

@cushon
Copy link
Contributor

cushon commented May 13, 2024

import org.checkerframework.checker.nullness.qual.MonotonicNonNull;
import org.checkerframework.checker.nullness.qual.RequiresNonNull;

class Require {
  @MonotonicNonNull String s;

  @RequiresNonNull("s")
  Supplier<String> s() {
    return () -> s;
  }

  interface Supplier<T> {
    T get();
  }
}

Actual:

$ ./checker-framework-3.43.0/checker/bin/javac -processor nullness Require.java
Require.java:9: error: [return] incompatible types in return.
    return () -> s;
                 ^
  type of expression: @Initialized @MonotonicNonNull String
  method return type: @Initialized @NonNull String
1 error

Expected:

No error: Even though the lambda may run later, s is not only known to be non-null initially but is also known to remain so because of @MonotonicNonNull.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant