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
{{ message }}
Repository navigation
[groovy] CPD fails on GStrings that end in an interpolated variable #7100
CPD reports a lexical error on valid Groovy when a GString ends in a $name interpolation. For some
inputs the error is a GroovySyntaxError that stops the whole run, even with --no-fail-on-error.
GroovyCpdLexer builds org.apache.groovy.parser.antlr4.GroovyLexer. The Groovy compiler does not
use that class on its own. It uses the subclass GroovyLangLexer, which lexes these inputs without
error.
Code Sample demonstrating the issue:
def a ="$i"
$ pmd cpd -l groovy --minimum-tokens 10 -d A.groovy
[ERROR] Skipping file: Lexical error in file 'A.groovy' at line 1, column 12: token recognition error at: '\n'
"x $i" fails the same way. "x $i y" and "${i}" pass.
When another string follows on the same line, the lexer throws GroovySyntaxError instead:
f("x-$i", "y")
$ pmd cpd -l groovy --minimum-tokens 10 --no-fail-on-error -d B.groovy
Exception in thread "main" org.apache.groovy.parser.antlr4.GroovySyntaxError: Unexpected character: '"'
at org.apache.groovy.parser.antlr4.SyntaxErrorReportable.throwSyntaxError(SyntaxErro
...
at org.apache.groovy.parser.antlr4.GroovyLexer.UNEXPECTED_CHAR_action(GroovyLexer.ja
GroovySyntaxError extends AssertionError, so CPD does not skip the file. The run ends with no
report.
Expected outcome:
CPD tokenizes both files, as groovyc compiles them.
I ran both lexers over the Groovy test files of one project (Spock specs), with an error
listener that throws, as GroovyTokenManager does:
Activity
Add contribution 34: pmd/pmd#7100
[groovy] Fix #7100: CPD fails on GStrings ending in an interpolated v…