You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@groovy.apache.org by "Paul King (Jira)" <ji...@apache.org> on 2022/07/03 23:44:00 UTC
[jira] [Resolved] (GROOVY-10676) ErrorReporter (used by FileSystemCompiler) can throw an IOOB exception on files with CR only
[ https://issues.apache.org/jira/browse/GROOVY-10676?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]
Paul King resolved GROOVY-10676.
--------------------------------
Fix Version/s: 5.0.0-alpha-1
3.0.12
4.0.4
Resolution: Fixed
Proposed PR merged.
> 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
> Priority: Major
> Fix For: 5.0.0-alpha-1, 3.0.12, 4.0.4
>
>
> 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)