You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
What is the smallest, simplest way to reproduce the problem?
The issue can be reproduced with the following code snippet:
classRemoveEnableBatchProcessingTestimplementsRewriteTest {
@Overridepublicvoiddefaults(RecipeSpecspec) {
spec.recipe(newRemoveEnableBatchProcessing())
.parser(JavaParser.fromJavaVersion().classpath("spring-batch-core", "spring-boot"));
}
@TestvoidremoveSpringBatchAnnotation() {
rewriteRun(
//language=javajava(
""" import org.springframework.batch.core.configuration.annotation.EnableBatchProcessing; import org.springframework.boot.autoconfigure.SpringBootApplication; @EnableBatchProcessing @SpringBootApplication public class Application { } """,
""" import org.springframework.boot.autoconfigure.SpringBootApplication; @SpringBootApplication public class Application { } """
)
);
}
@TestvoidremoveSpringBatchAnnotation2() {
rewriteRun(
//language=javajava(
""" import org.springframework.batch.core.configuration.annotation.EnableBatchProcessing; import org.springframework.boot.autoconfigure.SpringBootApplication; @SpringBootApplication @EnableBatchProcessing public class Application { } """,
""" import org.springframework.boot.autoconfigure.SpringBootApplication; @SpringBootApplication public class Application { } """
)
);
}
}
What did you expect to see?
I expected both test methods (removeSpringBatchAnnotation and removeSpringBatchAnnotation2) to run successfully.
What did you see instead?
The removeSpringBatchAnnotation test method passed successfully, but the removeSpringBatchAnnotation2 method failed with following error:
org.opentest4j.AssertionFailedError: [Unexpectedresultin"Application.java":
diff --git a/Application.javab/Application.javaindex 0eaa8a0..7bbfe15 100644
--- a/Application.java+++b/Application.java
@@ -1,5 +1,6 @@
import org.springframework.boot.autoconfigure.SpringBootApplication;
+@SpringBootApplication
public class Application {
}
\ No newline at end of file
]
expected:"import org.springframework.boot.autoconfigure.SpringBootApplication; @SpringBootApplication public class Application { }"butwas:"import org.springframework.boot.autoconfigure.SpringBootApplication; @SpringBootApplication public class Application { }"
hi @wapkch ; thanks for logging a runnable example! To give a bit of context: preceding newlines and comments are stored in a prefix, that can be manipulated by recipes as well.
In this case we remove the annotation by returning null here:
At that point I suspect we manipulate the prefix in openrewrite/rewrite, meaning you end up with the double newlines in some cases. As such the fix is likely upstream, and then related to handling of leading annotations. Any help exploring that would be appreciated, and then benefit all the cases where two annotations are present and one removed.
What version of OpenRewrite are you using?
I am using
How are you running OpenRewrite?
Unit Tests.
What is the smallest, simplest way to reproduce the problem?
The issue can be reproduced with the following code snippet:
What did you expect to see?
I expected both test methods (removeSpringBatchAnnotation and removeSpringBatchAnnotation2) to run successfully.
What did you see instead?
The removeSpringBatchAnnotation test method passed successfully, but the removeSpringBatchAnnotation2 method failed with following error:
Are you interested in contributing a fix to OpenRewrite?
I’m not entirely sure what the underlying issue is, but I would be happy to contribute a fix if you can provide some guidance on how to resolve it.
The text was updated successfully, but these errors were encountered: