Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Don't throw a bounds exception when reporting Java errors at EOF. #61

Open
kristapsdz-saic opened this issue Apr 21, 2022 · 1 comment

Comments

@kristapsdz-saic
Copy link

This fixes an off-by-one for the Java sources. If the condition is <=, the body will read after the end of the array and throw a bounds exception. This only occurs in the situation of printing an exception that has occurred at exactly the last character.

diff --git a/node_modules/canopy/templates/java/Parser.java b/node_modules/canopy/templates/java/Parser.java
index 8d38b7a..46563ed 100644
--- a/node_modules/canopy/templates/java/Parser.java
+++ b/node_modules/canopy/templates/java/Parser.java
@@ -27,7 +27,7 @@ public class {{name}} extends Grammar {
         String[] lines = input.split("\n");
         int lineNo = 0, position = 0;

-        while (position <= offset) {
+        while (position < offset) {
             position += lines[lineNo].length() + 1;
             lineNo += 1;
         }
@jcoglan
Copy link
Owner

jcoglan commented Apr 22, 2022

Could you give an example of a grammar and input text that triggers the bug you're fixing?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants