Description
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:
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)) }
Which throws this error:
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)
Attachments
Issue Links
- links to