-
Notifications
You must be signed in to change notification settings - Fork 364
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Toml ClassCastException #4890
Comments
Thanks for trying out the new toml parser, and the detailed failure report @jarasez ! Curious case indeed. I've briefly tried to replicate the issue with a unit test, but this passes so far: @Issue("https://github.com/openrewrite/rewrite/issues/4890")
@Test
void literalClassCastException(){
rewriteRun(
toml(
"""
[versions]
jackson = '2.14.2'
spring-boot = '2.7.16'
spring-dependency-management = '1.0.14.RELEASE'
openrewrite = '7.0.0'
[libraries]
jackson-annotations = { module = 'com.fasterxml.jackson.core:jackson-annotations', version.ref = 'jackson' }
jackson-core = { module = 'com.fasterxml.jackson.core:jackson-core', version.ref = 'jackson' }
jackson-databind = { module = 'com.fasterxml.jackson.core:jackson-databind', version.ref = 'jackson' }
[bundles]
jackson = ['jackson-annotations', 'jackson-core', 'jackson-databind']
[plugins]
spring-boot = { id = 'org.springframework.boot', version.ref = 'spring-boot' }
spring-boot-dependency-management = { id = 'io.spring.dependency-management', version.ref = 'spring-dependency-management' }
openrewrite = { id = 'org.openrewrite.rewrite', version.ref = 'openrewrite' }
"""
)
);
} Any help to trouble shoot this would be appreciated! |
Maybe it is a org.openrewrite.java.spring.boot3.UpgradeSpringBoot_3_3 recipe issue? is there a way to add the recipe to the test? Is running ./gradle rewriteRun on the repo link working for you? |
Turns out it's an issue with the visitor, which we hadn't tested previously. This test indeed fails already. import org.junit.jupiter.api.Test;
import org.openrewrite.*;
import org.openrewrite.marker.Markup;
import org.openrewrite.test.RewriteTest;
import java.nio.file.Path;
import java.util.ArrayList;
import java.util.List;
import java.util.Optional;
import static org.openrewrite.test.RewriteTest.toRecipe;
import static org.openrewrite.toml.Assertions.toml;
class TomlVisitorTest implements RewriteTest {
@Issue("https://github.com/openrewrite/rewrite-spring/issues/665")
@Test
void visit() {
List<RuntimeException> exceptions = new ArrayList<>();
rewriteRun(
spec -> spec.recipe(toRecipe(() -> new TreeVisitor<>() {
@Override
public Tree preVisit(Tree tree, ExecutionContext ctx) {
tree.getMarkers().findFirst(Markup.Error.class).ifPresent(e -> {
Optional<SourceFile> sourceFile = Optional.ofNullable(getCursor().firstEnclosing(SourceFile.class));
String sourcePath = sourceFile.map(SourceFile::getSourcePath).map(Path::toString).orElse("<unknown>");
exceptions.add(new RuntimeException("Error while visiting " + sourcePath + ": " + e.getDetail()));
});
return tree;
}
})),
toml(
"""
[versions]
jackson = '2.14.2'
spring-boot = '2.7.16'
spring-dependency-management = '1.0.14.RELEASE'
openrewrite = '7.0.0'
[libraries]
jackson-annotations = { module = 'com.fasterxml.jackson.core:jackson-annotations', version.ref = 'jackson' }
jackson-core = { module = 'com.fasterxml.jackson.core:jackson-core', version.ref = 'jackson' }
jackson-databind = { module = 'com.fasterxml.jackson.core:jackson-databind', version.ref = 'jackson' }
[bundles]
jackson = ['jackson-annotations', 'jackson-core', 'jackson-databind']
[plugins]
spring-boot = { id = 'org.springframework.boot', version.ref = 'spring-boot' }
spring-boot-dependency-management = { id = 'io.spring.dependency-management', version.ref = 'spring-dependency-management' }
openrewrite = { id = 'org.openrewrite.rewrite', version.ref = 'openrewrite' }
"""
)
);
}
} |
Let's continue on this PR containing the above unit test: |
Thanks again for the report @jarasez ; Turns out that the cast that tripped us up here was too strict for array values. Should go out with the next release. |
@timtebeek thanks for the fix, tested with gradle plugin version 7.0.1, however I still get the same error however at another line.
|
The correct place is here:
I suspect that Literal should implement the TomlValue interface. /cc @shanman190 |
So originally, I was using ...still assessing the correct fix... |
The original stacktrace and the latest stacktrace from 7.0.1 appear to be identical. Not sure if that was an accidental copy/paste or not. It does make me suspicious that the example is using the old version of the rewrite-toml code still with the cast that Tim removed. |
@shanman190 thank you. you are right, it's the same line with error. I updated the gradle plugin library, then I ran: |
The release process is supposed to capture the latest available versions of transitive dependencies at the time of the release, so typically just updating the plugin is enough. Regardless, you should be able to set the |
@shanman190 checked main branch and ran the test @timtebeek created and saw that the test goes through:
However in the pasted stacktrace it goes through:
Looking at the class TomlVisitor seems there is a cast to (TomlValue) on line 49.
Maybe that is the issue when running with gradle instead of the test? |
So that section is iterating over the values of the |
worked by adding |
What version of OpenRewrite are you using?
How are you running OpenRewrite?
Are you using the Maven plugin, Gradle plugin, Moderne CLI, Moderne.io or something else?
I am using the Gradle plugin, and my project is a single module project.
I am using toml files for managing dependency versions, with [bundles] tag.
Is your project a single module or a multi-module project?
The project is a single module
Is your project public? If so, can you share a link to it?
Managed to reproduce the bug, in this project: https://github.com/jarasez/openrewrite-toml
Can you share your configuration so that we can rule out any configuration issues?
libs.versions.toml
build.gradle
What is the smallest, simplest way to reproduce the problem?
Run gradle task rewriteRun.
What did you expect to see?
Successful execution of the gradle task rewriteRun. It seems that the [bundles] section of the toml causes the exception bellow.
What did you see instead?
The gradle task rewriteRun fails.
What is the full stack trace of any errors you encountered?
Are you interested in [contributing a fix to OpenRewrite]
I can get involved.
The text was updated successfully, but these errors were encountered: