Gradle parser fails with a trailing comma in method call
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.
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.
@shanman190 Thanks for looking into this.
I've set up a dedicated Gradle project for reproducing the issue with simple gradlew init: https://github.com/mccartney/rewrite-repro-4614-gradle/commit/f5b959e3b386b12ce84df29d5a5456ab5ee31b56
The Gradle build passes with and without this commit.
Also - the example has been extracted from real-life Gradle configuration file.
Also checked Groovy program in tio.run:
class Example {
static void main(String[] args) {
println('Hello World',);
}
}
and it worked fine.
@Test
void trailingCommaInMethodCall() {
rewriteRun(
groovy(
"""
System.out.println("Anwil Wloclawek", )
"""
)
);
}
fails in rewrite-groovy the same way as original report.
As a quick update: from the Java side we're now modeling the trailing comma as a marker; that might help here as well
- https://github.com/openrewrite/rewrite/pull/4869
This is the place where likely the marker logic needs to be added.
Proposed fix in: https://github.com/openrewrite/rewrite/pull/5711