Preserve nullable effective upper bound when reading generic fields through wildcards #1911
All Vouch review confidence checks passed
Residual risk 0.22 = Change Risk (0.42) × (1 − Review Confidence (0.47)).
Review depth and reviewer attention state are adequate.
Model 1 · Change Risk (XGBoost)
Score: 0.42 · 326 lines diff across 4 files
Model 2 · Review Depth (DistilBERT)
Depth Score: 0.02 · 1 substantive comment(s)
Model 3 · Review Timing & Attention
Session adequacy: 100% · Reviewer familiarity: 35%
Bedrock Claude 3 · Risk Narration
(disconnected)
Groq Risk Narration
AWS Bedrock is currently disconnected. Generate high-confidence PR triage narration on-demand using Groq.
Model 1 · Change Risk Attribution
SHAP Weights
Diff Size
diff_size
0.346
Shallow Review Depth
shallow_review_depth
0.344
Real PR Conversation Timeline
1 comments
"Review active on #1911"
general
weight: 0.35
arnabnandy7
Summary
In JSpecify mode, reading a generic field whose declared type is a type variable through a
? superwildcard receiver yields the wildcard's effective upper bound. When that type parameter has a nullable upper bound (e.g.T extends @Nullable Comparable<Integer>), the effective read type is@Nullable Comparable<Integer>.Previously, NullAway restored field annotations in
GenericsChecks.getTreeTypefrom the un-substituted declared field symbol (T) and did not evaluate generic substitutions for field expressions inmayBeNullExpror dataflow analysis (visitFieldAccess). As a result, reading the field throughNode<? super Integer>was silently treated as non-null.Changes
GenericsChecks.getTreeType, resolve field access types taking receiver type arguments and wildcards into account, restoring annotations from the effective wildcard upper bound when the resolved field type is a wildcard.getGenericFieldAccessNullnessandgetGenericFieldNullnesstoGenericsChecksto evaluate generic field nullness viagetTypeNullnessForRead.mayBeNullFieldtoNullAwayto evaluate top-level nullness for field accesses whose declared type is a type variable in JSpecify mode.genericFieldIsNullabletoAccessPathNullnessPropagation.visitFieldAccessto ensure dataflow models generic field reads with nullable substituted bounds as nullable while preserving non-null refinement after null-checks.WildcardTestsfor #1854 verifying passing to non-null parameters, dereferences, and null-check refinements.Fixes #1854
- [x] A description about what and why you are contributing, even if it's trivial.
- [x] The issue number(s) or PR number(s) in the description if you are contributing in response to those.
- [x] If applicable, unit tests.
Note on AI usage
NA
<!-- This is an auto-generated comment: release notes by coderabbit.ai -->
Summary by CodeRabbit
Bug Fixes
Improved nullability checks for fields whose types depend on generic type parameters, including fields accessed through wildcard types.
NullAway now reports potentially unsafe field use when the receiver’s type indicates the field may be nullable, while allowing use after a null check.
Field accesses in unannotated code and fields without nullable types continue to be treated as non-null.
* Nullable field reads through method-call receivers are also checked according to the receiver’s generic type.
<!-- end of auto-generated comment: release notes by coderabbit.ai -->