Skip to content

Add more modeling for Optional - #1613

Merged
msridhar merged 7 commits into
masterfrom
optional-model
Jun 26, 2026
Merged

msridhar merged 7 commits into
masterfrom
optional-model

Conversation

@msridhar

@msridhar msridhar commented Jun 18, 2026 •

Copy link
Copy Markdown
Contributor

Fixes #1611

We manually write more models for Optional, so we can address before fully fixing #950. Note that we do not model orElseGet as in JSpecify JDK right now due to false positives; see #1616.

Summary by CodeRabbit

Summary by CodeRabbit

  • Bug Fixes

    • Improved null-safety handling for java.util.Optional, including more accurate nullability propagation and diagnostics for ofNullable, map, orElse, equals, and filter.
  • Tests

    • Expanded JUnit coverage for Optional with jspecify nullability, adding new positive and negative compilation assertions, with one scenario temporarily skipped pending a tracked issue.

@msridhar

msridhar commented Jun 18, 2026 •

Copy link
Copy Markdown
Contributor Author

@coderabbitai

coderabbitai Bot commented Jun 18, 2026 •

Copy link
Copy Markdown
Contributor

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: ASSERTIVE

Plan: Pro

Run ID: 79db892e-25f0-4ec9-be94-aa5a7eef1c24

📥 Commits

Reviewing files that changed from the base of the PR and between e30cbfd and 23f2fb0.

📒 Files selected for processing (1)
  • nullaway/src/main/java/com/uber/nullaway/handlers/LibraryModelsHandler.java
💤 Files with no reviewable changes (1)
  • nullaway/src/main/java/com/uber/nullaway/handlers/LibraryModelsHandler.java

Walkthrough

LibraryModelsHandler.java updates java.util.Optional nullability modeling for explicit nullable parameters, always-nullable orElse returns, nested annotation propagation for map, and NULLMARKED_CLASSES. JSpecifyLibraryModelsTests.java adds embedded-source compilation tests for these Optional behaviors, including nullable inputs, nullable mapper results, or(...), filter(...), and an ignored orElseGet(() -> null) case.

Possibly related PRs

  • uber/NullAway#1298: Modifies LibraryModelsHandler.DefaultLibraryModels nullability tables for a JDK type, similar to the library-model changes here.

Suggested reviewers

  • yuxincs
  • lazaroclapp
🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title is concise and accurately describes the main change: expanded Optional modeling.
Linked Issues check ✅ Passed The changes add Optional modeling and tests that address the reported JSpecify false positive around Optional.or for #1611.
Out of Scope Changes check ✅ Passed The added Optional models and test coverage remain within the scope of improving Optional nullability behavior.
✨ 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 optional-model

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.

@codecov

codecov Bot commented Jun 18, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 88.10%. Comparing base (98096d7) to head (23f2fb0).
⚠️ Report is 1 commits behind head on master.

Additional details and impacted files
@@             Coverage Diff              @@
##             master    #1613      +/-   ##
============================================
+ Coverage     88.09%   88.10%   +0.01%     
  Complexity     3046     3046              
============================================
  Files           105      105              
  Lines         10170    10181      +11     
  Branches       2062     2062              
============================================
+ Hits           8959     8970      +11     
  Misses          572      572              
  Partials        639      639              

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

@msridhar
msridhar changed the base branch from master to library-model-lambda-issue June 19, 2026 18:32
@msridhar
msridhar changed the base branch from library-model-lambda-issue to lib-model-wildcard-crash June 19, 2026 20:54
@msridhar msridhar changed the title [draft] Add more modeling for Optional Add more modeling for Optional Jun 19, 2026
@msridhar
msridhar requested a review from lazaroclapp June 19, 2026 21:42

@lazaroclapp lazaroclapp 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.

👍

@msridhar
msridhar force-pushed the lib-model-wildcard-crash branch from 1bec1d8 to 5155f0b Compare June 24, 2026 22:03
@msridhar
msridhar force-pushed the lib-model-wildcard-crash branch from 5155f0b to 16f54dc Compare June 24, 2026 22:18
@msridhar
msridhar force-pushed the optional-model branch 3 times, most recently from 4235633 to a347dc6 Compare June 24, 2026 22:22
@msridhar
msridhar force-pushed the lib-model-wildcard-crash branch from 3f7be7e to 15ac4a4 Compare June 26, 2026 01:49
@msridhar
msridhar force-pushed the lib-model-wildcard-crash branch from 15ac4a4 to 811606b Compare June 26, 2026 02:21
msridhar added a commit that referenced this pull request Jun 26, 2026
Observed when running #1613 on Spring Framework. If have a class
`Box<T>` with a method method `foo(T)` with a library model making it
`foo(@nullable T)`, and a call site invoking `foo` on a `Box<?>`, we
could crash trying to put an invalid `@Nullable` on the wildcard.
Instead, we can just not substitute in the `@Nullable` annotation; our
existing wildcard checking logic should handle the `@Nullable` on the
formal correctly for this case.
Base automatically changed from lib-model-wildcard-crash to master June 26, 2026 02:36
@msridhar
msridhar enabled auto-merge (squash) June 26, 2026 16:37
@msridhar
msridhar merged commit f40a9fa into master Jun 26, 2026
7 of 8 checks passed
@msridhar
msridhar deleted the optional-model branch June 26, 2026 16:49
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.

False positive with Optional.or method and JSpecify

2 participants