Skip to content

Commit 3aa6760

Browse files
Fixing handling of a case when array dimensions is the last thing in a Groovy source file (#5689)
1 parent 6d291ca commit 3aa6760

File tree

2 files changed

+12
-1
lines changed

2 files changed

+12
-1
lines changed

rewrite-groovy/src/main/java/org/openrewrite/groovy/GroovyParserVisitor.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -722,7 +722,7 @@ private List<J.ArrayDimension> buildNewArrayDimensions(ArrayExpression expressio
722722
}
723723
while (true) {
724724
int beginBracket = indexOfNextNonWhitespace(cursor, source);
725-
if (source.charAt(beginBracket) != '[') {
725+
if (beginBracket >= source.length() || source.charAt(beginBracket) != '[') {
726726
break;
727727
}
728728

rewrite-groovy/src/test/java/org/openrewrite/groovy/GroovyParserTest.java

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,4 +117,15 @@ void inner() {
117117
)
118118
);
119119
}
120+
121+
@Test
122+
void variableDeclarationWithArrayInstantiationAsTheLastStatement() {
123+
rewriteRun(
124+
groovy(
125+
"""
126+
def arr = new String[2]
127+
"""
128+
)
129+
);
130+
}
120131
}

0 commit comments

Comments
 (0)