Skip to content

Fix GroovyParserVisitor crash on multi-variable field declarations#7467

Merged
timtebeek merged 4 commits intomainfrom
tim/fix-7463
Apr 23, 2026
Merged

Fix GroovyParserVisitor crash on multi-variable field declarations#7467
timtebeek merged 4 commits intomainfrom
tim/fix-7463

Conversation

@timtebeek
Copy link
Copy Markdown
Member

@timtebeek timtebeek commented Apr 23, 2026

Summary

The fix detects continuation fields at a leading , and emits a MultiVariable marker with an empty type expression, mirroring the existing handling for local multi-variable declarations like def a = 1, b = 2.

Test plan

  • ./gradlew :rewrite-groovy:test passes
  • Added round-trip tests for final String a, b and initializer variants in VariableDeclarationsTest
  • Added the original issue reproducer in ConstructorTest

Groovy emits a separate `FieldNode` for each variable in a multi-variable
field declaration (e.g., `final String a, b`). The parser was treating each
one as a complete declaration and re-consuming the modifiers and type tokens,
desynchronizing the cursor and eventually throwing `StringIndexOutOfBoundsException`
when parsing later nodes.

Detect continuation fields in `visitVariableField` and emit a `MultiVariable`
marker with an empty type expression, mirroring the existing handling for
local multi-variable declarations like `def a = 1, b = 2`.
Call it through the existing `visitor` instance from `visitVariableField`
to avoid displacing the `sourceBefore` javadoc.
@github-project-automation github-project-automation Bot moved this from In Progress to Ready to Review in OpenRewrite Apr 23, 2026
@timtebeek timtebeek marked this pull request as ready for review April 23, 2026 21:18
@timtebeek timtebeek merged commit a922f22 into main Apr 23, 2026
1 check passed
@timtebeek timtebeek deleted the tim/fix-7463 branch April 23, 2026 21:21
@github-project-automation github-project-automation Bot moved this from Ready to Review to Done in OpenRewrite Apr 23, 2026
iw2rmb pushed a commit to iw2rmb/rewrite that referenced this pull request Apr 24, 2026
Comparison-only alternative to openrewrite#7467: parse grouped field declarations as a single declaration to avoid cursor drift.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working groovy parser

Projects

Archived in project

Development

Successfully merging this pull request may close these issues.

GroovyParser fails on Gradle constructor-call list with typed constructor params and class fields (StringIndexOutOfBoundsException)

2 participants