Skip to content

Lambda parameter confuses #1373

Closed
Closed

Description

@agrieve
import org.chromium.build.annotations.NullMarked;
import org.chromium.build.annotations.Nullable;

@NullMarked
class Foo {
  interface Func<ParamT extends @Nullable Object, RetT extends @Nullable Object> {
    RetT apply(ParamT p);
  }

  public static <RetT extends @Nullable Object> RetT run(Func<String, RetT> func) {
    return func.apply("");
  }

  static void repro() {
      run(s -> s == null ? null : s);
  }
}

give:

Foo.java:16: warning: [NullAway] returning @Nullable expression from method with @NonNull return type
      run(s -> s == null ? null : s);
          ^
    (see http://t.uber.com/nullaway )

The return type is <RetT extends @Nullable Object>, so null should be fine.

Interestingly, this lambda does not emit a warning:

      run(s -> null, "");

Using a subclass rather than a lambda also does not emit a warning.

Activity

  1. added
    jspecify
    on Dec 10, 2025
  2. msridhar commented on Dec 10, 2025

    @msridhar
    Contributor

    Thanks for the report. This doesn't work because we need to run a dataflow analysis within the lambda body to figure out that s == null ? null : s is in fact @Nullable. We haven't quite implemented that properly yet. FYI @dhruv-agr

  3. added a commit that references this issue on Dec 19, 2025
    f4f03c0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugjspecify

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions