Skip to content
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

Trailing comma in an array end up in white-space #3997

Closed
dpozinen opened this issue Feb 13, 2024 · 3 comments · Fixed by #4869
Closed

Trailing comma in an array end up in white-space #3997

dpozinen opened this issue Feb 13, 2024 · 3 comments · Fixed by #4869
Labels
bug Something isn't working parser-java test provided Already replicated with a unit test, using JUnit pioneer's ExpectedToFail

Comments

@dpozinen
Copy link
Contributor

dpozinen commented Feb 13, 2024

rewrite bom 2.6.4, wasn't an issue on 2.5.3

Test failures when there is a trailing comma in an annotation. If I remove it, tests pass.

java.lang.AssertionError: Source file was parsed into an LST that contains non-whitespace characters in its whitespace. This is indicative of a bug in the parser.

package com.playtika.services.infra.rewrite.spring;

import org.springframework.boot.test.context.SpringBootTest;

@SpringBootTest(
        properties = {
                "feign.circuitbreaker.enabled=true",
                "feign.circuitbreaker.group.enabled=true",
                "eureka.client.enabled=false"~~(non-whitespace)~~>,
        <~~},
        webEnvironment = SpringBootTest.WebEnvironment.NONE
)
public abstract class A {
}

So the comma at the end of properties in a test like this

    @Test
    void shouldChangePropertyKeyInAnnotationProperties() {
        rewriteRun(
                spec -> spec.recipe(new ChangePropertyKeyAnnotationAttributeValue(
                        "org.springframework.boot.test.context.SpringBootTest",
                        "properties", "feign.circuitbreaker.enabled",
                        "spring.cloud.openfeign.circuitbreaker.enabled")),
                java(
                        """
                                        package com.playtika.services.infra.rewrite.spring;

                                        import org.springframework.boot.test.context.SpringBootTest;

                                        @SpringBootTest(
                                                properties = {
                                                        "feign.circuitbreaker.enabled=true",
                                                        "feign.circuitbreaker.group.enabled=true",
                                                        "eureka.client.enabled=false", <-- THIS COMMA HERE
                                                },
                                                webEnvironment = SpringBootTest.WebEnvironment.NONE
                                        )
                                        public abstract class A {
                                        }
                                """
...
        ));
    }

@dpozinen dpozinen added the bug Something isn't working label Feb 13, 2024
@timtebeek
Copy link
Contributor

Hi! We recently added validation indeed to flush out LST issues in our parsers. It's helpful to improve the parsers, but indeed might cause a test to fail until we circle back to the parser. I'd encountered this case as well and logged a test last week 78a55a4

We can keep your issue open to see that parser issue resolved; in the meantime you can remove that trailing comma from the test. Hope that helps!

@timtebeek timtebeek added the test provided Already replicated with a unit test, using JUnit pioneer's ExpectedToFail label Feb 13, 2024
@timtebeek timtebeek changed the title Trailing comma in an array field of annotation fails rewrite test Trailing comma in an array end up in white-space Feb 13, 2024
@timtebeek timtebeek moved this to Backlog in OpenRewrite Feb 13, 2024
@timtebeek
Copy link
Contributor

And perhaps good to note: This is only an internal modeling issue; your source code will still be reproduced faithfully even with that modeling mishap, as we have a separate check for that. So rest assured that any code changes will be just fine; it's only a matter of using compatible examples in tests until the parser correctly models the code.

@knutwannheden
Copy link
Contributor

Another test case which can be enabled again once this is fixed:

@Disabled // TODO: This exposes bug around trailing commas in the parser
@Issue("https://github.com/openrewrite/rewrite/issues/1053")
@Test
void doNotRemoveTrailingComma() {
rewriteRun(
java(
"""
public class Test {
Integer[] integerArray = new Integer[] {
1,
2,
4,
};
}
"""
)
);
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working parser-java test provided Already replicated with a unit test, using JUnit pioneer's ExpectedToFail
Projects
Archived in project
Development

Successfully merging a pull request may close this issue.

3 participants