Skip to content

Indicate when an inference failure is due to a @NonNull type variable upper bound #1721

Closed

Description

@msridhar

(From ben-manes/caffeine#2004 (comment))

16 errors read "inference failure: type variable V constrained to be both @nonnull and @nullable",
concentrated in generic inference and wildcards. These were Caffeine's fault, not NullAway's.
CompletableFuture<T extends @Nullable Object> and BiFunction<T, U, R> with all three bounded by
@Nullable Object; Caffeine's helpers declared plain type variables, which bind to non-null
Object in null-marked code, so they could not accept those types at all. Widening the bounds
cleared all 16.

The diagnostic could point at this more directly. Adding an explicit type witness produces the
message that actually explains it:

Type argument cannot be @Nullable, as method <T,U,R>identity(...)'s type variable U is not @Nullable

whereas the inferred call says only that a type variable is "constrained to be both @nonnull and
@nullable", which reads like an inference defect rather than a missing bound on the user's own
declaration.

Activity

  1. added
    jspecify
    and removed on Aug 23, 2026
  2. changed the title [-]Inscrutable error messages from inference failures[/-] [+]Indicate when an inference failure is due to a `@NonNull` type variable upper bound[/+] on Aug 28, 2026
  3. msridhar commented on Aug 28, 2026

    @msridhar
    ContributorAuthor

    I scoped this one down to making the error message indicate more clearly when an inference failure is due to a @NonNull upper bound on a type variable. We could improve inference failure methods in various other ways, but that will require deeper investigation and design work.

  4. added 3 commits that reference this issue on Aug 28, 2026
    26298ae
    69d7c21
    a0c220d
  5. added a commit that references this issue on Aug 29, 2026
    f142e85
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

    highpriorityjspecify

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions