Skip to content

More TreePath hardening - #1684

Merged
msridhar merged 4 commits into
masterfrom
more-treepath-hardening
Aug 8, 2026
Merged

More TreePath hardening#1684
msridhar merged 4 commits into
masterfrom
more-treepath-hardening

Conversation

@msridhar

@msridhar msridhar commented Aug 7, 2026

Copy link
Copy Markdown
Collaborator

For step 3 of #1680 (comment)

We modify the global VisitorState stored in AccessPathNullnessPropagation such that any use of its TreePath causes an immediate failure at runtime, via the new class FailingTreePath. This exposed an issue in the EnsuresNonNullIfHandler where this tree path was being used to check suppressions on return trees. Now, we store correct paths for those return trees and use those instead. This allows us to remove the VisitorState parameter from onDataflowVisitReturn entirely.

Summary by CodeRabbit

  • Bug Fixes

    • Improved path-aware nullness analysis for return statements and method invocations.
    • Prevented invalid path access during dataflow processing.
    • Improved validation of @EnsuresNonNullIf contracts across control-flow paths and source locations.
  • Behavior

    • Invalid @EnsuresNonNullIf diagnostics can now be suppressed with @SuppressWarnings("NullAway").
  • Tests

    • Added coverage for suppressing diagnostics from invalid conditional nullness contracts.

@msridhar

msridhar commented Aug 7, 2026

Copy link
Copy Markdown
Collaborator Author

This change is part of the following stack:

Change managed by git-spice.

@msridhar
msridhar marked this pull request as ready for review August 7, 2026 20:10
@msridhar
msridhar requested a review from yuxincs August 7, 2026 20:11
@coderabbitai

coderabbitai Bot commented Aug 7, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

Walkthrough

The change guards the shared VisitorState path with FailingTreePath. Method-invocation callbacks receive invocation-specific path state. Return callbacks no longer receive VisitorState. EnsuresNonNullIfHandler stores return paths and reconstructs path-specific state during validation. A suppression test covers invalid contracts.

Possibly related PRs

  • uber/NullAway#1681: Both changes update AccessPathNullnessPropagation with path-aware VisitorState handling.
  • uber/NullAway#1683: Both changes propagate explicit TreePath context for path-sensitive analysis.
  • uber/NullAway#1328: Both changes introduce explicit TreePath propagation in dataflow nullness analysis.

Suggested reviewers: yuxincs

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly and concisely describes the main TreePath hardening changes in the pull request.
✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch more-treepath-hardening

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

Comment @coderabbitai help to get the list of available commands.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In
`@nullaway/src/main/java/com/uber/nullaway/handlers/contract/fieldcontract/EnsuresNonNullIfHandler.java`:
- Around line 123-124: Add Javadoc to the private method
buildUpReturnToEnclosingMethodMap, documenting that it records only return
statements directly enclosed by the method currently under validation. Keep the
documentation focused on this method’s behavior and retain the existing
implementation unchanged.
🪄 Autofix

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: ASSERTIVE

Plan: Pro Plus

Run ID: 676db359-cc96-452f-b7bc-b13d74b879ea

📥 Commits

Reviewing files that changed from the base of the PR and between 9b2b56b and 59da766.

📒 Files selected for processing (6)
  • nullaway/src/main/java/com/uber/nullaway/dataflow/AccessPathNullnessPropagation.java
  • nullaway/src/main/java/com/uber/nullaway/handlers/CompositeHandler.java
  • nullaway/src/main/java/com/uber/nullaway/handlers/Handler.java
  • nullaway/src/main/java/com/uber/nullaway/handlers/StreamNullabilityPropagator.java
  • nullaway/src/main/java/com/uber/nullaway/handlers/contract/fieldcontract/EnsuresNonNullIfHandler.java
  • nullaway/src/test/java/com/uber/nullaway/EnsuresNonNullIfTests.java

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
nullaway/src/main/java/com/uber/nullaway/handlers/contract/fieldcontract/EnsuresNonNullIfHandler.java (1)

164-177: 📐 Maintainability & Code Quality | 🟠 Major | ⚡ Quick win

Add Javadoc for onDataflowVisitReturn.

This non-trivial method now performs path-specific return validation. Document its handling of tracked returns and nested lambdas or anonymous classes.

As per coding guidelines, **/src/main/**/*.java requires Javadoc for every non-trivial method, including private methods.

Proposed Javadoc
+  /**
+   * Validates each directly enclosed return using its path-specific visitor state.
+   * Returns inside nested lambdas and anonymous classes are ignored.
+   */
   `@Override`
   public void onDataflowVisitReturn(
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In
`@nullaway/src/main/java/com/uber/nullaway/handlers/contract/fieldcontract/EnsuresNonNullIfHandler.java`
around lines 164 - 177, Add Javadoc directly above onDataflowVisitReturn
describing that it validates tracked return statements using the path-specific
dataflow context and ignores returns outside the method under analysis,
including returns nested in lambdas or anonymous classes.

Source: Coding guidelines

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Outside diff comments:
In
`@nullaway/src/main/java/com/uber/nullaway/handlers/contract/fieldcontract/EnsuresNonNullIfHandler.java`:
- Around line 164-177: Add Javadoc directly above onDataflowVisitReturn
describing that it validates tracked return statements using the path-specific
dataflow context and ignores returns outside the method under analysis,
including returns nested in lambdas or anonymous classes.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: ASSERTIVE

Plan: Pro Plus

Run ID: 76b8638d-7669-44a3-9035-d6ebbcba0263

📥 Commits

Reviewing files that changed from the base of the PR and between 59da766 and 28a7e68.

📒 Files selected for processing (1)
  • nullaway/src/main/java/com/uber/nullaway/handlers/contract/fieldcontract/EnsuresNonNullIfHandler.java

@codecov

codecov Bot commented Aug 7, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 87.77%. Comparing base (73d8de0) to head (389ce9b).

Additional details and impacted files
@@            Coverage Diff            @@
##             master    #1684   +/-   ##
=========================================
  Coverage     87.77%   87.77%           
  Complexity     3143     3143           
=========================================
  Files           109      109           
  Lines         10608    10613    +5     
  Branches       2151     2152    +1     
=========================================
+ Hits           9311     9316    +5     
  Misses          611      611           
  Partials        686      686           

☔ 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.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
nullaway/src/main/java/com/uber/nullaway/dataflow/AccessPathNullnessPropagation.java (1)

224-225: 📐 Maintainability & Code Quality | 🟠 Major | ⚡ Quick win

Add Javadoc for the changed non-trivial methods.

Document the constructor’s guarded VisitorState invariant and the path-specific state passed to method-invocation handlers.

Suggested Javadocs
+  /**
+   * Creates a propagation transfer function with a guarded global {`@link` VisitorState}.
+   *
+   * <p>Path-sensitive callbacks must provide an explicit path.
+   */
   public AccessPathNullnessPropagation(

+  /**
+   * Visits a method invocation and applies its nullness updates.
+   *
+   * <p>Handlers receive a {`@link` VisitorState} rooted at the invocation tree.
+   */
   `@Override`
   public TransferResult<Nullness, NullnessStore> visitMethodInvocation(

As per coding guidelines, **/src/main/**/*.java requires Javadoc for every non-trivial method, including private methods.

Also applies to: 1095-1102

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In
`@nullaway/src/main/java/com/uber/nullaway/dataflow/AccessPathNullnessPropagation.java`
around lines 224 - 225, Add Javadoc to the changed non-trivial methods in
AccessPathNullnessPropagation, including the constructor and the
method-invocation handlers around the affected state updates. Document the
constructor’s guarded VisitorState invariant and clarify that invocation
handlers receive path-specific state, while preserving the existing behavior and
signatures.

Source: Coding guidelines

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Outside diff comments:
In
`@nullaway/src/main/java/com/uber/nullaway/dataflow/AccessPathNullnessPropagation.java`:
- Around line 224-225: Add Javadoc to the changed non-trivial methods in
AccessPathNullnessPropagation, including the constructor and the
method-invocation handlers around the affected state updates. Document the
constructor’s guarded VisitorState invariant and clarify that invocation
handlers receive path-specific state, while preserving the existing behavior and
signatures.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: ASSERTIVE

Plan: Pro Plus

Run ID: 011967af-20e1-4ec5-8012-af591314a175

📥 Commits

Reviewing files that changed from the base of the PR and between 28a7e68 and 11f35e7.

📒 Files selected for processing (1)
  • nullaway/src/main/java/com/uber/nullaway/dataflow/AccessPathNullnessPropagation.java

@msridhar
msridhar force-pushed the preserve-paths-through-nested-type-repair branch from 9b2b56b to d0a83c4 Compare August 7, 2026 22:51
@msridhar
msridhar force-pushed the more-treepath-hardening branch from 11f35e7 to 23b21c2 Compare August 7, 2026 22:51
@msridhar
msridhar force-pushed the preserve-paths-through-nested-type-repair branch from d0a83c4 to 6fc043b Compare August 7, 2026 23:46
@msridhar
msridhar force-pushed the more-treepath-hardening branch from 23b21c2 to d681267 Compare August 7, 2026 23:46
Base automatically changed from preserve-paths-through-nested-type-repair to master August 8, 2026 02:20
@msridhar
msridhar force-pushed the more-treepath-hardening branch from d681267 to 389ce9b Compare August 8, 2026 02:54
@msridhar
msridhar enabled auto-merge (squash) August 8, 2026 02:55
@msridhar
msridhar merged commit e708b2c into master Aug 8, 2026
14 checks passed
@msridhar
msridhar deleted the more-treepath-hardening branch August 8, 2026 03:10
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.

2 participants