← Back to Pull requests

Preserve nullable effective upper bound when reading generic fields through wildcards #1911

Open
unknown opened this pull request with 326 lines diff across 4 files
View on GitHub
unknown unknown commented on Oct 03, 2026 13:10 UTC
Author

Summary

In JSpecify mode, reading a generic field whose declared type is a type variable through a ? super wildcard 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.getTreeType from the un-substituted declared field symbol (T) and did not evaluate generic substitutions for field expressions in mayBeNullExpr or dataflow analysis (visitFieldAccess). As a result, reading the field through Node<? super Integer> was silently treated as non-null.

Changes

  • In 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.

  • Added getGenericFieldAccessNullness and getGenericFieldNullness to GenericsChecks to evaluate generic field nullness via getTypeNullnessForRead.

  • Added mayBeNullField to NullAway to evaluate top-level nullness for field accesses whose declared type is a type variable in JSpecify mode.

  • Added genericFieldIsNullable to AccessPathNullnessPropagation.visitFieldAccess to ensure dataflow models generic field reads with nullable substituted bounds as nullable while preserving non-null refinement after null-checks.

  • Added regression coverage in WildcardTests for #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 -->

    Diff: 326 lines (+244 / -82) across 4 files Reviewer: arnabnandy7 Review duration: 17768m
    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
    0.42
    Model 2 · Review Depth (DistilBERT)
    Depth Score: 0.02 · 1 substantive comment(s)
    0.02
    Model 3 · Review Timing & Attention
    Session adequacy: 100% · Reviewer familiarity: 35%
    46%
    Bedrock Claude 3 · Risk Narration
    (disconnected)
    Groq
    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
    Reviewers
    Assignees
    Unassigned
    Labels
    risk: low confidence: 46.7% reviewed
    Vouch Risk Breakdown
    AI-powered review risk analysis
    Change Risk
    Change Risk · Model 1 (XGBoost)
    Predicted defect probability (0.00–1.00) based on diff churn, modified sensitive files, and author risk history.
    Score: 42% (MEDIUM) · Higher = larger blast radius
    42%
    Review Confidence
    Review Confidence · Models 2 & 3
    Scrutiny score (0.00–1.00) combining DistilBERT semantic review depth with reviewer familiarity and session dwell time.
    Score: 46.7% · Lower = rushed or shallow review
    46.7%
    Residual Risk
    Residual Risk · Core Equation
    Residual = Change × (1 − Confidence)
    Unmitigated risk surviving review. ≥ 0.65 triggers an automated re-queue to protect production.
    Score: 22.4% · Safe to merge
    22.4%
    Repository