Skip to content

Document null-probing semantic differences in singleton migrations#1081

Merged
timtebeek merged 1 commit intomainfrom
tim/issue-1079
May 4, 2026
Merged

Document null-probing semantic differences in singleton migrations#1081
timtebeek merged 1 commit intomainfrom
tim/issue-1079

Conversation

@timtebeek
Copy link
Copy Markdown
Member

@timtebeek timtebeek commented May 4, 2026

List.of(..), Set.of(..), and Map.of(..) throw NullPointerException when probed with contains(null) and friends, whereas the Collections.singleton* factories return false/-1/null. The semantic difference is undecidable across method boundaries (the reporter's case has the probe happen in downstream code), so rather than make the rewrite conditional, this PR calls out the divergence in each recipe description so users can decide whether the migration is safe for their code.

Also fixes a Set.OfSet.of typo in the MigrateCollectionsSingletonSet description.

`List.of(..)`, `Set.of(..)`, and `Map.of(..)` throw `NullPointerException`
when probed with `contains(null)` and friends, whereas the
`Collections.singleton*` factories return `false`/`-1`/`null`. Call this
out in each recipe description so users can decide whether the migration
is safe for their code. Also fixes a `Set.Of` typo.
@github-project-automation github-project-automation Bot moved this to In Progress in OpenRewrite May 4, 2026
@timtebeek timtebeek merged commit b6c609d into main May 4, 2026
1 check passed
@timtebeek timtebeek deleted the tim/issue-1079 branch May 4, 2026 18:55
@github-project-automation github-project-automation Bot moved this from In Progress to Done in OpenRewrite May 4, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

MigrateCollectionsSingletonList changes contains(null) semantics

1 participant