What version of OpenRewrite are you using?
- rewrite-migrate-java: 3.34.0
- rewrite-core: 8.81.4
- rewrite-java: 8.81.4
What is the smallest, simplest way to reproduce the problem?
package com.helloworld;
import com.google.common.collect.ImmutableList;
import java.util.List;
class Main {
List<String> copy(Iterable<String> values) {
return ImmutableList.copyOf(values);
}
}
Run org.openrewrite.java.migrate.guava.NoGuavaImmutableListCopyOf with Java 21 source/version markers.
What did you expect to see?
No change.
ImmutableList.copyOf(..) accepts an Iterable, but List.copyOf(..) only accepts a Collection, so this overload cannot be rewritten directly to List.copyOf(..).
What did you see instead?
The recipe rewrites the call to List.copyOf(values):
package com.helloworld;
import java.util.List;
class Main {
List<String> copy(Iterable<String> values) {
return List.copyOf(values);
}
}
This rewritten code does not compile.
What is the full stack trace of any errors you encountered?
Downstream compilation fails with an error like:
- error: method copyOf in interface List<E#2> cannot be applied to given types;
return List.copyOf(values);
^
- required: Collection<? extends E#1>
found: Iterable<String>
What version of OpenRewrite are you using?
What is the smallest, simplest way to reproduce the problem?
Run
org.openrewrite.java.migrate.guava.NoGuavaImmutableListCopyOfwith Java 21 source/version markers.What did you expect to see?
No change.
ImmutableList.copyOf(..)accepts anIterable, butList.copyOf(..)only accepts aCollection, so this overload cannot be rewritten directly toList.copyOf(..).What did you see instead?
The recipe rewrites the call to
List.copyOf(values):This rewritten code does not compile.
What is the full stack trace of any errors you encountered?
Downstream compilation fails with an error like: