What version of OpenRewrite are you using?
rewrite-migrate-java 2.20.0
What is the smallest, simplest way to reproduce the problem?
I can reproduce the issue with the following testcase:
@Test
void enumSetOfVarargs() {
rewriteRun(
spec -> spec.recipe(new UseEnumSetOf()),
java(
"""
package com.helloworld;
import java.util.concurrent.TimeUnit;
import java.util.Set;
public class Main {
public Set<TimeUnit> method(final TimeUnit... units) {
final Set<TimeUnit> asSet = Set.of(units);
return asSet;
}
}"""));
}
}
What did you expect to see?
Either to bail out and keep it as is.
Or alternatively we could translate the varargs parameter into a collection first, e.g.
public Set<TimeUnit> method(final TimeUnit... units) {
final Set<TimeUnit> asSet = EnumSet.noneOf(TimeUnit.class);
asSet.addAll(Arrays.asList(units));
return asSet;
}
Note that the more convenient-looking EnumSet.copyOf(asList(units)) throws an exception for empty array.
What did you see instead?
public Set<TimeUnit> method(final TimeUnit... units) {
final Set<TimeUnit> asSet = EnumSet.of(units);
return asSet;
}
(doesn't compile)
What version of OpenRewrite are you using?
rewrite-migrate-java 2.20.0
What is the smallest, simplest way to reproduce the problem?
I can reproduce the issue with the following testcase:
What did you expect to see?
Either to bail out and keep it as is.
Or alternatively we could translate the varargs parameter into a collection first, e.g.
Note that the more convenient-looking
EnumSet.copyOf(asList(units))throws an exception for empty array.What did you see instead?
(doesn't compile)