Skip to content

Skip UseSetOf/UseListOf for HashSet/ArrayList subclasses - #1182

Merged
timtebeek merged 1 commit into
mainfrom
tim/issue-1181
Aug 3, 2026
Merged

Skip UseSetOf/UseListOf for HashSet/ArrayList subclasses#1182
timtebeek merged 1 commit into
mainfrom
tim/issue-1181

Conversation

@timtebeek

@timtebeek timtebeek commented Aug 3, 2026

Copy link
Copy Markdown
Member

new LinkedHashSet<>() matched the java.util.HashSet <constructor>() matcher (which uses matchOverrides, needed for the anonymous-subclass form), so:

LinkedHashSet<TestObject> ordered = new LinkedHashSet<>();
ordered.add(t1);
ordered.add(t2);

became LinkedHashSet<TestObject> ordered = new HashSet<>(Set.of(t1, t2)); — which doesn't compile, and would silently drop the iteration-order contract if it did.

`LinkedHashSet` matched the `new HashSet<>()` constructor matcher, so an
ordered set built with `add(..)` statements was rewritten to
`new HashSet<>(Set.of(..))`: uncompilable against the `LinkedHashSet`
declared type, and dropping the iteration-order contract. Mirrors the
`UseMapOf` guards added for #1113 and #1163.
@github-project-automation github-project-automation Bot moved this to In Progress in OpenRewrite Aug 3, 2026
@timtebeek
timtebeek merged commit 1234cf3 into main Aug 3, 2026
1 check passed
@timtebeek
timtebeek deleted the tim/issue-1181 branch August 3, 2026 11:59
@github-project-automation github-project-automation Bot moved this from In Progress to Done in OpenRewrite Aug 3, 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.

Recipe JavaUtilAPIs with LinkedHashSet usage in code result in uncompilable code and unordered set

1 participant