Skip to content

@NonNull not working when used in generic return type #1354

@agrieve

Description

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

@NullMarked
class Foo {
  interface MaybeNull<T extends @Nullable Object> {
    T get();

    default MaybeNull<@NonNull T> asNonNull() {
      return (MaybeNull<@NonNull T>)this;
    }
  }

  static void accept(MaybeNull<String> nonNullThing) {}

  static void main() {
    MaybeNull<@Nullable String> nullable = null;
    accept(nullable.asNonNull());
  }
}

results in:

Foo.java:19: warning: [NullAway] incompatible types: MaybeNull<@Nullable String> cannot be converted to MaybeNull<String>
    accept(nullable.asNonNull());
                             ^
    (see http://t.uber.com/nullaway )

I would expect MaybeNull<@NonNull T>to mean MaybeNull<T> when T is @Nullable.

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions