Skip to content

Substitute the explicit type arguments of a generic constructor call - #2194

Open
vlsi wants to merge 1 commit into
apache:masterfrom
vlsi:explicit-constructor-type-arguments
Open

vlsi wants to merge 1 commit into
apache:masterfrom
vlsi:explicit-constructor-type-arguments

Conversation

@vlsi

@vlsi vlsi commented Nov 26, 2026

Copy link
Copy Markdown
Contributor

In JSpecify mode, the check of nested nullability at a call compared the arguments of a generic constructor with its type variables left free, even where the call names its type arguments. new <@Nullable String>Consumer(nullable), with <U extends @Nullable Object> Consumer(Box<U> input) and a Box<@Nullable String> argument, was reported as incompatible types: Box<@Nullable String> cannot be converted to Box<U>, while the generic method call Test.<@Nullable String>consume(nullable) was not.

getInvokedMethodTypeAtCall now substitutes the explicit type arguments of a constructor call as it does those of a method call, in every JSpecify mode. The target type a generic call gets as an argument of such a constructor call takes them too, so make() in new <@Nullable String>Consumer(make()) is inferred against Box<@Nullable String> and not against Box<U>; without that, the argument check would compare an argument inferred as Box<String> with Box<@Nullable String>. A constructor call without explicit type arguments is checked as before.

User-visible:
new <@Nullable String>Consumer(boxOfNullable) is no longer reported.
new <String>Consumer(boxOfNullable) is still reported, as incompatible types: Box<@Nullable String> cannot be converted to Box<String> instead of ... to Box<U>.
new <@Nullable String>Consumer(boxOfNonNull) is now reported, as incompatible types: Box<String> cannot be converted to Box<@Nullable String>.

Fixes #2193

Scope. #1955 changes the same if in getInvokedMethodTypeAtCall to infer the type arguments of a generic constructor called with a diamond; its inference path returns early for a call with explicit type arguments, so the two changes do not overlap in behavior and whichever lands second needs a textual merge only. Inference for a generic constructor called without a diamond and without type arguments stays as it is (#2191).

Verification. PIT keeps one mutant on the changed condition: it treats tree instanceof NewClassTree as always true, which is equivalent because only a method invocation or a constructor call reaches that check.

🤖 Generated with Claude Code

In JSpecify mode, the check of nested nullability at a call compared the arguments of a generic constructor with its type variables left free, even where the call names its type arguments. `new <@nullable String>Consumer(nullable)`, with `<U extends @nullable Object> Consumer(Box<U> input)` and a `Box<@nullable String>` argument, was reported as `incompatible types: Box<@nullable String> cannot be converted to Box<U>`, while the generic method call `Test.<@nullable String>consume(nullable)` was not.

`getInvokedMethodTypeAtCall` now substitutes the explicit type arguments of a constructor call as it does those of a method call, in every JSpecify mode. The target type a generic call gets as an argument of such a constructor call takes them too, so `make()` in `new <@nullable String>Consumer(make())` is inferred against `Box<@nullable String>` and not against `Box<U>`; without that, the argument check would compare an argument inferred as `Box<String>` with `Box<@nullable String>`. A constructor call without explicit type arguments is checked as before.

User-visible:
`new <@nullable String>Consumer(boxOfNullable)` is no longer reported.
`new <String>Consumer(boxOfNullable)` is still reported, as `incompatible types: Box<@nullable String> cannot be converted to Box<String>` instead of `... to Box<U>`.
`new <@nullable String>Consumer(boxOfNonNull)` is now reported, as `incompatible types: Box<String> cannot be converted to Box<@nullable String>`.

Fixes apache#2193

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

coderabbitai Bot commented Nov 26, 2026

Copy link
Copy Markdown
Contributor

Explain Change →

No actionable comments were generated in the recent review.

Walkthrough

In JSpecify mode, explicit type arguments on generic constructor calls were not applied when checking constructor parameters. The change resolves constructor parameter types using the call’s explicit type arguments. Calls without explicit constructor type arguments retain their existing type-variable behavior. A regression test covers nullable and non-null type arguments for constructors and methods.

Severity of issue fixed: Low

Merge Risk: Minimal · up to 06711

This change applies explicit type arguments on generic constructor calls when checking arguments under JSpecify, matching how method calls already behave. The behavior change is narrow, regression tests cover it, and no merge-blocking risk was identified.

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

@codecov

codecov Bot commented Nov 26, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 85.71429% with 2 lines in your changes missing coverage. Please review.
✅ Project coverage is 89.56%. Comparing base (af5ba08) to head (067112a).

Files with missing lines Patch % Lines
...ava/com/uber/nullaway/generics/GenericsChecks.java 85.71% 0 Missing and 2 partials ⚠️
Additional details and impacted files
@@             Coverage Diff              @@
##             master    #2194      +/-   ##
============================================
- Coverage     89.58%   89.56%   -0.02%     
- Complexity     4031     4034       +3     
============================================
  Files           113      113              
  Lines         13208    13211       +3     
  Branches       2729     2731       +2     
============================================
+ Hits          11832    11833       +1     
  Misses          621      621              
- Partials        755      757       +2     

☔ 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 added a commit to vlsi/NullAway that referenced this pull request Nov 26, 2026
…ard is required

Previously, a `Box<T>` declared with `T extends @nullable Object` was accepted where a `Box<? extends Object>` was required, and a `Box<Object>` was accepted where a `Box<? super T>` with that `T` was required, so a null could reach a position that excludes one. The containment check judged a type argument by the annotation on its use site, which a bare type variable has none of, so every such assignment, argument, and return passed. No diagnostic marks the defect; the symptom is the missing error.

`CheckIdenticalNullabilityVisitor` now decides the top-level nullness of every wildcard containment check, for `? extends`, `?`, and `? super`, with the JSpecify nullness subtyping rules: a type is a nullness subtype of another where the supertype is null-inclusive, where the subtype is null-exclusive, or where the supertype is a type variable, not written `@NonNull`, that the subtype reaches through declared upper bounds none of which is nullable. A type variable is null-exclusive only through its bounds, so `T` with `T extends @nullable Object` fits neither `? extends Object` nor the lower bound of `? super T` from a `Box<Object>`, while `S` with `S extends T` still fits `? extends T` and `@Nullable T` does not. The path may pass through any element of an intersection, so a capture bounded by `T & @nullable Runnable` fits `? extends T`, and an intersection is null-exclusive where one of its written elements is, not counting the `Object` javac adds to an intersection of interfaces. A capture is judged by its upper bound, which carries the annotation written on the wildcard it captures. Each type usage carries one of the specification's nullness operators, read in the specification's lenient "some world" sense, and NullAway stays optimistic where a usage is `UNSPECIFIED`, for two stated reasons. A capture in the type of a generic method or diamond call that needs inference, used directly, in parentheses, or through a `var` local it initializes, comes from javac's types, whose captured bounds carry no type-use annotation, so a written `@NonNull` there cannot be read (apache#1585). A bare type variable actual against a wildcard on a type parameter whose declared bound is not nullable fits there exactly when it is a well-formed instantiation of that parameter, a check of its own (apache#1946), with the same answer for `?` and for `? extends Object`. A type variable declared in unannotated code admits null only where its bound is annotated `@Nullable` or a library model says so; whether a bound admits null is decided by the helper apache#1955 uses for inference. A rule written by hand for the type-variable case of `? extends` was tried first; every boundary with the rest of the checker needed an exception of its own, and the `? super` case was missed.

The override check adapts the overriding method's types to the overridden method's type parameters before comparing, as JLS 8.4.4 does, so a `Box<V>` returned over a `Box<? extends V>` is judged with one `V`; without the adaptation every such override would be reported. JLS 8.4.4 compares the signatures of methods with the same type parameters only, so where the nullness of a type parameter's bound differs, the bound mismatch is the one error reported.

NullAway infers neither a generic constructor called without a diamond nor a generic method reference outside a call needing inference, and a diamond call is inferred only with JSpecifyExperimental, so their type variables can reach the check uninstantiated, and judging them by their bounds would report valid code: `new Consumer(input)` with `<U extends @nullable Object> Consumer(Box<? extends U> input)` and a `Box<T>` whose `T` admits null, and `use(Test::singleton)` with `<U extends @nullable Object> List<U> singleton(U value)` and `use(Function<String, List<? extends Object>> f)`. While the arguments of a generic constructor call, or the types of such a reference, are checked, GenericsChecks passes the callee's type variables to the check with that comparison only, and the check compares a marked variable written without an annotation as master compares every type variable: only a type annotated `@Nullable` fails, against one not annotated `@Nullable`. So the check rejects every such call that master rejects, including `new Copier(listOfNullable, listOfNonNull)` with `<U extends @nullable Object> Copier(List<? extends U> source, List<? super U> target)`, which no single `U` satisfies. A type variable of a generic functional-interface method, and one in scope, is not marked. Reading a marked variable as unspecified wherever its bound admits null was rejected: each occurrence then takes its own nullness, and that `Copier` call passes. Inferring these uses was rejected too: with javac's instantiation it needs NestedTypeVarSubstitutionRepairVisitor to restore nested nullability in every argument shape javac drops it from, which full-type inference (apache#1585) replaces. A generic constructor called with explicit type arguments is compared the same way; substituting them is apache#2194.

Caller sees:
- `incompatible types: Box<T> cannot be converted to Box<? extends Object>` where `T`'s declared bound admits null, including a bound whose every intersection element is `@Nullable`; accepted before.
- `incompatible types: Box<Object> cannot be converted to Box<? super T>` where `T`'s declared bound admits null, and the same for a `Box<? super Object>`; accepted before.
- `incompatible types: Box<S> cannot be converted to Box<? extends T>` for `<S extends @nullable T>`, whatever `T`'s own bound, and `Box<T>` against `Box<? extends @nonnull T>` where `T`'s bound admits null; accepted before.
- `incompatible types` on `Box<? super @nullable T> sink = inferred` and `Box<? extends Object> source = inferred`, where `inferred` is a `Box<T>` that javac inferred as `T` for a generic call such as `id(box)` or `new ArrayList<>(list)`; the second was accepted before.
- `incompatible types: List<T> cannot be converted to Collection<? extends Object>` on `List<Object> copy = new ArrayList<>(in)` with a `List<T>` whose `T` admits null, since the target fixes the constructor's `E` to be non-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, such as Caffeine's `AsyncCacheLoader.bulk`; accepted before.
- `incompatible types: Box<capture of ? extends T> cannot be converted to Box<? extends Object>` on `return get();` with `get()` returning `Box<? extends T>` where `T`'s bound admits null, and `RunnableBox<capture of ? extends V> cannot be converted to RunnableBox<? extends Runnable>` for a capture bounded by `V & @nullable Runnable` against `? extends @nonnull Runnable`; accepted before.

Not changed:
- A type variable declared in unannotated code with no `@Nullable` on its bound and no library model is not reported.
- A capture in the inferred type of a generic call is not reported where its bound is bare: `return id(get());` passes where `return get();` is reported, because the inferred type cannot show a written `@NonNull`, as in Caffeine's `CacheLoader.asyncLoadAll` (apache#1585).
- A generic constructor called with explicit type arguments is compared as one without them, as on master (apache#2193).
- An invariant type argument is compared by annotation only, so `Box<? extends Object> x = idBox(box)` is accepted (apache#1945), and so is a `Box<@nonnull T>` where a `Box<T>` is required. A `Class<T>` still fits a `Class<?>` parameter.
- A generic constructor without a diamond and a generic method reference outside an inferred call still report `Box<@nullable String> cannot be converted to Box<? extends U>` where `U` admits null, and report nothing where a `Box<T>` whose `T` admits null meets a `U` that excludes it, as on master.

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

Previously, a `Box<T>` declared with `T extends @nullable Object` was accepted where a `Box<? extends Object>` was required, and a `Box<Object>` was accepted where a `Box<? super T>` with that `T` was required, so a null could reach a position that excludes one. The containment check judged a type argument by the annotation on its use site, which a bare type variable has none of, so every such assignment, argument, and return passed. No diagnostic marks the defect; the symptom is the missing error.

`CheckIdenticalNullabilityVisitor` now decides the top-level nullness of every wildcard containment check, for `? extends`, `?`, and `? super`, with the JSpecify nullness subtyping rules: a type is a nullness subtype of another where the supertype is null-inclusive, where the subtype is null-exclusive, or where the supertype is a type variable, not written `@NonNull`, that the subtype reaches through declared upper bounds none of which is nullable. A type variable is null-exclusive only through its bounds, so `T` with `T extends @nullable Object` fits neither `? extends Object` nor the lower bound of `? super T` from a `Box<Object>`, while `S` with `S extends T` still fits `? extends T` and `@Nullable T` does not. The path may pass through any element of an intersection, so a capture bounded by `T & @nullable Runnable` fits `? extends T`, and an intersection is null-exclusive where one of its written elements is, not counting the `Object` javac adds to an intersection of interfaces. A capture is judged by its upper bound, which carries the annotation written on the wildcard it captures. Each type usage carries one of the specification's nullness operators, read in the specification's lenient "some world" sense, and NullAway stays optimistic where a usage is `UNSPECIFIED`, for two stated reasons. A capture in the type of a generic method or diamond call that needs inference, used directly, in parentheses, or through a `var` local it initializes, comes from javac's types, whose captured bounds carry no type-use annotation, so a written `@NonNull` there cannot be read (apache#1585). A bare type variable actual against a wildcard on a type parameter whose declared bound is not nullable fits there exactly when it is a well-formed instantiation of that parameter, a check of its own (apache#1946), with the same answer for `?` and for `? extends Object`. A type variable declared in unannotated code admits null only where its bound is annotated `@Nullable` or a library model says so; whether a bound admits null is decided by the helper apache#1955 uses for inference. A rule written by hand for the type-variable case of `? extends` was tried first; every boundary with the rest of the checker needed an exception of its own, and the `? super` case was missed.

The override check adapts the overriding method's types to the overridden method's type parameters before comparing, as JLS 8.4.4 does, so a `Box<V>` returned over a `Box<? extends V>` is judged with one `V`; without the adaptation every such override would be reported. JLS 8.4.4 compares the signatures of methods with the same type parameters only, so where the nullness of a type parameter's bound differs, the bound mismatch is the one error reported.

NullAway infers neither a generic constructor called without a diamond nor a generic method reference outside a call needing inference, and a diamond call is inferred only with JSpecifyExperimental, so their type variables can reach the check uninstantiated, and judging them by their bounds would report valid code: `new Consumer(input)` with `<U extends @nullable Object> Consumer(Box<? extends U> input)` and a `Box<T>` whose `T` admits null, and `use(Test::singleton)` with `<U extends @nullable Object> List<U> singleton(U value)` and `use(Function<String, List<? extends Object>> f)`. While the arguments of a generic constructor call, or the types of such a reference, are checked, GenericsChecks passes the callee's type variables to the check with that comparison only, and the check compares a marked variable written without an annotation as master compares every type variable: only a type annotated `@Nullable` fails, against one not annotated `@Nullable`. So the check rejects every such call that master rejects, including `new Copier(listOfNullable, listOfNonNull)` with `<U extends @nullable Object> Copier(List<? extends U> source, List<? super U> target)`, which no single `U` satisfies. A type variable of a generic functional-interface method, and one in scope, is not marked. Reading a marked variable as unspecified wherever its bound admits null was rejected: each occurrence then takes its own nullness, and that `Copier` call passes. Inferring these uses was rejected too: with javac's instantiation it needs NestedTypeVarSubstitutionRepairVisitor to restore nested nullability in every argument shape javac drops it from, which full-type inference (apache#1585) replaces. A generic constructor called with explicit type arguments is compared the same way; substituting them is apache#2194.

Caller sees:
- `incompatible types: Box<T> cannot be converted to Box<? extends Object>` where `T`'s declared bound admits null, including a bound whose every intersection element is `@Nullable`; accepted before.
- `incompatible types: Box<Object> cannot be converted to Box<? super T>` where `T`'s declared bound admits null, and the same for a `Box<? super Object>`; accepted before.
- `incompatible types: Box<S> cannot be converted to Box<? extends T>` for `<S extends @nullable T>`, whatever `T`'s own bound, and `Box<T>` against `Box<? extends @nonnull T>` where `T`'s bound admits null; accepted before.
- `incompatible types` on `Box<? super @nullable T> sink = inferred` and `Box<? extends Object> source = inferred`, where `inferred` is a `Box<T>` that javac inferred as `T` for a generic call such as `id(box)` or `new ArrayList<>(list)`; the second was accepted before.
- `incompatible types: List<T> cannot be converted to Collection<? extends Object>` on `List<Object> copy = new ArrayList<>(in)` with a `List<T>` whose `T` admits null, since the target fixes the constructor's `E` to be non-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, such as Caffeine's `AsyncCacheLoader.bulk`; accepted before.
- `incompatible types: Box<capture of ? extends T> cannot be converted to Box<? extends Object>` on `return get();` with `get()` returning `Box<? extends T>` where `T`'s bound admits null, and `RunnableBox<capture of ? extends V> cannot be converted to RunnableBox<? extends Runnable>` for a capture bounded by `V & @nullable Runnable` against `? extends @nonnull Runnable`; accepted before.

Not changed:
- A type variable declared in unannotated code with no `@Nullable` on its bound and no library model is not reported.
- A capture in the inferred type of a generic call is not reported where its bound is bare: `return id(get());` passes where `return get();` is reported, because the inferred type cannot show a written `@NonNull`, as in Caffeine's `CacheLoader.asyncLoadAll` (apache#1585, apache#2195).
- A generic constructor called with explicit type arguments is compared as one without them, as on master (apache#2193).
- An invariant type argument is compared by annotation only, so `Box<? extends Object> x = idBox(box)` is accepted (apache#1945), and so is a `Box<@nonnull T>` where a `Box<T>` is required. A `Class<T>` still fits a `Class<?>` parameter.
- A generic constructor without a diamond and a generic method reference outside an inferred call still report `Box<@nullable String> cannot be converted to Box<? extends U>` where `U` admits null, and report nothing where a `Box<T>` whose `T` admits null meets a `U` that excludes it, as on master.

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

Previously, a `Box<T>` declared with `T extends @nullable Object` was accepted where a `Box<? extends Object>` was required, and a `Box<Object>` was accepted where a `Box<? super T>` with that `T` was required, so a null could reach a position that excludes one. The containment check judged a type argument by the annotation on its use site, which a bare type variable has none of, so every such assignment, argument, and return passed. No diagnostic marks the defect; the symptom is the missing error.

`CheckIdenticalNullabilityVisitor` now decides the top-level nullness of every wildcard containment check, for `? extends`, `?`, and `? super`, with the JSpecify nullness subtyping rules: a type is a nullness subtype of another where the supertype is null-inclusive, where the subtype is null-exclusive, or where the supertype is a type variable, not written `@NonNull`, that the subtype reaches through declared upper bounds none of which is nullable. A type variable is null-exclusive only through its bounds, so `T` with `T extends @nullable Object` fits neither `? extends Object` nor the lower bound of `? super T` from a `Box<Object>`, while `S` with `S extends T` still fits `? extends T` and `@Nullable T` does not. The path may pass through any element of an intersection, so a capture bounded by `T & @nullable Runnable` fits `? extends T`, and an intersection is null-exclusive where one of its written elements is, not counting the `Object` javac adds to an intersection of interfaces. A capture is judged by its upper bound, which carries the annotation written on the wildcard it captures. Each type usage carries one of the specification's nullness operators, read in the specification's lenient "some world" sense, and NullAway stays optimistic where a usage is `UNSPECIFIED`, for two stated reasons. A capture in the type of a generic method or diamond call that needs inference, used directly, in parentheses, or through a `var` local it initializes, comes from javac's types, whose captured bounds carry no type-use annotation, so a written `@NonNull` there cannot be read (apache#1585). A bare type variable actual against a wildcard on a type parameter whose declared bound is not nullable fits there exactly when it is a well-formed instantiation of that parameter, a check of its own (apache#1946), with the same answer for `?` and for `? extends Object`. A type variable declared in unannotated code admits null only where its bound is annotated `@Nullable` or a library model says so; whether a bound admits null is decided by the helper apache#1955 uses for inference. A rule written by hand for the type-variable case of `? extends` was tried first; every boundary with the rest of the checker needed an exception of its own, and the `? super` case was missed.

The override check adapts the overriding method's types to the overridden method's type parameters before comparing, as JLS 8.4.4 does, so a `Box<V>` returned over a `Box<? extends V>` is judged with one `V`; without the adaptation every such override would be reported. JLS 8.4.4 compares the signatures of methods with the same type parameters only, so where the nullness of a type parameter's bound differs, the bound mismatch is the one error reported.

NullAway infers neither a generic constructor called without a diamond nor a generic method reference outside a call needing inference, and a diamond call is inferred only with JSpecifyExperimental, so their type variables can reach the check uninstantiated, and judging them by their bounds would report valid code: `new Consumer(input)` with `<U extends @nullable Object> Consumer(Box<? extends U> input)` and a `Box<T>` whose `T` admits null, and `use(Test::singleton)` with `<U extends @nullable Object> List<U> singleton(U value)` and `use(Function<String, List<? extends Object>> f)`. While the arguments of a generic constructor call, or the types of such a reference, are checked, GenericsChecks passes the callee's type variables to the check with that comparison only, and the check compares a marked variable written without an annotation as master compares every type variable: only a type annotated `@Nullable` fails, against one not annotated `@Nullable`. So the check rejects every such call that master rejects, including `new Copier(listOfNullable, listOfNonNull)` with `<U extends @nullable Object> Copier(List<? extends U> source, List<? super U> target)`, which no single `U` satisfies. A type variable of a generic functional-interface method, and one in scope, is not marked. Reading a marked variable as unspecified wherever its bound admits null was rejected: each occurrence then takes its own nullness, and that `Copier` call passes. Inferring these uses was rejected too: with javac's instantiation it needs NestedTypeVarSubstitutionRepairVisitor to restore nested nullability in every argument shape javac drops it from, which full-type inference (apache#1585) replaces. A generic constructor called with explicit type arguments is compared the same way; substituting them is apache#2194.

Caller sees:
- `incompatible types: Box<T> cannot be converted to Box<? extends Object>` where `T`'s declared bound admits null, including a bound whose every intersection element is `@Nullable`; accepted before.
- `incompatible types: Box<Object> cannot be converted to Box<? super T>` where `T`'s declared bound admits null, and the same for a `Box<? super Object>`; accepted before.
- `incompatible types: Box<S> cannot be converted to Box<? extends T>` for `<S extends @nullable T>`, whatever `T`'s own bound, and `Box<T>` against `Box<? extends @nonnull T>` where `T`'s bound admits null; accepted before.
- `incompatible types` on `Box<? super @nullable T> sink = inferred` and `Box<? extends Object> source = inferred`, where `inferred` is a `Box<T>` that javac inferred as `T` for a generic call such as `id(box)` or `new ArrayList<>(list)`; the second was accepted before.
- `incompatible types: List<T> cannot be converted to Collection<? extends Object>` on `List<Object> copy = new ArrayList<>(in)` with a `List<T>` whose `T` admits null, since the target fixes the constructor's `E` to be non-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, such as Caffeine's `AsyncCacheLoader.bulk`; accepted before.
- `incompatible types: Box<capture of ? extends T> cannot be converted to Box<? extends Object>` on `return get();` with `get()` returning `Box<? extends T>` where `T`'s bound admits null, and `RunnableBox<capture of ? extends V> cannot be converted to RunnableBox<? extends Runnable>` for a capture bounded by `V & @nullable Runnable` against `? extends @nonnull Runnable`; accepted before.

Not changed:
- A type variable declared in unannotated code with no `@Nullable` on its bound and no library model is not reported.
- A capture in the inferred type of a generic call is not reported where its bound is bare: `return id(get());` passes where `return get();` is reported, because the inferred type cannot show a written `@NonNull`, as in Caffeine's `CacheLoader.asyncLoadAll` (apache#1585, apache#2195).
- A generic constructor called with explicit type arguments is compared as one without them, as on master (apache#2193).
- An invariant type argument is compared by annotation only, so `Box<? extends Object> x = idBox(box)` is accepted (apache#1945), and so is a `Box<@nonnull T>` where a `Box<T>` is required. A `Class<T>` still fits a `Class<?>` parameter.
- A generic constructor without a diamond and a generic method reference outside an inferred call still report `Box<@nullable String> cannot be converted to Box<? extends U>` where `U` admits null, and report nothing where a `Box<T>` whose `T` admits null meets a `U` that excludes it, as on master.

Assisted-by: Claude Code (claude-fable-5-1)
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.

JSpecify mode: explicit type arguments of a generic constructor call are ignored

1 participant