Skip to content

Report a generic nullability mismatch as a marked diff of the two types - #1828

Draft
vlsi wants to merge 46 commits into
apache:masterfrom
vlsi:claude/nullaway-false-positive-messages-2889ba
Draft

vlsi wants to merge 46 commits into
apache:masterfrom
vlsi:claude/nullaway-false-positive-messages-2889ba

Conversation

@vlsi

@vlsi vlsi commented Sep 8, 2026 •

Copy link
Copy Markdown
Contributor

In JSpecify mode, an assignment, argument, or return whose type arguments differ in nullness was reported with both types in full, leaving the reader to diff them. The "before" messages below are what master reports for the same source; the "after" messages are this branch's.

Unbounded wildcard passed where a non-null bound is required (#1822)

@NullMarked
class Test {
  Collection<Object> copy(List<?> list) {
    List<Object> result = new ArrayList<>();
    result.addAll(list); // reported here
    return result;
  }
}

Before:

incompatible types: List<?> cannot be converted to Collection<? extends Object> (List<?> is a subtype of Collection<?>)

After:

incompatible nullability in type argument for E of Collection -> upper bound of wildcard: source has @Nullable Object where target requires Object
    source: List<?>
                 ^
    target: Collection<? extends Object>
                                 ^^^^^^
    note: the unbounded wildcard ? in List<?> has the upper bound of type parameter E of List, which is @Nullable Object (JLS 5.1.10)

The error is correct: the JSpecify JDK model declares List's E as E extends @Nullable Object, so a List<?> may hold null, and addAll on a List<Object> takes only a Collection<? extends Object>.

Two mismatches, one of them nested

@NullMarked
class Test {
  static void take(Map<String, List<? extends Collection<Integer>>> m) {}

  void test(Map<@Nullable String, List<? extends Collection<@Nullable Integer>>> m) {
    take(m); // reported here
  }
}

Before:

incompatible types: Map<@Nullable String, List<? extends Collection<@Nullable Integer>>> cannot be converted to Map<String, List<? extends Collection<Integer>>>

After:

incompatible nullability in type argument for K of Map and 1 other differing position: source has @Nullable String where target requires String
    source: Map<@Nullable String, List<? extends Collection<@Nullable Integer>>>
                ^^^^^^^^^^^^^^^^                            ^^^^^^^^^^^^^^^^^
                1                                           2
    target: Map<String, List<? extends Collection<Integer>>>
                ^^^^^^                            ^^^^^^^
                1                                 2

    1. path: type argument for K of Map
       source: @Nullable String
       target: String

    2. path: type argument for V of Map -> type argument for E of List -> upper bound of wildcard -> type argument for E of Collection
       source: @Nullable Integer
       target: Integer

Mismatch visible only in a supertype

@NullMarked
class Test {
  static class Base<B> {}

  static class Indirect<X extends @Nullable Object> extends Base<List<X>> {}

  static void take(Base<? extends List<? extends Object>> b) {}

  void test(Indirect<?> i) {
    take(i); // reported here
  }
}

Before:

incompatible types: Indirect<?> cannot be converted to Base<? extends List<? extends Object>> (Indirect<?> is a subtype of Base<List<?>>)

After:

incompatible nullability in type argument for B of Base -> upper bound of wildcard -> type argument for E of List -> upper bound of wildcard: source has @Nullable Object where target requires Object
    source: Indirect<?>
                     ^
    target: Base<? extends List<? extends Object>>
                                          ^^^^^^
    note: the unbounded wildcard ? in Indirect<?> has the upper bound of type parameter X of Indirect, which is @Nullable Object (JLS 5.1.10)

The positions come from CheckIdenticalNullabilityVisitor itself: while it compares, it reports each step and each comparison it rejects to NullabilityMismatches, so the message cannot name a position the check accepts, and building it costs one more run of the check. A separate walk that predicted the check's rejections was rejected: it disagreed with the check at array elements, captures, and lower bounds, and was exponential on a shared bound graph. Array covariance moved from GenericsChecks into the visitor so that it is recorded too.

User-visible:

  • The first line is incompatible nullability in <path>[ and N other differing positions]: source has X where target requires Y; it stands alone for a tool that shows only that line. Source and target are the two sides of the pseudo-assignment, the value and the type it is assigned to, as in JLS ch. 5.
  • Where the source states a type argument outright and is the less nullable side, the first line reads …: a non-wildcard type argument must have the same nullability in source and target; source has String where target requires @Nullable String.
  • A difference in a ? super bound reads source has String where target requires a supertype of @Nullable String, at a lower bound of wildcard step.
  • In a numbered entry for such a position, the target: type ends in (a non-wildcard type argument must have the same nullability in source and target).
  • Several differences get numbered path:/source:/target: entries, five at most, then and N more differing positions, not listed. Two differences below one printed ? share its caret, numbered 1,2.
  • Where a marked node holds another marked node, as @Nullable List<@Nullable String> does, each nesting depth gets its own caret row and number row, outermost first. A number that would run into the one before it goes on a row of its own, below the other numbers of its depth.
  • The note: line replaces master's (target wildcard upper bound is …; source wildcard upper bound is …) parenthetical, citing JLS 5.1.10. For an unbounded ? or a ? super X in the source it names the type parameter the wildcard takes its upper bound from and that bound with the class's other type arguments substituted. It prints the class the ? is a type argument of, and writes every other type argument whose printed form contains ? or < as ...: note: the unbounded wildcard ? in Triple<String, ?, ...> has the upper bound of type parameter B of Triple, which is @Nullable Object (JLS 5.1.10). For a ? super X it reads note: the wildcard ? super String in List<? super String> has no upper bound of its own; its upper bound is the bound of type parameter E of List, which is @Nullable Object (JLS 5.1.10). Where the types differ at the bound itself and that bound is @Nullable only because its class is unannotated (NullAway added the @Nullable, the bound was not replaced by capture conversion, and the type parameter the note names takes its bound the same way), the note ends in ; the bound is @Nullable because Legacy is unannotated; a bound written @Nullable or @NonNull, or one a type argument substitutes, gets no such ending. Where the type parameter of the class the ? is printed in declares another bound than the one the check compared, as a subtype of it does, there is no note.
  • For a captured wildcard the note reads note: capture of ? is a captured wildcard whose upper bound is @Nullable Object (JLS 5.1.10), or capture of ? is the captured type argument for T of Box, whose upper bound is … where the capture fills that type parameter; the ; the bound is @Nullable because Box is unannotated ending follows the same rule as for a written ?. A type parameter in the bound is printed by its name, never as capture of ?; where the bound cannot be printed that way, there is no note.
  • Where the ? sits in no printed type, the note gives the bound alone: note: the unbounded wildcard ? in the source has the upper bound @Nullable Object (JLS 5.1.10).
  • Positions are named in JLS terms: type argument for E of Collection, upper bound of wildcard, lower bound of wildcard, component type, enclosing type.
  • Where the check views the source as a supertype at the top of the type and the compared node is not in the written type, a source supertype: line prints that view and carries the carets of the nodes the written type does not hold, while a node the written type holds keeps its caret on the source: line; the keys of the type lines are then padded to its width, so the types still start in one column.
  • The message is built only for a mismatch whose error is reported; one in suppressed or excluded code costs no second run of the check.
  • Ternary, method-reference, and override reporters keep their own messages: Give the conditional-expression, method-reference, and override reporters the marked generic mismatch message #2207.

Not changed: which code is reported. The test-library-models and jdk-integration-test expectations change with the text of the diagnostic.

Scope. The message suggests no change to a declaration. A prototype that printed possible fix: lines and attached Error Prone edits was taken out of this change, because review kept finding programs where the offered change moved the error to another line; it is kept as the tag nullaway-1828-possible-fix in vlsi/NullAway, and #2216 tracks it. Where the source is viewed as a supertype below the top of the type, as for an element of List<Sub>, the source: line gets no caret and no source supertype: line: #2197. For an intersection target, the target: line gets no caret: #2202. The check compares the bound that the class the target names declares, not the bound of the class the ? is printed in (#2206), so a note: names the latter's type parameter only where it declares the same bound, @Nullable at every node included. A subclass whose bound is a subtype of the compared bound, such as TopSub<U extends TopNested>, gets no note: #2224. The printer writes the dimensions of a nested array innermost first (Integer @Nullable [] [] for Integer[] @Nullable []), as on master, and the printed source:/target: lines keep that order: #2201.

Fixes #1822

Assisted-by: Claude Code (claude-opus-5-5)

@coderabbitai

coderabbitai Bot commented Sep 8, 2026 •

Copy link
Copy Markdown
Contributor

Review Change StackReview Change Stack

No actionable comments were generated in the recent review.

Walkthrough

NullAway now explains implicit wildcard upper bounds in JSpecify generic conversion diagnostics. It reports provenance for captured, unbounded, and super-bounded wildcards. It suggests explicit extends bounds for applicable unbounded wildcards. Tests cover direct, array, nested, and generic-method conversions. The changelog documents the improvement.

Suggested reviewers: msridhar, dbwiddis

Severity of issue fixed: Medium

Merge Risk: Minimal · up to daa16

This change improves JSpecify wildcard incompatibility diagnostics and adds explicit-bound suggestions where applicable. The documented behavior is covered by targeted tests, with no concrete current-head merge risk identified.

Pre-merge checks: Passed 4

Check name Status Explanation
Linked Issues check Passed The changes address issue #1822 by improving the incompatible-types diagnostic for List<?> and Collection<? extends Object>. The implementation explains implicit bounds, nullable versus non-null upper…
Out of Scope Changes check Passed The implementation, tests, and changelog entry are related to the linked issue and the stated objective of improving implicit wildcard-bound diagnostics. No unrelated code changes are identified.
Title check Passed The title describes the main change: a generic nullability mismatch is now reported as a marked diff of the two types. The raw summary covers the message rework in GenericsChecks and related tests, an…
Description check Passed The description explains a concrete change: JSpecify generic nullability mismatch diagnostics are reformatted as a diff with carets, path lines, notes, and repair suggestions. It gives before/after ex…
Full details: Linked Issues check

Explanation

The changes address issue #1822 by improving the incompatible-types diagnostic for List<?> and Collection<? extends Object>. The implementation explains implicit bounds, nullable versus non-null upper bounds, and suggests an explicit bound. Tests cover the reported case and related wildcard scenarios.

Full details: Title check

Explanation

The title describes the main change: a generic nullability mismatch is now reported as a marked diff of the two types. The raw summary covers the message rework in GenericsChecks and related tests, and the description confirms the diff-style report. The title does not mention the implicit wildcard bound notes or the suggested explicit bound, but it names the primary change and is specific enough for a teammate scanning history.

Full details: Description check

Explanation

The description explains a concrete change: JSpecify generic nullability mismatch diagnostics are reformatted as a diff with carets, path lines, notes, and repair suggestions. It gives before/after examples for the wildcard, nested, type-variable, supertype, and variable-declaration cases, names the affected reporters, and references issue #1822. This matches the changeset's GenericsChecks, WildcardTests, and GenericMethodTests edits, so it is related and specific.

Finishing Touches

🧪 Generate unit tests (beta)

  • Create PR with unit tests
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

Share

ℹ️ Recent review info

⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: ASSERTIVE

Plan: Advanced

Run ID: 9b115014-f541-4169-8fd4-efc1046018d3

📥 Commits

Reviewing files that changed from the base of the PR and between 2b8638f and daa16a1.

📒 Files selected for processing (4)

  • CHANGELOG.md
  • nullaway/src/main/java/com/uber/nullaway/generics/GenericsChecks.java
  • nullaway/src/test/java/com/uber/nullaway/jspecify/GenericMethodTests.java
  • nullaway/src/test/java/com/uber/nullaway/jspecify/WildcardTests.java

Included review availability: Your plan provides up to 8 included reviews per hour; 5 remain after this review.

@vlsi
vlsi marked this pull request as draft September 8, 2026 09:03
@vlsi
vlsi force-pushed the claude/nullaway-false-positive-messages-2889ba branch from daa16a1 to 60b00c5 Compare September 8, 2026 12:21
@codecov

codecov Bot commented Sep 8, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 90.18868% with 78 lines in your changes missing coverage. Please review.
✅ Project coverage is 89.62%. Comparing base (af5ba08) to head (af204ca).
⚠️ Report is 1 commits behind head on master.

Files with missing lines Patch % Lines
.../nullaway/generics/NullabilityMismatchMessage.java 88.53% 8 Missing and 32 partials ⚠️
.../uber/nullaway/generics/NullabilityMismatches.java 87.91% 9 Missing and 20 partials ⚠️
...way/generics/GenericTypePrettyPrintingVisitor.java 92.30% 2 Missing and 2 partials ⚠️
...main/java/com/uber/nullaway/generics/TypePath.java 94.11% 1 Missing and 2 partials ⚠️
...way/generics/CheckIdenticalNullabilityVisitor.java 97.46% 0 Missing and 2 partials ⚠️
Additional details and impacted files
@@             Coverage Diff              @@
##             master    #1828      +/-   ##
============================================
+ Coverage     89.58%   89.62%   +0.03%     
- Complexity     4031     4253     +222     
============================================
  Files           113      116       +3     
  Lines         13208    13845     +637     
  Branches       2729     2892     +163     
============================================
+ Hits          11832    12408     +576     
- Misses          621      636      +15     
- Partials        755      801      +46     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@vlsi
vlsi force-pushed the claude/nullaway-false-positive-messages-2889ba branch from 60b00c5 to 13c891a Compare September 9, 2026 05:05
@vlsi vlsi changed the title Explain implicit wildcard bounds and suggest an explicit bound in incompatible types diagnostics Mark the type argument at fault in incompatible types diagnostics and suggest a wildcard bound Sep 9, 2026
@vlsi
vlsi force-pushed the claude/nullaway-false-positive-messages-2889ba branch from 13c891a to 0294e03 Compare September 9, 2026 06:28
@vlsi vlsi changed the title Mark the type argument at fault in incompatible types diagnostics and suggest a wildcard bound Report a generic nullability mismatch as a marked diff of the two types Sep 9, 2026
@vlsi
vlsi force-pushed the claude/nullaway-false-positive-messages-2889ba branch 8 times, most recently from 6adae68 to da87527 Compare September 9, 2026 10:07
@vlsi
vlsi force-pushed the claude/nullaway-false-positive-messages-2889ba branch 2 times, most recently from 07f667d to f3ecbb5 Compare September 9, 2026 15:28
vlsi added a commit to vlsi/NullAway that referenced this pull request Oct 8, 2026
…ard is required

Previously, a `Box<T>` declared with `T extends @nullable Object` was accepted where a `Box<? extends Object>` was required, so a null could reach a position that rejects one. A wildcard actual in that position was judged by its effective upper bound, but a type variable was judged by its use site, which carries no nullness of its own, so every such assignment, argument, and return passed. No diagnostic marks the defect; the symptom is the missing error.

`CheckIdenticalNullabilityVisitor` now compares a type variable that carries no `@Nullable` or `@NonNull` at its use site as its declared upper bound. That bound admits null when it is annotated `@Nullable`, when the variable is declared in `@NullUnmarked` code, or when a library model overrides it. `GenericsUtils.typeVariableUpperBound` holds that rule, and the wildcard path uses it too, so the two cannot drift apart.

A requirement that names a type variable, `? extends T`, is not read that way. It admits whatever `T` is instantiated as, so the two types are compared as written: `Box<T>` and `Box<S extends T>` stay assignable to `Box<? extends T>`, and `Box<@nullable T>` into `Box<? extends T>` is still reported. Substituting `T`'s bound there would silence that report. Instead, the check also asks whether the actual may be null where `T` may not, so `Box<S>` with `S extends @nullable T` passed to `Box<? extends T>` with a non-null `T` is reported, and so is `Box<T>` passed to `Box<? extends @nonnull T>`.

A captured actual is exempt from that question, because capture conversion drops type-use annotations. In Caffeine's `CacheLoader.asyncLoadAll`, a `Map<? extends K, ? extends @nonnull V>` returned into a `CompletableFuture<? extends Map<? extends K, ? extends @nonnull V>>` reaches the check as `Map<capture of ? extends K, capture of ? extends V>`, and comparing its bare `V` against `@NonNull V` would report a correct return. Resolving the requirement's bound as well as the actual's reported Caffeine's `CacheLoader.asyncReload`, where `CompletableFuture.supplyAsync` infers `CompletableFuture<V>` against `CompletableFuture<? extends V>`:

```text
CacheLoader.java:196: error: [NullAway] incompatible types: CompletableFuture<V> cannot be converted to CompletableFuture<? extends V>
```

Caller sees:
- `incompatible types: Box<T> cannot be converted to Box<? extends Object>` where `T`'s declared bound admits null; accepted before.
- `mismatched type parameter nullability` on an override that returns `List<V>` where the overridden method returns `List<? extends @nonnull V>` and `V` may be null; accepted before. Caffeine's `AsyncCacheLoader.bulk` is such an override. Code that compiled clean can need a narrower return type or a suppression.

Not changed:
- `ConstraintSolverImpl` builds its constraints from wildcard upper bounds without this rule, so a type variable whose bound admits null, inferred into a non-null `? extends` position, may still go unreported.
- `? super` containment does not resolve a type variable actual; javac rejects a `Box<T>` for a `Box<? super Object>` before NullAway runs.

The tests in `WildcardTests` cover a type variable actual with each use-site annotation against `? extends Object`, `? extends @nullable Object`, `?`, `? extends T`, and `? extends @nonnull T`, a bound declared in unannotated code or inherited from another variable, the inferred and captured shapes above, and the override reporter with a clean control. Ten mutations of the new code each turn at least one of them red. The library-model rule has no test through the new caller: a model keys the bound to a class's own type parameter, which checked code sees only after substitution, and the rule keeps its coverage through the existing callers.

`GenericsChecks` decides whether a bound admits null by hand in three more places; unifying them is outside this change. This is the first commit of apache#1828 as a standalone change; apache#1828 rewrites the message of the same diagnostic in `CheckIdenticalNullabilityVisitor`, `GenericsChecks`, and `WildcardTests`, so it goes after this one.

Assisted-by: Claude Code (claude-opus-5-5)
vlsi added a commit to vlsi/NullAway that referenced this pull request Oct 8, 2026
…ard is required

Previously, a `Box<T>` declared with `T extends @nullable Object` was accepted where a `Box<? extends Object>` was required, so a null could reach a position that rejects one. A wildcard actual in that position was judged by its effective upper bound, but a type variable was judged by its use site, which carries no nullness of its own, so every such assignment, argument, and return passed. No diagnostic marks the defect; the symptom is the missing error.

`CheckIdenticalNullabilityVisitor` now compares a type variable that carries no `@Nullable` or `@NonNull` at its use site as its declared upper bound. That bound admits null when it is annotated `@Nullable`, when the variable is declared in `@NullUnmarked` code, or when a library model overrides it. `GenericsUtils.typeVariableUpperBound` holds that rule, and the wildcard path uses it too, so the two cannot drift apart.

A requirement that names a type variable, `? extends T`, is not read that way. It admits whatever `T` is instantiated as, so the two types are compared as written: `Box<T>` and `Box<S extends T>` stay assignable to `Box<? extends T>`, and `Box<@nullable T>` into `Box<? extends T>` is still reported. Substituting `T`'s bound there would silence that report. Instead, the check also asks whether the actual may be null where `T` may not, so `Box<S>` with `S extends @nullable T` passed to `Box<? extends T>` with a non-null `T` is reported, and so is `Box<T>` passed to `Box<? extends @nonnull T>`.

A captured actual is exempt from that question, because capture conversion drops type-use annotations. In Caffeine's `CacheLoader.asyncLoadAll`, a `Map<? extends K, ? extends @nonnull V>` returned into a `CompletableFuture<? extends Map<? extends K, ? extends @nonnull V>>` reaches the check as `Map<capture of ? extends K, capture of ? extends V>`, and comparing its bare `V` against `@NonNull V` would report a correct return. Resolving the requirement's bound as well as the actual's reported Caffeine's `CacheLoader.asyncReload`, where `CompletableFuture.supplyAsync` infers `CompletableFuture<V>` against `CompletableFuture<? extends V>`:

```text
CacheLoader.java:196: error: [NullAway] incompatible types: CompletableFuture<V> cannot be converted to CompletableFuture<? extends V>
```

Caller sees:
- `incompatible types: Box<T> cannot be converted to Box<? extends Object>` where `T`'s declared bound admits null; accepted before.
- `mismatched type parameter nullability` on an override that returns `List<V>` where the overridden method returns `List<? extends @nonnull V>` and `V` may be null; accepted before. Caffeine's `AsyncCacheLoader.bulk` is such an override. Code that compiled clean can need a narrower return type or a suppression.

Not changed:
- `ConstraintSolverImpl` builds its constraints from wildcard upper bounds without this rule, so a type variable whose bound admits null, inferred into a non-null `? extends` position, may still go unreported.
- `? super` containment does not resolve a type variable actual; javac rejects a `Box<T>` for a `Box<? super Object>` before NullAway runs.

The tests in `WildcardTests` cover a type variable actual with each use-site annotation against `? extends Object`, `? extends @nullable Object`, `?`, `? extends T`, and `? extends @nonnull T`, a bound declared in unannotated code or inherited from another variable, the inferred and captured shapes above, and the override reporter with a clean control. Ten mutations of the new code each turn at least one of them red. The library-model rule has no test through the new caller: a model keys the bound to a class's own type parameter, which checked code sees only after substitution, and the rule keeps its coverage through the existing callers.

`GenericsChecks` decides whether a bound admits null by hand in three more places; unifying them is outside this change. This is the first commit of apache#1828 as a standalone change; apache#1828 rewrites the message of the same diagnostic in `CheckIdenticalNullabilityVisitor`, `GenericsChecks`, and `WildcardTests`, so it goes after this one.

Assisted-by: Claude Code (claude-opus-5-5)
vlsi added a commit to vlsi/NullAway that referenced this pull request Oct 8, 2026
…ard is required

Previously, a `Box<T>` declared with `T extends @nullable Object` was accepted where a `Box<? extends Object>` was required, so a null could reach a position that rejects one. A wildcard actual in that position was judged by its effective upper bound, but a type variable was judged by its use site, which carries no nullness of its own, so every such assignment, argument, and return passed. No diagnostic marks the defect; the symptom is the missing error.

`CheckIdenticalNullabilityVisitor` now compares a type variable that carries no `@Nullable` or `@NonNull` at its use site as its declared upper bound. That bound admits null when it is annotated `@Nullable`, when the variable is declared in `@NullUnmarked` code, or when a library model overrides it. `GenericsUtils.typeVariableUpperBound` holds that rule, and the wildcard path uses it too, so the two cannot drift apart.

A requirement that names a type variable, `? extends T`, is not read that way. It admits whatever `T` is instantiated as, so the two types are compared as written: `Box<T>` and `Box<S extends T>` stay assignable to `Box<? extends T>`, and `Box<@nullable T>` into `Box<? extends T>` is still reported. Substituting `T`'s bound there would silence that report. Instead, the check also asks whether the actual may be null where `T` may not, so `Box<S>` with `S extends @nullable T` passed to `Box<? extends T>` with a non-null `T` is reported, and so is `Box<T>` passed to `Box<? extends @nonnull T>`.

A captured actual is exempt from that question, because capture conversion drops type-use annotations. In Caffeine's `CacheLoader.asyncLoadAll`, a `Map<? extends K, ? extends @nonnull V>` returned into a `CompletableFuture<? extends Map<? extends K, ? extends @nonnull V>>` reaches the check as `Map<capture of ? extends K, capture of ? extends V>`, and comparing its bare `V` against `@NonNull V` would report a correct return. Resolving the requirement's bound as well as the actual's reported Caffeine's `CacheLoader.asyncReload`, where `CompletableFuture.supplyAsync` infers `CompletableFuture<V>` against `CompletableFuture<? extends V>`:

```text
CacheLoader.java:196: error: [NullAway] incompatible types: CompletableFuture<V> cannot be converted to CompletableFuture<? extends V>
```

Caller sees:
- `incompatible types: Box<T> cannot be converted to Box<? extends Object>` where `T`'s declared bound admits null; accepted before.
- `mismatched type parameter nullability` on an override that returns `List<V>` where the overridden method returns `List<? extends @nonnull V>` and `V` may be null; accepted before. Caffeine's `AsyncCacheLoader.bulk` is such an override. Code that compiled clean can need a narrower return type or a suppression.

Not changed:
- `ConstraintSolverImpl` builds its constraints from wildcard upper bounds without this rule, so a type variable whose bound admits null, inferred into a non-null `? extends` position, may still go unreported.
- `? super` containment does not resolve a type variable actual; javac rejects a `Box<T>` for a `Box<? super Object>` before NullAway runs.

The tests in `WildcardTests` cover a type variable actual with each use-site annotation against `? extends Object`, `? extends @nullable Object`, `?`, `? extends T`, and `? extends @nonnull T`, a bound declared in unannotated code or inherited from another variable, the inferred and captured shapes above, and the override reporter with a clean control. Ten mutations of the new code each turn at least one of them red. The library-model rule has no test through the new caller: a model keys the bound to a class's own type parameter, which checked code sees only after substitution, and the rule keeps its coverage through the existing callers.

`GenericsChecks` decides whether a bound admits null by hand in three more places; unifying them is outside this change. This is the first commit of apache#1828 as a standalone change; apache#1828 rewrites the message of the same diagnostic in `CheckIdenticalNullabilityVisitor`, `GenericsChecks`, and `WildcardTests`, so it goes after this one.

Assisted-by: Claude Code (claude-opus-5-5)
vlsi added a commit to vlsi/NullAway that referenced this pull request Oct 8, 2026
…ard is required

Previously, a `Box<T>` declared with `T extends @nullable Object` was accepted where a `Box<? extends Object>` was required, so a null could reach a position that rejects one. A wildcard actual in that position was judged by its effective upper bound, but a type variable was judged by its use site, which carries no nullness of its own, so every such assignment, argument, and return passed. No diagnostic marks the defect; the symptom is the missing error.

`CheckIdenticalNullabilityVisitor` now compares a type variable that carries no `@Nullable` or `@NonNull` at its use site as its declared upper bound. That bound admits null when it is annotated `@Nullable`, when the variable is declared in `@NullUnmarked` code, or when a library model overrides it. `GenericsUtils.typeVariableUpperBound` holds that rule, and the wildcard path uses it too, so the two cannot drift apart.

A requirement that names a type variable, `? extends T`, is not read that way. It admits whatever `T` is instantiated as, so the two types are compared as written: `Box<T>` and `Box<S extends T>` stay assignable to `Box<? extends T>`, and `Box<@nullable T>` into `Box<? extends T>` is still reported. Substituting `T`'s bound there would silence that report. Instead, the check also asks whether the actual may be null where `T` may not, so `Box<S>` with `S extends @nullable T` passed to `Box<? extends T>` with a non-null `T` is reported, and so is `Box<T>` passed to `Box<? extends @nonnull T>`.

A captured actual is exempt from that question, because capture conversion drops type-use annotations. In Caffeine's `CacheLoader.asyncLoadAll`, a `Map<? extends K, ? extends @nonnull V>` returned into a `CompletableFuture<? extends Map<? extends K, ? extends @nonnull V>>` reaches the check as `Map<capture of ? extends K, capture of ? extends V>`, and comparing its bare `V` against `@NonNull V` would report a correct return. Resolving the requirement's bound as well as the actual's reported Caffeine's `CacheLoader.asyncReload`, where `CompletableFuture.supplyAsync` infers `CompletableFuture<V>` against `CompletableFuture<? extends V>`:

```text
CacheLoader.java:196: error: [NullAway] incompatible types: CompletableFuture<V> cannot be converted to CompletableFuture<? extends V>
```

Caller sees:
- `incompatible types: Box<T> cannot be converted to Box<? extends Object>` where `T`'s declared bound admits null; accepted before.
- `mismatched type parameter nullability` on an override that returns `List<V>` where the overridden method returns `List<? extends @nonnull V>` and `V` may be null; accepted before. Caffeine's `AsyncCacheLoader.bulk` is such an override. Code that compiled clean can need a narrower return type or a suppression.

Not changed:
- `ConstraintSolverImpl` builds its constraints from wildcard upper bounds without this rule, so a type variable whose bound admits null, inferred into a non-null `? extends` position, may still go unreported.
- `? super` containment does not resolve a type variable actual; javac rejects a `Box<T>` for a `Box<? super Object>` before NullAway runs.

The tests in `WildcardTests` cover a type variable actual with each use-site annotation against `? extends Object`, `? extends @nullable Object`, `?`, `? extends T`, and `? extends @nonnull T`, a bound declared in unannotated code or inherited from another variable, the inferred and captured shapes above, and the override reporter with a clean control. Ten mutations of the new code each turn at least one of them red. The library-model rule has no test through the new caller: a model keys the bound to a class's own type parameter, which checked code sees only after substitution, and the rule keeps its coverage through the existing callers.

`GenericsChecks` decides whether a bound admits null by hand in three more places; unifying them is outside this change. This is the first commit of apache#1828 as a standalone change; apache#1828 rewrites the message of the same diagnostic in `CheckIdenticalNullabilityVisitor`, `GenericsChecks`, and `WildcardTests`, so it goes after this one.

Assisted-by: Claude Code (claude-opus-5-5)
vlsi added a commit to vlsi/NullAway that referenced this pull request Oct 8, 2026
…ard is required

Previously, a `Box<T>` declared with `T extends @nullable Object` was accepted where a `Box<? extends Object>` was required, so a null could reach a position that rejects one. A wildcard actual in that position was judged by its effective upper bound, but a type variable was judged by its use site, which carries no nullness of its own, so every such assignment, argument, and return passed. No diagnostic marks the defect; the symptom is the missing error.

`CheckIdenticalNullabilityVisitor` now compares a type variable that carries no `@Nullable` or `@NonNull` at its use site as its declared upper bound. That bound admits null when it is annotated `@Nullable`, when the variable is declared in `@NullUnmarked` code, or when a library model overrides it.

A requirement that names a type variable, `? extends T`, admits whatever `T` is instantiated as, so there the two types are compared as written: `Box<T>` and `Box<S extends T>` stay assignable to `Box<? extends T>`, and `Box<@nullable T>` is still reported. The check then also asks whether the actual may be null where `T` may not, so `Box<S>` with `S extends @nullable T` passed to `Box<? extends T>` with a non-null `T` is reported, and so is `Box<T>` passed to `Box<? extends @nonnull T>`. Substituting `T`'s bound instead was tried: on the requirement side alone it reports Caffeine's `CacheLoader.asyncReload`, where `CompletableFuture.supplyAsync` infers `CompletableFuture<V>` against `CompletableFuture<? extends V>`, and on both sides it silences the `Box<@nullable T>` report.

```text
CacheLoader.java:196: error: [NullAway] incompatible types: CompletableFuture<V> cannot be converted to CompletableFuture<? extends V>
```

A captured actual skips the null check, because capture conversion drops type-use annotations. In Caffeine's `CacheLoader.asyncLoadAll`, a `Map<? extends K, ? extends @nonnull V>` returned into a `CompletableFuture<? extends Map<? extends K, ? extends @nonnull V>>` reaches the check as `Map<capture of ? extends K, capture of ? extends V>`, with no `@NonNull` left on `V`.

Caller sees:
- `incompatible types: Box<T> cannot be converted to Box<? extends Object>` where `T`'s declared bound admits null; accepted before.
- `mismatched type parameter nullability` on an override that returns `List<V>` where the overridden method returns `List<? extends @nonnull V>` and `V` may be null; accepted before. Caffeine's `AsyncCacheLoader.bulk` is such an override. Code that compiled clean can need a narrower return type or a suppression.

Not changed:
- `ConstraintSolverImpl` builds its constraints from wildcard upper bounds without this rule, so a type variable whose bound admits null, inferred into a non-null `? extends` position, may still go unreported.
- `? super` containment does not resolve a type variable actual; javac rejects a `Box<T>` for a `Box<? super Object>` before NullAway runs.

The new tests in `WildcardTests` put the reported and the accepted cases of each rule in one source, and ten mutations of the new code each turn at least one of them red. The library-model rule has no test through the new code: a model keys the bound to a class's own type parameter, which checked code sees only after substitution.

`GenericsChecks` decides whether a bound admits null by hand in three more places; unifying them is outside this change. This is the first commit of apache#1828 as a standalone change; apache#1828 rewrites the message of the same diagnostic in `CheckIdenticalNullabilityVisitor`, `GenericsChecks`, and `WildcardTests`, so it goes after this one.

Assisted-by: Claude Code (claude-opus-5-5)
vlsi added a commit to vlsi/NullAway that referenced this pull request Oct 8, 2026
…ard is required

Previously, a `Box<T>` declared with `T extends @nullable Object` was accepted where a `Box<? extends Object>` was required, so a null could reach a position that rejects one. A wildcard actual in that position was judged by its effective upper bound, but a type variable was judged by its use site, which carries no nullness of its own, so every such assignment, argument, and return passed. No diagnostic marks the defect; the symptom is the missing error.

`CheckIdenticalNullabilityVisitor` now compares a type variable that carries no `@Nullable` or `@NonNull` at its use site as its declared upper bound. That bound admits null when it is annotated `@Nullable`, when the variable is declared in `@NullUnmarked` code, or when a library model overrides it.

A requirement that names a type variable, `? extends T`, admits whatever `T` is instantiated as, so there the two types are compared as written: `Box<T>` and `Box<S extends T>` stay assignable to `Box<? extends T>`, and `Box<@nullable T>` is still reported. The check then also asks whether the actual may be null where this instantiation of `T` may not: it walks the actual's declared bounds up to `T` and looks for a link annotated or declared `@Nullable`. So `Box<S>` with `S extends @nullable T` passed to `Box<? extends T>` is reported whatever `T`'s own bound, and so is `Box<T>` passed to `Box<? extends @nonnull T>` when `T`'s bound admits null. Where the walk does not reach `T`, as between the type variables of an overriding and an overridden generic method, the declared bounds of the two are compared instead. Substituting `T`'s bound instead was tried: on the requirement side alone it reports Caffeine's `CacheLoader.asyncReload`, where `CompletableFuture.supplyAsync` infers `CompletableFuture<V>` against `CompletableFuture<? extends V>`, and on both sides it silences the `Box<@nullable T>` report.

```text
CacheLoader.java:196: error: [NullAway] incompatible types: CompletableFuture<V> cannot be converted to CompletableFuture<? extends V>
```

A captured actual skips the null check, because capture conversion drops type-use annotations. In Caffeine's `CacheLoader.asyncLoadAll`, a `Map<? extends K, ? extends @nonnull V>` returned into a `CompletableFuture<? extends Map<? extends K, ? extends @nonnull V>>` reaches the check as `Map<capture of ? extends K, capture of ? extends V>`, with no `@NonNull` left on `V`.

Caller sees:
- `incompatible types: Box<T> cannot be converted to Box<? extends Object>` where `T`'s declared bound admits null; accepted before.
- `mismatched type parameter nullability` on an override that returns `List<V>` where the overridden method returns `List<? extends @nonnull V>` and `V` may be null; accepted before. Caffeine's `AsyncCacheLoader.bulk` is such an override. Code that compiled clean can need a narrower return type or a suppression.
- `mismatched type parameter nullability` on an override of an unannotated generic method that declares its type variable without `@Nullable`, such as `<U> CompletionStage<U> thenApply(Function<? super T, ? extends U> fn)`; it comes beside the existing `Method type variable U has a non-null upper bound` report for the same declaration, because the overridden method's type variables are not renamed to the overrider's before the comparison.

Not changed:
- `ConstraintSolverImpl` builds its constraints from wildcard upper bounds without this rule, so a type variable whose bound admits null, inferred into a non-null `? extends` position, may still go unreported.
- `? super` containment does not resolve a type variable actual; javac rejects a `Box<T>` for a `Box<? super Object>` before NullAway runs.
- A captured actual still skips the null check, so `Source<? extends T>.load()` returning `List<E>` passes as `List<? extends @nonnull T>` when `T`'s bound admits null. Such a capture cannot be told apart from the one in `asyncLoadAll`, whose `@NonNull` inference dropped.
- A type variable bounded by an intersection whose every element is `@Nullable`, such as `T extends @nullable Object & @nullable Serializable`, is still treated as excluding null: `upperBoundIsNullable` reads the annotations of the intersection, not of its elements.

The new tests in `WildcardTests` put the reported and the accepted cases of each rule in one source, and a mutation of each branch of the new code turns at least one of them red. The library-model rule has no test through the new code: a model keys the bound to a class's own type parameter, which checked code sees only after substitution.

`GenericsChecks` decides whether a bound admits null by hand in three more places; unifying them is outside this change. This is the first commit of apache#1828 as a standalone change; apache#1828 rewrites the message of the same diagnostic in `CheckIdenticalNullabilityVisitor`, `GenericsChecks`, and `WildcardTests`, so it goes after this one.

Assisted-by: Claude Code (claude-opus-5-5)
vlsi added a commit to vlsi/NullAway that referenced this pull request Oct 8, 2026
…ard is required

Previously, a `Box<T>` declared with `T extends @nullable Object` was accepted where a `Box<? extends Object>` was required, so a null could reach a position that rejects one. A wildcard actual in that position was judged by its effective upper bound, but a type variable was judged by its use site, which carries no nullness of its own, so every such assignment, argument, and return passed. No diagnostic marks the defect; the symptom is the missing error.

`CheckIdenticalNullabilityVisitor` now compares a type variable that carries no `@Nullable` or `@NonNull` at its use site as its declared upper bound. That bound admits null when it is annotated `@Nullable`, when the variable is declared in `@NullUnmarked` code, or when a library model overrides it.

A requirement that names a type variable, `? extends T`, admits whatever `T` is instantiated as, so there the two types are compared as written: `Box<T>` and `Box<S extends T>` stay assignable to `Box<? extends T>`, and `Box<@nullable T>` is still reported. The check then also asks whether the actual may be null where this instantiation of `T` may not: it walks the actual's declared bounds up to `T` and looks for a link annotated or declared `@Nullable`. So `Box<S>` with `S extends @nullable T` passed to `Box<? extends T>` is reported whatever `T`'s own bound, and so is `Box<T>` passed to `Box<? extends @nonnull T>` when `T`'s bound admits null. Where the walk does not reach `T`, as between the type variables of an overriding and an overridden generic method, the declared bounds of the two are compared instead. Substituting `T`'s bound instead was tried: on the requirement side alone it reports Caffeine's `CacheLoader.asyncReload`, where `CompletableFuture.supplyAsync` infers `CompletableFuture<V>` against `CompletableFuture<? extends V>`, and on both sides it silences the `Box<@nullable T>` report.

```text
CacheLoader.java:196: error: [NullAway] incompatible types: CompletableFuture<V> cannot be converted to CompletableFuture<? extends V>
```

A captured actual skips the null check, because capture conversion drops type-use annotations. In Caffeine's `CacheLoader.asyncLoadAll`, a `Map<? extends K, ? extends @nonnull V>` returned into a `CompletableFuture<? extends Map<? extends K, ? extends @nonnull V>>` reaches the check as `Map<capture of ? extends K, capture of ? extends V>`, with no `@NonNull` left on `V`.

Caller sees:
- `incompatible types: Box<T> cannot be converted to Box<? extends Object>` where `T`'s declared bound admits null; accepted before.
- `mismatched type parameter nullability` on an override that returns `List<V>` where the overridden method returns `List<? extends @nonnull V>` and `V` may be null; accepted before. Caffeine's `AsyncCacheLoader.bulk` is such an override. Code that compiled clean can need a narrower return type or a suppression.
- `mismatched type parameter nullability` on an override of a generic method whose type variable admits null, when the override declares that variable without `@Nullable`, for example `<U> CompletionStage<U> thenApply(Function<? super T, ? extends U> fn)` overriding the unannotated JDK method. It comes beside the existing `Method type variable U has a non-null upper bound` report for the same declaration, because the overridden method's type variables are not renamed to the overrider's before the comparison.

Not changed:
- `ConstraintSolverImpl` builds its constraints from wildcard upper bounds without this rule, so a type variable whose bound admits null, inferred into a non-null `? extends` position, may still go unreported.
- `? super` containment does not resolve a type variable actual; javac rejects a `Box<T>` for a `Box<? super Object>` before NullAway runs.
- A captured actual still skips the null check, so `Source<? extends T>.load()` returning `List<E>` passes as `List<? extends @nonnull T>` when `T`'s bound admits null. Such a capture cannot be told apart from the one in `asyncLoadAll`, whose `@NonNull` inference dropped.
- A type variable bounded by an intersection whose every element is `@Nullable`, such as `T extends @nullable Object & @nullable Serializable`, is still treated as excluding null: `upperBoundIsNullable` reads the annotations of the intersection, not of its elements.

The new tests in `WildcardTests` put the reported and the accepted cases of each rule in one source, and a mutation of each branch of the new code turns at least one of them red. The library-model rule has no test through the new code: a model keys the bound to a class's own type parameter, which checked code sees only after substitution.

`GenericsChecks` decides whether a bound admits null by hand in three more places; unifying them is outside this change. This is the first commit of apache#1828 as a standalone change; apache#1828 rewrites the message of the same diagnostic in `CheckIdenticalNullabilityVisitor`, `GenericsChecks`, and `WildcardTests`, so it goes after this one.

Assisted-by: Claude Code (claude-opus-5-5)
vlsi added a commit to vlsi/NullAway that referenced this pull request Oct 8, 2026
…ard is required

Previously, a `Box<T>` declared with `T extends @nullable Object` was accepted where a `Box<? extends Object>` was required, so a null could reach a position that rejects one. A wildcard actual in that position was judged by its effective upper bound, but a type variable was judged by its use site, which carries no nullness of its own, so every such assignment, argument, and return passed. No diagnostic marks the defect; the symptom is the missing error.

`CheckIdenticalNullabilityVisitor` now compares a type variable that carries no `@Nullable` or `@NonNull` at its use site as its declared upper bound. That bound admits null when it is annotated `@Nullable`, when the variable is declared in `@NullUnmarked` code, or when a library model overrides it.

A requirement that names a type variable, `? extends T`, admits whatever `T` is instantiated as, so there the two types are compared as written: `Box<T>` and `Box<S extends T>` stay assignable to `Box<? extends T>`, and `Box<@nullable T>` is still reported. The check then also asks whether the actual may be null where this instantiation of `T` may not: it walks the actual's declared bounds up to `T` and looks for a link annotated or declared `@Nullable`. So `Box<S>` with `S extends @nullable T` passed to `Box<? extends T>` is reported whatever `T`'s own bound, and so is `Box<T>` passed to `Box<? extends @nonnull T>` when `T`'s bound admits null. Where the walk does not reach `T`, as between the type variables of an overriding and an overridden generic method, the declared bounds of the two are compared instead. Substituting `T`'s bound instead was tried: on the requirement side alone it reports Caffeine's `CacheLoader.asyncReload`, where `CompletableFuture.supplyAsync` infers `CompletableFuture<V>` against `CompletableFuture<? extends V>`, and on both sides it silences the `Box<@nullable T>` report.

```text
CacheLoader.java:196: error: [NullAway] incompatible types: CompletableFuture<V> cannot be converted to CompletableFuture<? extends V>
```

A captured actual skips the null check, because capture conversion drops type-use annotations. In Caffeine's `CacheLoader.asyncLoadAll`, a `Map<? extends K, ? extends @nonnull V>` returned into a `CompletableFuture<? extends Map<? extends K, ? extends @nonnull V>>` reaches the check as `Map<capture of ? extends K, capture of ? extends V>`, with no `@NonNull` left on `V`.

Caller sees:
- `incompatible types: Box<T> cannot be converted to Box<? extends Object>` where `T`'s declared bound admits null; accepted before.
- `mismatched type parameter nullability` on an override that returns `List<V>` where the overridden method returns `List<? extends @nonnull V>` and `V` may be null; accepted before. Caffeine's `AsyncCacheLoader.bulk` is such an override. Code that compiled clean can need a narrower return type or a suppression.
- `mismatched type parameter nullability` on an override of a generic method whose type variable admits null, when the override declares that variable without `@Nullable`, for example `<U> CompletionStage<U> thenApply(Function<? super T, ? extends U> fn)` overriding the unannotated JDK method. It comes beside the existing `Method type variable U has a non-null upper bound` report for the same declaration, because the overridden method's type variables are not renamed to the overrider's before the comparison.

Not changed:
- `ConstraintSolverImpl` builds its constraints from wildcard upper bounds without this rule, so a type variable whose bound admits null, inferred into a non-null `? extends` position, may still go unreported.
- `? super` containment does not resolve a type variable actual; javac rejects a `Box<T>` for a `Box<? super Object>` before NullAway runs.
- A captured actual still skips the null check, so `Source<? extends T>.load()` returning `List<E>` passes as `List<? extends @nonnull T>` when `T`'s bound admits null. Such a capture cannot be told apart from the one in `asyncLoadAll`, whose `@NonNull` inference dropped.
- A type variable bounded by an intersection whose every element is `@Nullable`, such as `T extends @nullable Object & @nullable Serializable`, is still treated as excluding null: `upperBoundIsNullable` reads the annotations of the intersection, not of its elements. apache#1836 fixes that.

The new tests in `WildcardTests` put the reported and the accepted cases of each rule in one source, and a mutation of each branch of the new code turns at least one of them red. The library-model rule has no test through the new code: a model keys the bound to a class's own type parameter, which checked code sees only after substitution.

`GenericsChecks` decides whether a bound admits null by hand in three more places; unifying them is outside this change. This is the first commit of apache#1828 as a standalone change; apache#1828 rewrites the message of the same diagnostic in `CheckIdenticalNullabilityVisitor`, `GenericsChecks`, and `WildcardTests`, so it goes after this one.

Assisted-by: Claude Code (claude-opus-5-5)
vlsi added a commit to vlsi/NullAway that referenced this pull request Oct 8, 2026
…ard is required

Previously, a `Box<T>` declared with `T extends @nullable Object` was accepted where a `Box<? extends Object>` was required, so a null could reach a position that rejects one. A wildcard actual in that position was judged by its effective upper bound, but a type variable was judged by its use site, which carries no nullness of its own, so every such assignment, argument, and return passed. No diagnostic marks the defect; the symptom is the missing error.

`CheckIdenticalNullabilityVisitor` now compares a type variable that carries no `@Nullable` or `@NonNull` at its use site as its declared upper bound. That bound admits null when it is annotated `@Nullable`, when a library model overrides it, or when the variable is declared in unannotated code and its bound is not annotated `@NonNull`.

A requirement that names a type variable, `? extends T`, admits whatever `T` is instantiated as, so there the two types are compared as written: `Box<T>` and `Box<S extends T>` stay assignable to `Box<? extends T>`, and `Box<@nullable T>` is still reported. The check then also asks whether the actual may be null where this instantiation of `T` may not: it walks the actual's declared bounds up to `T` and looks for a link annotated or declared `@Nullable`. So `Box<S>` with `S extends @nullable T` passed to `Box<? extends T>` is reported whatever `T`'s own bound, and so is `Box<T>` passed to `Box<? extends @nonnull T>` when `T`'s bound admits null. Where the walk does not reach `T`, as between the type variables of an overriding and an overridden generic method, the declared bounds of the two are compared instead. Substituting `T`'s bound instead was tried: on the requirement side alone it reports Caffeine's `CacheLoader.asyncReload`, where `CompletableFuture.supplyAsync` infers `CompletableFuture<V>` against `CompletableFuture<? extends V>`, and on both sides it silences the `Box<@nullable T>` report.

```text
CacheLoader.java:196: error: [NullAway] incompatible types: CompletableFuture<V> cannot be converted to CompletableFuture<? extends V>
```

A captured actual skips the null check, because capture conversion drops type-use annotations. In Caffeine's `CacheLoader.asyncLoadAll`, a `Map<? extends K, ? extends @nonnull V>` returned into a `CompletableFuture<? extends Map<? extends K, ? extends @nonnull V>>` reaches the check as `Map<capture of ? extends K, capture of ? extends V>`, with no `@NonNull` left on `V`.

Caller sees:
- `incompatible types: Box<T> cannot be converted to Box<? extends Object>` where `T`'s declared bound admits null; accepted before.
- `mismatched type parameter nullability` on an override that returns `List<V>` where the overridden method returns `List<? extends @nonnull V>` and `V` may be null; accepted before. Caffeine's `AsyncCacheLoader.bulk` is such an override. Code that compiled clean can need a narrower return type or a suppression.
- `mismatched type parameter nullability` on an override of a generic method whose type variable admits null, when the override declares that variable without `@Nullable`, for example `<U> CompletionStage<U> thenApply(Function<? super T, ? extends U> fn)` overriding the unannotated JDK method. It comes beside the existing `Method type variable U has a non-null upper bound` report for the same declaration, because the overridden method's type variables are not renamed to the overrider's before the comparison.
- `incompatible types: List<String> cannot be converted to List<@nullable String>` where a `@Nullable` argument is passed to a generic method of unannotated code that declares `T extends @nonnull Object` and the result is assigned to `List<@nullable String>`; accepted before. `GenericsUtils.upperBoundIsNullable` now checks an explicit annotation on a bound before the default of unannotated code, as JSpecify requires, so inference treats such a type variable as non-null. Wildcard bounds and both sides of the override bound check change only for a type variable whose bound reaches one, such as `<U extends S>` with `S extends @nonnull Object` in unannotated code. Any annotation NullAway recognizes as non-null counts.

Not changed:
- `ConstraintSolverImpl` builds its constraints from wildcard upper bounds without this rule, so a type variable whose bound admits null, inferred into a non-null `? extends` position, may still go unreported.
- `? super` containment does not resolve a type variable actual; javac rejects a `Box<T>` for a `Box<? super Object>` before NullAway runs.
- A captured actual still skips the null check, so `Source<? extends T>.load()` returning `List<E>` passes as `List<? extends @nonnull T>` when `T`'s bound admits null. Such a capture cannot be told apart from the one in `asyncLoadAll`, whose `@NonNull` inference dropped.
- A type variable bounded by an intersection whose every element is `@Nullable`, such as `T extends @nullable Object & @nullable Serializable`, is still treated as excluding null: `upperBoundIsNullable` reads the annotations of the intersection, not of its elements. apache#1836 fixes that.

The new tests in `WildcardTests` put the reported and the accepted cases of each rule in one source, and a mutation of each branch of the new code turns at least one of them red. The library-model rule has no test through the new code: a model keys the bound to a class's own type parameter, which checked code sees only after substitution.

`GenericsChecks` decides whether a bound admits null by hand in three more places; unifying them is outside this change. This is the first commit of apache#1828 as a standalone change; apache#1828 rewrites the message of the same diagnostic in `CheckIdenticalNullabilityVisitor`, `GenericsChecks`, and `WildcardTests`, so it goes after this one.

Assisted-by: Claude Code (claude-opus-5-5)
vlsi added a commit to vlsi/NullAway that referenced this pull request Oct 9, 2026
…ard is required

Previously, a `Box<T>` declared with `T extends @nullable Object` was accepted where a `Box<? extends Object>` was required, so a null could reach a position that rejects one. A wildcard actual in that position was judged by its effective upper bound, but a type variable was judged by its use site, which carries no nullness of its own, so every such assignment, argument, and return passed. No diagnostic marks the defect; the symptom is the missing error.

`CheckIdenticalNullabilityVisitor` now compares a type variable that carries no `@Nullable` or `@NonNull` at its use site as its declared upper bound. That bound admits null when it is annotated `@Nullable`, when a library model overrides it, or when the variable is declared in unannotated code and its bound is not annotated `@NonNull`.

A requirement that names a type variable, `? extends T`, admits whatever `T` is instantiated as, so there the two types are compared as written: `Box<T>` and `Box<S extends T>` stay assignable to `Box<? extends T>`, and `Box<@nullable T>` is still reported. The check then also asks whether the actual may be null where this instantiation of `T` may not: it walks the actual's declared bounds up to `T` and looks for a link annotated or declared `@Nullable`. So `Box<S>` with `S extends @nullable T` passed to `Box<? extends T>` is reported whatever `T`'s own bound, and so is `Box<T>` passed to `Box<? extends @nonnull T>` when `T`'s bound admits null. Where the walk does not reach `T`, as between the type variables of an overriding and an overridden generic method, the check adds nothing. The `@NonNull` that inference substitutes for a type variable it finds not `@Nullable` does not count as a written `? extends @nonnull T`, so `new HashSet<>(list)` and `copyOf(list)` with a `List<T>` keep compiling. Substituting `T`'s bound instead was tried: on the requirement side alone it reports Caffeine's `CacheLoader.asyncReload`, where `CompletableFuture.supplyAsync` infers `CompletableFuture<V>` against `CompletableFuture<? extends V>`, and on both sides it silences the `Box<@nullable T>` report.

```text
CacheLoader.java:196: error: [NullAway] incompatible types: CompletableFuture<V> cannot be converted to CompletableFuture<? extends V>
```

A captured actual skips the null check, because capture conversion drops type-use annotations. In Caffeine's `CacheLoader.asyncLoadAll`, a `Map<? extends K, ? extends @nonnull V>` returned into a `CompletableFuture<? extends Map<? extends K, ? extends @nonnull V>>` reaches the check as `Map<capture of ? extends K, capture of ? extends V>`, with no `@NonNull` left on `V`.

Caller sees:
- `incompatible types: Box<T> cannot be converted to Box<? extends Object>` where `T`'s declared bound admits null; accepted before.
- `mismatched type parameter nullability` on an override that returns `List<V>` where the overridden method returns `List<? extends @nonnull V>` and `V` may be null; accepted before. Caffeine's `AsyncCacheLoader.bulk` is such an override. Code that compiled clean can need a narrower return type or a suppression.
- `incompatible types: List<String> cannot be converted to List<@nullable String>` where a `@Nullable` argument is passed to a generic method of unannotated code that declares `T extends @nonnull Object` and the result is assigned to `List<@nullable String>`; accepted before. `GenericsUtils.upperBoundIsNullable` now checks an explicit annotation on a bound before the default of unannotated code, as JSpecify requires, so inference treats such a type variable as non-null. Wildcard bounds and both sides of the override bound check change only for a type variable whose bound reaches one, such as `<U extends S>` with `S extends @nonnull Object` in unannotated code. Any annotation NullAway recognizes as non-null counts.

Not changed:
- `ConstraintSolverImpl` builds its constraints from wildcard upper bounds without this rule, so a type variable whose bound admits null, inferred into a non-null `? extends` position, may still go unreported.
- `? super` containment does not resolve a type variable actual; javac rejects a `Box<T>` for a `Box<? super Object>` before NullAway runs.
- A captured actual still skips the null check, so `Source<? extends T>.load()` returning `List<E>` passes as `List<? extends @nonnull T>` when `T`'s bound admits null. Such a capture cannot be told apart from the one in `asyncLoadAll`, whose `@NonNull` inference dropped.
- A type variable bounded by an intersection whose every element is `@Nullable`, such as `T extends @nullable Object & @nullable Serializable`, is still treated as excluding null: `upperBoundIsNullable` reads the annotations of the intersection, not of its elements. apache#1836 fixes that.

The new tests put the reported and the accepted cases of each rule in one source, and a mutation of each branch of the new code turns at least one of them red. The library-model rule has no test through the new code: a model keys the bound to a class's own type parameter, which checked code sees only after substitution.

`GenericsChecks` decides whether a bound admits null by hand in three more places; unifying them is outside this change. This is the first commit of apache#1828 as a standalone change; apache#1828 rewrites the message of the same diagnostic in `CheckIdenticalNullabilityVisitor`, `GenericsChecks`, and `WildcardTests`, so it goes after this one.

Assisted-by: Claude Code (claude-opus-5-5)
vlsi added a commit to vlsi/NullAway that referenced this pull request Oct 9, 2026
…ard is required

Previously, a `Box<T>` declared with `T extends @nullable Object` was accepted where a `Box<? extends Object>` was required, so a null could reach a position that rejects one. A wildcard actual in that position was judged by its effective upper bound, but a type variable was judged by its use site, which carries no nullness of its own, so every such assignment, argument, and return passed. No diagnostic marks the defect; the symptom is the missing error.

`CheckIdenticalNullabilityVisitor` now compares a type variable that carries no `@Nullable` or `@NonNull` at its use site as its declared upper bound. That bound admits null when it is annotated `@Nullable`, directly or through the bound of another type variable that carries no annotation, or when a library model overrides it. A type variable declared in unannotated code with no `@Nullable` on its bound and no library model is not reported, as NullAway stays optimistic about unannotated code: the unannotated default of `upperBoundIsNullable`, which lets inference, override, and wildcard-bound checks accept a nullable instantiation, does not apply to this check. A `@Nullable` written in unannotated code still counts, since JSpecify gives annotations in null-unmarked code their meaning.

A requirement that names a type variable, `? extends T`, admits whatever `T` is instantiated as, so there the two types are compared as written: `Box<T>` and `Box<S extends T>` stay assignable to `Box<? extends T>`, and `Box<@nullable T>` is still reported. The check then also asks whether the actual may be null where this instantiation of `T` may not: it walks the actual's declared bounds up to `T` and looks for a link annotated or declared `@Nullable`. So `Box<S>` with `S extends @nullable T` passed to `Box<? extends T>` is reported whatever `T`'s own bound, and so is `Box<T>` passed to `Box<? extends @nonnull T>` when `T`'s bound admits null. Where the walk does not reach `T`, as between the type variables of an overriding and an overridden generic method, the check adds nothing. The `@NonNull` that inference substitutes for a type variable it finds not `@Nullable` does not count as a written `? extends @nonnull T`, so `new HashSet<>(list)` and `copyOf(list)` with a `List<T>` keep compiling. Substituting `T`'s bound instead was tried: on the requirement side alone it reports Caffeine's `CacheLoader.asyncReload`, where `CompletableFuture.supplyAsync` infers `CompletableFuture<V>` against `CompletableFuture<? extends V>`, and on both sides it silences the `Box<@nullable T>` report.

```text
CacheLoader.java:196: error: [NullAway] incompatible types: CompletableFuture<V> cannot be converted to CompletableFuture<? extends V>
```

A captured actual skips the null check, because capture conversion drops type-use annotations. In Caffeine's `CacheLoader.asyncLoadAll`, a `Map<? extends K, ? extends @nonnull V>` returned into a `CompletableFuture<? extends Map<? extends K, ? extends @nonnull V>>` reaches the check as `Map<capture of ? extends K, capture of ? extends V>`, with no `@NonNull` left on `V`.

Caller sees:
- `incompatible types: Box<T> cannot be converted to Box<? extends Object>` where `T`'s declared bound admits null; accepted before.
- `mismatched type parameter nullability` on an override that returns `List<V>` where the overridden method returns `List<? extends @nonnull V>` and `V` may be null; accepted before. Caffeine's `AsyncCacheLoader.bulk` is such an override. Code that compiled clean can need a narrower return type or a suppression.

Not changed:
- `ConstraintSolverImpl` builds its constraints from wildcard upper bounds without this rule, so a type variable whose bound admits null, inferred into a non-null `? extends` position, may still go unreported.
- A `? extends @nonnull T` whose `@NonNull` comes from a library model or from stream nullability propagation carries NullAway's synthetic annotation, which this check cannot tell apart from the one inference substitutes, so it counts as `? extends T`. That can miss an error, not add one.
- `? super` containment does not resolve a type variable actual; javac rejects a `Box<T>` for a `Box<? super Object>` before NullAway runs.
- A captured actual still skips the null check against a requirement that names a type variable. So `Source<? extends T>.load()` returning `List<E>` passes as `List<? extends @nonnull T>` when `T`'s bound admits null, and `Holder<S>.get()` returning `Box<? extends X>` passes as `Box<? extends T>` for `S extends @nullable T`. Such a capture cannot be told apart from one whose `@NonNull` inference dropped, as in `asyncLoadAll` or a `Map<String, ? extends @nonnull S>` returned through `CompletableFuture.supplyAsync`, and checking it reported those.
- A type variable bounded by an intersection whose every element is `@Nullable`, such as `T extends @nullable Object & @nullable Serializable`, is still treated as excluding null: `upperBoundIsNullable` and the new `GenericsUtils.boundIsExplicitlyNullable` read the annotations of the intersection, not of its elements. apache#1836 fixes `upperBoundIsNullable`; the new helper needs the same change.

The new tests put the reported and the accepted cases of each rule in one source, and a mutation of each branch of the new code turns at least one of them red. The library-model rule has no test through the new code: a model keys the bound to a class's or method's own type parameter, which checked code sees only after substitution.

`GenericsChecks` decides whether a bound admits null by hand in three more places; unifying them is outside this change. This is the first commit of apache#1828 as a standalone change; apache#1828 rewrites the message of the same diagnostic in `CheckIdenticalNullabilityVisitor`, `GenericsChecks`, and `WildcardTests`, so it goes after this one.

Assisted-by: Claude Code (claude-opus-5-5)
The target line of a nested array prints its dimensions innermost first (apache#2201), and the target line of an intersection has no caret (apache#2202).

Assisted-by: Claude Code (claude-opus-5-5)
vlsi added 12 commits November 30, 2026 00:16
A `possible fix:` line, and the edit that pastes it, could print a type that does not compile or that drops an annotation the check relied on:

- With `CustomNullableAnnotations` naming a type-use annotation whose simple name is not `Nullable`, `Map<?, @CanBeNull String> m = make();` was rewritten to `Map<? extends Object, String> m = make();`. `isDeclarable` accepted every nullable annotation, while the printer prints only one named `Nullable`.
- A local class declared in an instance method, a constructor, or an initializer printed as `Test.Local<? extends Object>`, which names no type.
- For an inner class, `@Nullable Test.Inner<?> x` was rewritten to `@Nullable @nullable Test.Inner<? extends Object> x`. javac attaches a type-use annotation among the modifiers to `Test`, the leftmost type the type tree names, and the printer left the annotation out only on the root type.

The printer and `isDeclarable` now read the same two predicates: which annotation the printer prints, and whether a class prints its enclosing type. A type carrying any other annotation withholds the fix. The enclosing type prints only for a member class, as javac's `ClassType.toString` does. The modifier's annotation is left out on the leftmost type, reached through array elements and enclosing types.

User-visible:
A custom type-use nullable annotation of another simple name withholds the `possible fix:` line and its edit.
The `source:` and `target:` lines print a local class under its simple name, `Local<?>`, where they printed `Test.Local<?>`.
The `possible fix:` line and its edit spell an array as a declaration does, `List<@nullable String>[]`; the `source:` and `target:` lines keep `List<@nullable String> []`.

Assisted-by: Claude Code (claude-opus-5-5)
A `possible fix:` line or its Error Prone edit can produce code that does not compile or that NullAway rejects again: the edit for a local is checked only at the reported pseudo-assignment, and the printed type can drop a custom nullable annotation, qualify a local class, or repeat a modifier's annotation. FixRoundTripTests applies every fix of a program, the edits through `-XepPatchChecks` and each `declare <name> as <type>` line by rewriting that declaration, and compiles the result with NullAway again. After the edits, no generic mismatch may remain on a line naming the rewritten variable; after a text line, none on the reported line and no javac error.

The programs these fixes break today are marked as known failures, which fail once they start passing: four for the edit of a local (`List<?> l = make(); take(l);`, a `@Nullable` type argument in the initializer, a rejected reassignment, and a target local that is returned) and seven for the printed type (a custom nullable annotation, local classes outside a static method, and an inner class with a nullable modifier).

Assisted-by: Claude Code (claude-opus-5-5)
…ccepts it

The source fix of a local was checked only at the reported pseudo-assignment. For `List<?> l = make(); take(l);`, with `make()` returning `List<?>`, the message offered `declare l as List<? extends Object>` and the edit wrote it, and NullAway then reported `List<? extends Object> l = make();`, with a fix that wrote the old type back. The target-side edit had the same gap at a later read of the local: after `Map<? extends Object, @nullable String> declared = m;`, NullAway reported `return declared;`.

The source rewrite makes the local's type less nullable, so only the values assigned to the local can reject it. Where the check rejects the rewritten type for the initializer or for a simple assignment to the local, the source fix is not offered; a target fix, where there is one, stays. Where every value is accepted, the fix gets the edit as well. The walk that already indexes the local declarations of the unit records those values, and their paths share the enclosing method's path with the reported site, so a dataflow run keyed on it is reused. The edit, but not the line, is withheld where the type of a value cannot be computed without changing what the check later computes: a lambda, a method reference, a conditional expression, and a generic call or diamond whose inference the check has not run yet, since running it against the rewritten type would cache that result. The variable of an enhanced for loop gets the line and no edit. The target fix gets no edit at all, since the rewritten variable may be read as a source anywhere in its scope.

`FixRoundTripTests` applies each fix line and each edit and recompiles: a source fix has to leave no mismatch on any line naming the variable, a target fix none on the reported line.

User-visible:
A local source whose initializer or an assignment to it rejects the rewritten type gets no `possible fix:` line for itself; where the target can be fixed, the message offers only that fix.
A `possible fix:` line for the target type carries no `Did you mean` edit.
A `possible fix:` line for a local source carries the edit only where the type of every value assigned to it is known and accepts the rewritten type.
Where both fixes are offered, the message lists them under `possible fixes:`, each with its condition:

    possible fixes:
      if list never holds null: declare list as List<? extends Object>
      if it may: declare c as Collection<? extends @nullable Object>

Assisted-by: Claude Code (claude-opus-5-5)
A note under a wildcard mismatch could leave out the bound, state a bound with `capture of ?` substituted into it, or state a bound whose nullness contradicts the first line of the message, and a test that pinned such a note passed. MismatchMessageTestBase now checks every diagnostic it compares, whatever text the test expects: each note states an upper bound and cites JLS 5.1.10, the stated bound contains no `capture of`, and where the message has one note and its path ends at the source wildcard's upper bound, the bound has the top-level nullness the first line gives the source. A test reports every broken invariant it saw, with the text mismatch attached as suppressed.

NoteTests gains the cases that break them on this commit: captured wildcards whose note names only a type parameter, a subclass bound that disagrees with the compared one (apache#2206), and bounds that depend on a wildcard argument. These tests and the captured-note tests in CaretTests and ViewedSourceTests fail until the next commit fixes the notes.

Assisted-by: Claude Code (claude-opus-5-5)
The note under a wildcard mismatch could contradict the first line of the message or name the wrong type parameter. For a captured wildcard it named the type parameter from WildcardType.bound, which javac rebinds whenever it substitutes the wildcard into a supertype, so an unrelated earlier statement changed the note from `E of List` to `E of SequencedCollection`. Where the class the target names bounds its type parameter otherwise than the printed holder does (apache#2206), the holder note gave the holder's bound, whose nullness disagrees with the one the first line reports. And a bound that depends on another wildcard argument was printed with `capture of ?` substituted into it.

The check now records, where it goes below a wildcard's implicit bound, the bound it stepped to and the steps it took below it. The note for a captured wildcard states that bound and names a type parameter only where the caret's type-argument step is the one the capture instantiates. A holder note is printed only where its declared bound, followed along the recorded steps, has the nullness the first line gives. The declared bound substitutes only the type arguments that are neither wildcards nor captures.

User-visible:
A captured wildcard's note reads `capture of ? is the captured type argument for T of Box, whose upper bound is @nullable Object (JLS 5.1.10)` where the capture instantiates the printed type parameter, and `capture of ? is a captured wildcard whose upper bound is @nullable Object (JLS 5.1.10)` otherwise.
Where the printed holder's declared bound disagrees with the nullness the check found, the message has no note.
A bound that depends on a wildcard argument keeps that type parameter's name, as in `which is List<A>`.

Assisted-by: Claude Code (claude-opus-5-5)
Resolve the conflicts with W1-A's source-only edits: the fix text prints through printForFixLine, the target fix keeps no edit, and the inner-class cases of FixTests use W1-A's accepting initializers. FixRoundTripTests runs the F70, F71, and F74 cases as ordinary round trips.

Assisted-by: Claude Code (claude-opus-5-5)
Assisted-by: Claude Code (claude-opus-5-5)
A message whose source is less nullable than the target said "a non-wildcard type argument must be the same type", which did not say the same as what, and a Java reader sees String and @nullable String as one type. The first line now says "a non-wildcard type argument must have the same nullness in source and target", and so does the numbered entry.

The first line said "and N other positions" and the line after the list said "and N more, not listed", which read as two counts of different things. Both now count differing positions: "and N other differing positions" on the first line, and "and N more differing positions, not listed" after the five listed entries.

TypePath.Step no longer carries the owner class of a type-argument step beside its type parameter; describe() takes it from the type parameter's owner. Kind.WILDCARD_BOUND and wildcardBound() are WILDCARD_UPPER_BOUND and wildcardUpperBound(), beside WILDCARD_LOWER_BOUND.

Three guards gain the tests they lacked: the source fix is withheld for a member read through a parameterized receiver, whose declared type differs from the type it is read at; under a ? super bound the target is the subtype side, for a reordering subclass and for a wildcard only the source states; and a declaration whose second declarator has annotated brackets gets no edit.

User-visible:
Where a non-null type argument meets a @nullable one, the first line and the numbered entry say "a non-wildcard type argument must have the same nullness in source and target".
Where several positions differ, the first line says "and N other differing position(s)" and the line after the five listed entries says "and N more differing position(s), not listed".

Assisted-by: Claude Code (claude-opus-5-5)
…n to accept it

The source fix of a local was dropped only where a value assigned to the local was known to reject the rewritten type. Where the type of a value was not computed, the `possible fix:` line was still printed, and applying it could move the error. After `declare s as Source<? extends Object>` for `Source<?> s = () -> null;`, NullAway reported the lambda. A resource variable skipped the check entirely, so `try (Res<?> r = open())` got the line even where `open()` rejects the rewrite. The loop variable of an enhanced for loop also skipped it, including assignments to it in the body.

Each branch of a conditional expression is now checked as a value of its own, under the path of the conditional, as the conditional check compares each branch with the local's type. A raw value is accepted, since the assignment check skips it. The initializer of a resource variable is recorded and checked in the walk that already indexes the unit. For the variable of an enhanced for loop, the loop's elements count as accepted, since no generic check compares them with the variable's type, and assignments to it in the body are checked. Where a value still cannot be shown to accept the rewrite, such as a lambda, a method reference, or a generic call whose inference has not run, the source fix is not offered. A resource or loop variable gets the line without the edit.

User-visible:
A local or resource variable source gets no `possible fix:` line for itself unless each value assigned to it is shown to accept the rewritten type; where the target can be fixed, the message offers only that fix.
A local initialized by a conditional expression whose branches each accept the rewritten type gets the source fix and its `Did you mean` edit.

Assisted-by: Claude Code (claude-opus-5-5)
…ocal value once

Four gaps in the `possible fix:` lines of a generic nullability mismatch message.

The printer writes an annotation named `Nullable` without its element values and writes none on a wildcard, but the declarability check accepted both. So `Map<?, @p.Nullable("x") String>` got `declare m as Map<? extends Object, @nullable String>`, which does not compile where `value` is required. The target fix had the same gap where it copied such an annotation from the source. The check also looked only at the rewritten type, which a rewrite builds from new nodes, so an annotation on the node it replaced was dropped silently: `Map<String, @tainted String> d = m` got `declare d as Map<String, @nullable String>`, and `Map<@tainted ?, String>` lost its `@Tainted`. A fix is now offered only where the printer reproduces every annotation of both the declared type it replaces and the type it declares: `@Nullable` with no element values, and no annotation on a wildcard. The target fix copies a nullable annotation only where it has no element values.

The source fix of a local checked every value assigned to the local against the rewritten type once per diagnostic that read the local, so a local with W values read R times cost R × W checks. A definite result is now kept per value tree and rewritten type, keyed by `Type.toString()`, which qualifies names and keeps annotations, and cleared with the unit's index. An unknown result, such as a generic call whose inference has not run yet, is computed again on the next read.

A pattern variable, and any variable kind other than a local, resource, parameter, or field, got an unchecked source fix. Only those four kinds now get one: a local or resource where its values are shown to accept the rewrite, and a parameter or field unchecked, as before.

User-visible:
No `possible fix:` line is offered where the declared type it replaces or the type it declares carries a type-use annotation other than `@Nullable`, a `@Nullable` with element values, or an annotation on a wildcard.
A pattern variable gets no source fix; a target fix beside it is unchanged.

Assisted-by: Claude Code (claude-opus-5-5)
…ter's fix

A `note:` about a captured wildcard printed the capture's upper bound as javac holds it, and that bound refers to the captures of the class that holds the wildcard. For `Self<T extends @nullable Comparable<T>>` and a `Self<?>` source, the note read `whose upper bound is @nullable Comparable<capture of ?>`. The note now prints each capture among the holder's type arguments as the type parameter it instantiates: `@Nullable Comparable<T>`. Where the note does not name the holder's class, a type parameter of that class or of a class enclosing it would name nothing, so the note is left out, as it is where the bound still holds a capture. The note on an unbounded wildcard below the root of a supertype view printed such a capture too, and is left out the same way.

A lambda parameter, explicitly or implicitly typed, got `declare l as List<? extends Object>`. The functional interface fixes that type: the line compiles, since javac treats `List<?>` and `List<? extends Object>` as the same type, and NullAway then reports the parameter as one whose type arguments differ from those of the method it overrides. A lambda parameter now gets no source fix. `FixRoundTripTests` counts that report as well as a generic mismatch on the lines it checks.

Each diagnostic that read a local rebuilt the path of every value assigned to it before looking up the kept result, so D reads of a local with A values cost D × A rebuilds. A path is now rebuilt only where the check runs, and the values after an unknown one are still checked so that their definite results are kept.

User-visible:
A `note:` about a captured wildcard prints a type parameter of the class that holds it where its bound used to print `capture of ?`, and is left out where the bound cannot be printed without one.
A lambda parameter gets no `possible fix:` line for itself.

Assisted-by: Claude Code (claude-opus-5-5)
vlsi added 6 commits November 30, 2026 17:54
A generic nullability message ended with a `possible fix:` line that named a declaration to rewrite. For a local variable, it also attached an edit. Keeping the line correct took a check of every value assigned to the local, a printer mode that reproduces declarations as written, and a cache cleared per compilation unit. It also needed rules for where the rewritten type compiles yet moves the error, such as a lambda parameter. The fix is moved to apache#2216, so this change keeps the path, caret, and note lines and drops the rest.

The printer goes back to master's printing of a local class's enclosing type, which only the fix needed to change. Two display cases that only the fix tests checked move to `NoteTests` and `CaretTests`: a wildcard in an enclosing type argument, and the printed form of annotations not named `Nullable`.

User-visible:
A generic nullability mismatch no longer prints a `possible fix:` line and carries no suggested edit.

Assisted-by: Claude Code (claude-opus-5-5)
Two mismatches can mark nested nodes of one printed type. This happens where a supertype view puts one type argument at two positions: for `interface Same<T> extends Pair<T, T>`, passing a `Same<@nullable List<@nullable String>>` to a `Pair<? extends List<@nullable String>, ? extends @nullable List<String>>` marks both the list and its element. The caret parser assumed marks never nest. It stopped at the inner end marker, so the source line read `Same<@nullable List<1@Nullable String>>`, and the second caret and its number were lost. The parser now keeps open marks on a stack. Each level of nesting gets its own caret row, and its own number row where the message is numbered, outermost first. Output where nothing nests is unchanged.

`TypePath.then` copied every step above it, so walking or printing a type nested N deep stored N(N+1)/2 steps, even with no caret requested. A path now shares its parent and stores one step. `steps()` builds the list root-first on demand.

Building a message reruns the nullability check over both types, and `reportNullabilityMismatch` skips that for a suppressed error. The test for that shortcut went away with the fix code. A counting hook on the message build brings it back: three mismatches in a class excluded by `ExcludedClassAnnotations` build no message, and one outside it builds one.

User-visible:
Where a supertype view marks a node inside another marked node, the `source:` line prints the type without stray digits, and each marked node gets its own caret run and number.

Assisted-by: Claude Code (claude-opus-5-5)
Each caret's number started under the first column of its caret, on one row per level of nesting. Where a number was wider than the gap to the next caret, the two ran together. For `ThreeAndTwo<?, ?>`, whose wildcards hide three and two differences, the row read `1,2,34,5`. A number now goes on the first number row of its level that leaves a space before it, and a new row opens where none does. A level's number rows all come before the next level's caret row. Output where no numbers collide is unchanged.

The test that `TypePath.then` shares its parent counted `then` calls through a hook that always reported one stored step, so a `then` that copied the path still passed it. The hook is gone. The test now checks that each new path's parent is the path it extends, and that `TypePath` has no instance fields but its parent, its last step, and its depth.

User-visible:
On a numbered `source:` or `target:` line, a caret number that would run into the one before it is printed on another row under its caret.

Assisted-by: Claude Code (claude-opus-5-5)
The previous commit put four `import` lines into the Java source that `aMismatchInAnExcludedNestedClassBuildsNoMessage` compiles. They belonged in the test class's import list. The formatter then moved the text block's opening quotes to column 0. The block is restored as it was.

A new `CaretTests` case has a number row that would collide at a level with a deeper caret row below it. Its extra number row prints before that caret row, and a version that appends extra number rows after every caret row fails the case.

Assisted-by: Claude Code (claude-opus-5-5)
Building the message for a mismatch whose compared bound is an inner class of a generic outer crashed NullAway where the holder's type parameter was bounded by a top-level subclass of it:

    java.lang.NullPointerException: Cannot invoke "Object.equals(Object)" because "node.tsym" is null
        at NullabilityMismatchMessage.typeArgumentAt

`hasNullnessAt` stepped into the enclosing type of the top-level class, got javac's `noType`, and the next type-argument step dereferenced its null `tsym`. A second copy of the same descent, `nodeAt`, did not step through a captured wildcard, so a `?` marked inside a capture's printed bound got the bare `in the source` note instead of naming its class and type parameter.

Four walkers (`nodeAt`, `hasNullnessAt`, `childByPosition`, `followDeclared`) each worked out the child a `TypePath.Step` reaches, and the copies had drifted. `TypePath.childAt` now owns that descent: an enclosing type only where it is a class type, and a wildcard bound, of a wildcard or of the wildcard a capture stands for, only where the wildcard states a bound of the step's kind. The walkers keep only their own cases: the hidden track below `?`, the bound of a type variable, the supertype view, and the class check.

Also: tests that kill the round-4 survivors in `followDeclared`, `viewedAs`, `printsTypeVariable`, `printedCapturedBound`, `enterLowerBounds`, and the provisional wildcard-comparison entry (a depth-24 input whose sides differ at every level, which times out without that entry); comment fixes; the private comparison record renamed `ComparisonStep`; the marking printer checks its ten-path limit.

User-visible:
A mismatch whose holder's type parameter is bounded by a top-level subclass of an inner class is reported instead of crashing NullAway.
A `?` inside the printed bound of a captured wildcard gets the note that names its class and type parameter, as `note: the unbounded wildcard ? in List<?> has the upper bound of type parameter E of List, which is @nullable Object (JLS 5.1.10)`.
The clause for a non-wildcard type argument reads `a non-wildcard type argument must have the same nullability in source and target`.

Assisted-by: Claude Code (claude-opus-5-5)
A source caret was placed only on a node of the class the comparison steps from. No test checked
that: mutation testing removed the check and every test still passed, because the one input that
reaches it, an intersection source whose other component holds a type argument at the same index,
asserted only the first line. ViewedSourceTests now asserts the whole message for it; with the check
removed, the caret moves under the type argument of the other component.

childByPosition returns null for the enclosing type of a top-level class, which nearly every message
reaches; its Javadoc now says so, and the diff-coverage marker that called the branch unreached is
gone.

A test key in NoteTests that pins a missing note below the enclosing type of a subclass bound is
renamed to say the note is missing, and a comment explains why.

The TypePath class comment no longer says every step is one the printer takes, and a comment in
TraversalCostTests is rewrapped.

Assisted-by: Claude Code (claude-opus-5-5)
Assisted-by: Claude Code (claude-opus-5-5)
vlsi added 2 commits December 1, 2026 10:09
…e bound origin

Where the check viewed the source as a supertype and the differing node was also in the written type, as for an intersection bound, the caret moved to the `source supertype:` line and the `source:` line printed none. The note was built from two separate decisions, one on whether the wildcard's bound came from the class that declares the type parameter and one on whether that class is unannotated, so a captured wildcard two subclasses down was named as the type argument of a class it does not instantiate, and the `, and X is unannotated` ending appeared for a captured wildcard only. Below a hidden bound the note could name a bound whose declaration carries no nullness at the compared position (apache#2206).

`boundOriginNote` now computes one `BoundOrigin` (the type parameter, its owner, and whether the owner is unannotated) and every kind of wildcard reads from it. `NullabilityMismatches.Frame` records the bound the walk entered below the last shown source node, whether or not a line marks that node, so the note checks the bound the check compared even below the root of a supertype view.

User-visible:
Where a `source supertype:` line is printed and the differing node is in the written type, the caret stays on the `source:` line.
A note for an unbounded `?` or a `? super X` ends in `, and X is unannotated` where the class that declares the type parameter is unannotated, as the captured-wildcard note already did.
A captured wildcard is named `the captured type argument for T of C` only where it fills `T` of `C`; otherwise the note reads `is a captured wildcard whose upper bound is …`.
Below an implicit bound whose declaration has no nullness at the compared position, there is no note, also below the root of a supertype view (apache#2206).

Assisted-by: Claude Code (claude-opus-5-5)
A note named the wildcard's own type parameter wherever its bound had the
compared bound's nullness at one node, so SubL<T extends @nullable
List<String>> got a note stating a bound the check did not compare (apache#2206).
The note now names that type parameter only where its declared bound prints
as the compared bound does at every node, after substituting the type
arguments the holder's class passes; otherwise there is no note. TopSub,
whose bound is a subclass of the compared one, loses its note (apache#2224).

The "the bound is @nullable because X is unannotated" ending now names the
class whose bound the check compared, and appears only where the types
differ at the bound itself and both that bound and the named type
parameter's bound carry NullAway's synthetic @nullable for unannotated code,
not one written in the source or substituted by capture conversion.

A source supertype line is printed only where it carries a caret, and a
type line carries one run of carets. HIDDEN tracks and hidden bounds are
decided by one predicate.

The test invariants now match the four-space type lines they were meant to
check, and require that a note with the unannotated ending states a
top-level @nullable bound under a path that ends at the wildcard's upper
bound.

User-visible:
SubL<?> passed as Base<? extends Object>, where SubL<T extends @nullable List<String>> extends Base<T>, prints no note.
@NullUnmarked NestedLegacy<T extends List<@nullable String>> passed as NestedLegacy<? extends @nullable List<String>> prints its note without "; the bound is @nullable because NestedLegacy is unannotated".

Assisted-by: Claude Code (claude-opus-5-5)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

JSpecifyExperimental: false positive for addAll with ? element type

2 participants