Open MagicalAsh opened 3 months ago
Thanks for the detailed report @MagicalAsh ; That must not have been easy to pin and reduce down. Know that it is appreciated.
I don't quite know what would cause this to start failing, but it's definitely concerning. I suspect it's to do with one of those recipes not updating the model correctly, but that would have to be explored.
As a first step I've taken the recipes you've provided and replicated the problem in a unit test.
@Issue("https://github.com/openrewrite/rewrite-static-analysis/issues/321")
@Test
void repeatedApplicationOfRecipe() {
rewriteRun(
spec -> spec.recipes(
new UseCollectionInterfaces(),
new RemoveUnusedPrivateFields()
),
//language=java
java(
"""
import java.util.Arrays;
import java.util.HashSet;
class Main {
private static final HashSet<String> allowedMethods = new HashSet<>(Arrays.asList(
"GET", "HEAD", "TRACE", "OPTIONS"));
public boolean matches() {
return allowedMethods.contains("GET");
}
}
""",
"""
import java.util.Arrays;
import java.util.HashSet;
import java.util.Set;
class Main {
private static final Set<String> allowedMethods = new HashSet<>(Arrays.asList(
"GET", "HEAD", "TRACE", "OPTIONS"));
public boolean matches() {
return allowedMethods.contains("GET");
}
}
"""
)
);
}
Note that I was able to remove the chained recipes, as tests already run recipes repeatedly.
I've been able to narrow down your example quite a bit; it looks like this exact combination and minimal code above is enough to reproduce the issue; now to figure out why it's happening. 😕
What version of OpenRewrite are you using?
I am using
How are you running OpenRewrite?
I am using the Gradle plugin, and my project is a single module project. I've attached a copy of the project directory.
What is the smallest, simplest way to reproduce the problem?
Using this config file:
We see errors in the following file after running
./gradlew rewriteRun
when our project is configured withactiveRecipe("com.example.Migrate3")
.We were able to correct the incorrect behavior by removing the duplicated invocations of the
com.example.BaseFormat
recipe in our instance, but the expected behavior here would be that it simply runs the recipes correctly. Figuring out that this was the issue took a while.What did you expect to see?
The expected behavior would be to see all recipes executed correctly, i.e. the output should be nearly identical.
What did you see instead?
Note that the in-use allowedMethods private constant was removed, and that there's now a leftover unused import.
What is the full stack trace of any errors you encountered?
No explicit errors occured in the execution of OpenRewrite, however the following was output by the plugin:
Are you interested in contributing a fix to OpenRewrite?
I unfortunately don't have time to both investigate and submit a fix for this at the moment, sorry.