Skip to content

Conversation

ZzetT
Copy link
Contributor

@ZzetT ZzetT commented Jun 20, 2025

What's changed?

The rule org.openrewrite.java.migrate.util.MigrateCollectionsSingletonMap also migrated the following cases:

Collections.singletonMap(null, "foo")
Collections.singletonMap("bar", null)

to

Map.of(null, "foo")
Map.of("bar", null)

which leads to a NullPointerException

What's your motivation?

There is a closed issue #571 where it was even mentioned in the comments to apply the same to maps, but the changes were not done in the previous PR.

Checklist

  • I've added unit tests to cover both positive and negative cases
  • I've read and applied the recipe conventions and best practices
  • I've used the IntelliJ IDEA auto-formatter on affected files

@github-project-automation github-project-automation bot moved this to In Progress in OpenRewrite Jun 20, 2025
Copy link
Member

@timtebeek timtebeek left a comment

Choose a reason for hiding this comment

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

Thanks for taking this on @ZzetT ! I've applied a small polish for a recent addition; if you recall where you copied that pattern from we can do the same there.

@github-project-automation github-project-automation bot moved this from In Progress to Ready to Review in OpenRewrite Jun 20, 2025
@timtebeek timtebeek merged commit 9c36dc1 into openrewrite:main Jun 20, 2025
@github-project-automation github-project-automation bot moved this from Ready to Review to Done in OpenRewrite Jun 20, 2025
@ZzetT
Copy link
Contributor Author

ZzetT commented Jun 20, 2025

Thanks @timtebeek for the review and the quick merge.
I just wanted to add that we could applied your pattern also to MigrateCollectionsSingletonList and MigrateCollectionsSingletonSet, but I was a few seconds to late with my commit ;)

@timtebeek
Copy link
Member

All good, thanks! I've applied those with a recipe, and that'll be in our PR checks going forward. :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Archived in project

Development

Successfully merging this pull request may close these issues.

2 participants