Preserve Set.of immutability in UseEnumSetOf - #1205
Open
martinfrancois wants to merge 3 commits into
Open
Conversation
Merged
4 tasks
martinfrancois
force-pushed
the
agent/repro-use-enum-set-immutability
branch
from
August 15, 2026 20:26
0d094f8 to
7739d31
Compare
martinfrancois
force-pushed
the
agent/repro-use-enum-set-immutability
branch
from
August 16, 2026 02:53
7739d31 to
5b984a3
Compare
martinfrancois
marked this pull request as ready for review
August 17, 2026 08:08
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Suggested review order: 7 of 52 (Score: 8)
Review first: openrewrite/rewrite#8447
What's changed?
Wraps generated
EnumSetvalues withCollections.unmodifiableSet(...)soUseEnumSetOfpreserves the mutation contract ofSet.of(...). When source names prevent both safe spellings ofCollections, the recipe leaves the original expression unchanged.What's your motivation?
Recipe:
org.openrewrite.java.migrate.util.UseEnumSetOf.I found this by running
org.openrewrite.java.migrate.util.UseEnumSetOffromorg.openrewrite.recipe:rewrite-migrate-java:3.40.0onWorkflowConfigEditor.javain Symphony-Trello ata8013f27. I reproduced the same result with the latest released recipe artifact,org.openrewrite.recipe:rewrite-migrate-java:3.42.0.Before
Actual after the recipe
Expected after the recipe
Set.ofreturns an unmodifiable set, whileEnumSet.ofreturns a mutable set. The recipe changes an observable contract of the static constant even though the declared type remainsSet.Confirmed real-world execution
WorkflowConfigEditor.javaata8013f27.martinfrancois/symphony-trello@a8013f27.Anything in particular you'd like reviewers to focus on?
Please review the decision to retain the intended
EnumSetrepresentation while preserving the source set's mutation contract and the conservative no-change result when neitherCollectionsspelling is safe.Have you considered any alternatives or workarounds?
Leaving every
Set.of(...)expression unchanged preserves behavior but removes the standalone recipe's intended conversion. The unmodifiable wrapper retains both properties.Any additional context
Pre-existing tests changed:
UseEnumSetOfTest.java.changeDeclaration(updated),UseEnumSetOfTest.java.changeAssignment(updated),UseEnumSetOfTest.java.dontHaveArgs(updated).martinfrancois/symphony-trello@a8013f27org.openrewrite.recipe:rewrite-migrate-java:3.40.0org.openrewrite.recipe:rewrite-migrate-java:3.42.0UseEnumSetOfTestThis change was prepared with AI assistance. I reviewed the target execution evidence, implementation, tests, generated metadata, and contribution text.
Checklist
./gradlew buildlocally, and committed any resulting changes torecipes.csv