Paul King created GROOVY-10676:
----------------------------------
Summary: ErrorReporter (used by FileSystemCompiler) can throw an
IOOB exception on files with CR only
Key: GROOVY-10676
URL: https://issues.apache.org/jira/browse/GROOVY-10676
Project: Groovy
Issue Type: Bug
Reporter: Paul King
Assignee: Paul King
Systems using CR only aren't common but Groovy successfully parses such files.
This is true for the old and new parser.
For Groovy versions prior to 3, Antlr2 counted CR as a new line. Antlr4
doesn't. This makes a minor difference in the reported line/column numbers in
error messages but otherwise isn't a huge issue.
For places where we use {{ErrorReporter}} however, the CR counting behavior
causes a subsequent error.
Here is an example:
{code:java}
import org.codehaus.groovy.tools.ErrorReporter
try {
// error should be at column > 40, first line should be short
new GroovyShell().parse('/*\r * some comment\r */\r class class
{}\r')
} catch(e) {
Writer data = new StringWriter()
new ErrorReporter(e, true).write(new PrintWriter(data))
}
{code}
Which throws this error:
{noformat}
java.lang.StringIndexOutOfBoundsException: begin 10, end 2, length 2
at java.base/java.lang.String.checkBoundsBeginEnd(String.java:3319)
at java.base/java.lang.String.substring(String.java:1874)
at org.codehaus.groovy.control.SourceUnit.getSample(SourceUnit.java:288)
at
org.codehaus.groovy.control.messages.SyntaxErrorMessage.write(SyntaxErrorMessage.java:54)
at
org.codehaus.groovy.control.ErrorCollector.write(ErrorCollector.java:306)
{noformat}
--
This message was sent by Atlassian Jira
(v8.20.10#820010)