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

Gradle parser fails with a trailing comma in method call #4614

Open
mccartney opened this issue Oct 26, 2024 · 5 comments
Open

Gradle parser fails with a trailing comma in method call #4614

mccartney opened this issue Oct 26, 2024 · 5 comments
Labels

Comments

@mccartney
Copy link
Contributor

What is the smallest, simplest way to reproduce the problem?

    @Test
    void trailingComma() {
        rewriteRun(
          buildGradle(
            """
              plugins {
                  id 'java-library'
              }
              dependencies {
                  implementation platform("commons-lang:commons-lang:2.6", )
              }
              """
          )
        );
    }

What is the full stack trace of any errors you encountered?

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. 
plugins {
    id 'java-library'
}
dependencies {
    implementation platform("commons-lang:commons-lang:2.6"~~(non-whitespace)~~>, <~~)
}
	at org.openrewrite.test.RewriteTest.rewriteRun(RewriteTest.java:323)
	at org.openrewrite.test.RewriteTest.rewriteRun(RewriteTest.java:132)
	at org.openrewrite.test.RewriteTest.rewriteRun(RewriteTest.java:127)
	at org.openrewrite.gradle.GradleParserTest.trailingComma(GradleParserTest.java:199)

Context

  • AFAIK this is a valid Groovy-flavor Gradle file.
  • Obviously removing the comma makes the test pass.
@shanman190
Copy link
Contributor

I think this one needs to be verified with Gradle natively also before trying to fix the parser. I'd almost expect for Gradle to fail as well which is what I'd want to see verified.

@mccartney
Copy link
Contributor Author

@shanman190 Thanks for looking into this.
I've set up a dedicated Gradle project for reproducing the issue with simple gradlew init: mccartney/rewrite-repro-4614-gradle@f5b959e
The Gradle build passes with and without this commit.

Also - the example has been extracted from real-life Gradle configuration file.

@mccartney
Copy link
Contributor Author

mccartney commented Nov 1, 2024

Also checked Groovy program in tio.run:

class Example {
   static void main(String[] args) {
      println('Hello World',);
   }
}

and it worked fine.

@mccartney
Copy link
Contributor Author

    @Test
    void trailingCommaInMethodCall() {
        rewriteRun(
          groovy(
            """
              System.out.println("Anwil Wloclawek", )
              """
          )
        );
    }

fails in rewrite-groovy the same way as original report.

@timtebeek
Copy link
Contributor

As a quick update: from the Java side we're now modeling the trailing comma as a marker; that might help here as well

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
Status: Backlog
Development

No branches or pull requests

4 participants