Skip to content

Lambda parameter confuses #1373

@agrieve

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugjspecifyRelated to support for jspecify standard (see jspecify.dev)

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions