Skip to content

Skip Immutable*.copyOf rewrite when argument is not a Collection#1089

Merged
timtebeek merged 1 commit into
mainfrom
tim/issue-1086
May 6, 2026
Merged

Skip Immutable*.copyOf rewrite when argument is not a Collection#1089
timtebeek merged 1 commit into
mainfrom
tim/issue-1086

Conversation

@timtebeek
Copy link
Copy Markdown
Member

@timtebeek timtebeek commented May 6, 2026

NoGuavaImmutable{List,Set,Map}CopyOf were rewriting Immutable*.copyOf(Iterable) (and Iterator) calls into List.copyOf / Set.copyOf / Map.copyOf, but the JDK overloads only accept Collection (or Map), producing code that fails to compile. The shared AbstractNoGuavaImmutableOf now skips the rewrite when the argument type is not assignable to the JDK target's parameter type. Added regression tests covering Iterable/Iterator arguments for all three recipes.

`List.copyOf` and `Set.copyOf` only accept `Collection`, and `Map.copyOf`
only accepts `Map`, while their Guava counterparts also accept `Iterable`
and `Iterator`. Skip the rewrite when the argument type would not satisfy
the JDK signature, to avoid producing code that fails to compile.
@github-project-automation github-project-automation Bot moved this to In Progress in OpenRewrite May 6, 2026
@timtebeek timtebeek merged commit 7424e22 into main May 6, 2026
1 check passed
@github-project-automation github-project-automation Bot moved this from In Progress to Done in OpenRewrite May 6, 2026
@timtebeek timtebeek deleted the tim/issue-1086 branch May 6, 2026 15:55
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.

NoGuavaImmutableListCopyOf rewrites ImmutableList.copyOf(Iterable) to invalid List.copyOf(Iterable)

1 participant