Skip to content

False-positive for wildcard generics #1455

Closed

Description

@agrieve

This started when updating chrome from 0.12.14 -> 0.13.0.

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

@NullMarked
class Foo<OuterT> {

  interface Supplier<T extends @Nullable Object> {
    T get();
  }

  Supplier<@Nullable OuterT> sup;

  <T extends Supplier<?>> T acceptSup(T supplier) {
    return supplier;
  }

  void test() {
    acceptSup(sup);
  }
}
Foo.java:18: warning: [NullAway] incompatible types: Supplier<@org.chromium.build.annotations.Nullable OuterT> cannot be converted to Supplier<OuterT>
    acceptSup(sup);
              ^
    (see http://t.uber.com/nullaway )

Since acceptSup takes a T extends Supplier<?>, I think T should accept @nullable generics.

There is no warning if passing a Supplier<@Nullable String>, nor if acceptSup takes a Supplier<?> (doesn't use generics).

Activity

  1. agrieve commented on Jan 27, 2026

    @agrieve
    ContributorAuthor

    Maybe a dupe of #1350?

  2. giruuuuj commented on Jan 30, 2026

    @giruuuuj

    Fix wildcard generics false-positive (Issue #1455)

    This fix addresses false-positive warnings when using wildcard generics with nullable type parameters. Previously, wildcard types were skipped during nullability checking, causing incorrect "incompatible types" errors.

    Changes:

    • Implemented proper wildcard type handling in CheckIdenticalNullabilityVisitor
    • Unbounded wildcards (?) now correctly accept nullable types
    • Added comprehensive wildcard bound comparison logic
    • Fixed TODO comments for wildcard handling

    Test Results:

    • Basic wildcard assignment tests pass
    • Generic method type inference edge cases may need further refinement

    Fixes #1455

  3. yuxincs commented on Jan 30, 2026

    @yuxincs
    Contributor

    Hi @giruuuuj, while we really appreciate comments and discussions on existing issues and welcome insights from community, the comments you've been posting carry lower values and appears to be generated from LLMs. These comments cause burdens for maintainers and the issue creators since they often get notified whenever there is an interaction in the issues.

    Please refrain from posting such comments in the future.

  4. added a commit that references this issue on Mar 25, 2026
    e78dc89
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

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions