Dark Mode

Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Fix to handling of case null#1235

Merged
msridhar merged 5 commits intomasterfrom
issue-1233
Aug 4, 2025
Merged

Fix to handling of case null#1235
msridhar merged 5 commits intomasterfrom
issue-1233

Conversation

Copy link
Collaborator

msridhar commented Jul 30, 2025 *
edited by coderabbitai bot
Loading

Fixes #1233. Our handling of case null didn't actually check it was only operating for a null literal in the case, so it was getting applied too broadly.

Summary by CodeRabbit

  • Tests

    • Added a new test to verify handling of null and string cases in switch expressions with type refinement and nullness annotations.
  • Bug Fixes

    • Enhanced nullness propagation accuracy in switch-case expressions by supplying explicit nullness information for the case operand.

bannmann reacted with hooray emoji
msridhar added 2 commits July 29, 2025 14:15
Copy link
Contributor

coderabbitai bot commented Jul 30, 2025 *
edited
Loading

Walkthrough

A new unit test was added to verify correct handling of case null in switch expressions with type refinement and nullness annotations. The nullness propagation logic in AccessPathNullnessPropagation was updated to accept explicit nullness information for the left operand in equality comparisons, improving precision in nullness tracking during switch-case evaluation.

Changes

Cohort / File(s) Change Summary
Unit Test Addition
jdk-recent-unit-tests/src/test/java/com/uber/nullaway/jdk17/SwitchTests.java
Added a test method caseNullTypeRefinement to verify correct null handling in switch expressions with nullness annotations.
Nullness Propagation Logic
nullaway/src/main/java/com/uber/nullaway/dataflow/AccessPathNullnessPropagation.java
Extended handleEqualityComparison to accept explicit left operand nullness; updated visitCase to pass switch operand nullness to improve nullness propagation precision.

Sequence Diagram(s)

sequenceDiagram
participant TestRunner
participant NullAway
participant SourceCode

TestRunner->>NullAway: Run caseNullTypeRefinement test
NullAway->>SourceCode: Analyze switch expression with case null
NullAway->>NullAway: Use explicit nullness for switch operand in equality comparison
NullAway-->>TestRunner: Report analysis result (no false positive for default case)
Loading

Estimated code review effort

2 (Simple) | ~8 minutes

Assessment against linked issues

Objective Addressed Explanation
Correctly handle case null in switch expressions for nullness analysis (#1233)
Avoid false positive nullability warnings in default case when case null is present (#1233)

Assessment against linked issues: Out-of-scope changes

No out-of-scope changes found.

Note

Unit Test Generation is now available in beta!

Learn more here, or try it out under "Finishing Touches" below.


Recent review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

Commits

Reviewing files that changed from the base of the PR and between 54a4cda and 8694a54.

Files selected for processing (1)
  • nullaway/src/main/java/com/uber/nullaway/dataflow/AccessPathNullnessPropagation.java (3 hunks)
Additional context used
Code Graph Analysis (1)
nullaway/src/main/java/com/uber/nullaway/dataflow/AccessPathNullnessPropagation.java (1)
nullaway/src/main/java/com/uber/nullaway/dataflow/AccessPath.java (1)
  • AccessPath (78-797)
Additional comments (3)
nullaway/src/main/java/com/uber/nullaway/dataflow/AccessPathNullnessPropagation.java (3)

414-414: LGTM! Consistent API usage for equality comparisons.

The changes correctly pass null as the third parameter to handleEqualityComparison in both visitEqualTo and visitNotEqual, indicating that the left operand is a subnode and its nullness will be obtained from the input values.

Also applies to: 421-421


429-430: Well-designed API extension for explicit nullness propagation.

The addition of the nullable leftOperandNullness parameter is a clean solution that maintains backward compatibility while enabling more precise nullness tracking. The implementation correctly prioritizes the explicitly provided nullness over the subnode lookup.

Also applies to: 439-439, 445-446


972-979: Correct implementation of nullness refinement for switch cases.

This change properly addresses issue #1233 by explicitly retrieving and propagating the nullness of the switch operand during case evaluation. By passing the switch operand's nullness to handleEqualityComparison, the analysis can now correctly refine the nullness state in different switch branches, preventing false positive null dereference warnings after a case null.

The implementation correctly handles the case where no access path exists for the switch operand by passing null and letting handleEqualityComparison fall back to its default behavior.

Finishing Touches
  • Generate Docstrings
Generate unit tests
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch issue-1233

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
Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit , please review it.
    • Explain this complex logic.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai explain this code block.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and explain its main purpose.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @coderabbitai generate unit tests to generate unit tests for this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

msridhar requested a review from yuxincs July 30, 2025 04:08
msridhar added 2 commits July 30, 2025 08:42
Copy link

codecov bot commented Jul 30, 2025 *
edited
Loading

Codecov Report

Patch coverage is 77.77778% with 2 lines in your changes missing coverage. Please review.
Project coverage is 88.44%. Comparing base (d655f8f) to head (e326912).
Report is 1 commits behind head on master.

Files with missing lines Patch % Lines
...llaway/dataflow/AccessPathNullnessPropagation.java 77.77% 1 Missing and 1 partial
Additional details and impacted files
@@ Coverage Diff @@
## master #1235 +/- ##
============================================
- Coverage 88.45% 88.44% -0.02%
- Complexity 2372 2373 +1
============================================
Files 90 90
Lines 7781 7786 +5
Branches 1553 1555 +2
============================================
+ Hits 6883 6886 +3
- Misses 452 453 +1
- Partials 446 447 +1

View full report in Codecov by Sentry.
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.

yuxincs approved these changes Aug 4, 2025
msridhar enabled auto-merge (squash) August 4, 2025 14:20
msridhar merged commit ee85996 into master Aug 4, 2025
11 of 13 checks passed
msridhar deleted the issue-1233 branch August 4, 2025 14:30
haewiful pushed a commit to haewiful/NullAway01 that referenced this pull request Aug 9, 2025
coderabbitai bot mentioned this pull request Aug 29, 2025
coderabbitai bot mentioned this pull request Dec 24, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

yuxincs yuxincs approved these changes

Assignees

No one assigned

Labels

None yet

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

case null of switch expression is not considered

2 participants