You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@commons.apache.org by he...@apache.org on 2020/04/08 11:02:11 UTC

[commons-jexl] branch master updated: JEXL-330: use source in parsing error reporting Task #JEXL-330 - JexlException.Parsing.getMessage() throws StringIndexOutOfBoundsException when parse error is in long expression

This is an automated email from the ASF dual-hosted git repository.

henrib pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/commons-jexl.git


The following commit(s) were added to refs/heads/master by this push:
     new 1c2bdb4  JEXL-330: use source in parsing error reporting Task #JEXL-330 - JexlException.Parsing.getMessage() throws StringIndexOutOfBoundsException when parse error is in long expression
1c2bdb4 is described below

commit 1c2bdb466698e7dd7173c8ac52432188401f8296
Author: henrib <he...@apache.org>
AuthorDate: Wed Apr 8 13:01:06 2020 +0200

    JEXL-330: use source in parsing error reporting
    Task #JEXL-330 - JexlException.Parsing.getMessage() throws StringIndexOutOfBoundsException when parse error is in long expression
---
 RELEASE-NOTES.txt                                    |  1 +
 .../java/org/apache/commons/jexl3/parser/Parser.jjt  |  4 ++--
 src/site/xdoc/changes.xml                            |  3 +++
 .../java/org/apache/commons/jexl3/Issues300Test.java | 20 ++++++++++++++++++++
 4 files changed, 26 insertions(+), 2 deletions(-)

diff --git a/RELEASE-NOTES.txt b/RELEASE-NOTES.txt
index 26297b3..d6d3829 100644
--- a/RELEASE-NOTES.txt
+++ b/RELEASE-NOTES.txt
@@ -74,6 +74,7 @@ New Features in 3.2:
 
 Bugs Fixed in 3.2:
 ==================
+* JEXL-330:      JexlException.Parsing.getMessage() throws exception when parse error is in long expression
 * JEXL-328:      JXLT template scripts evaluation do not process pragmas
 * JEXL-327:      map[null] does not work in assignment context
 * JEXL-326:      Link to "JavaCC" on syntax reference page is broken
diff --git a/src/main/java/org/apache/commons/jexl3/parser/Parser.jjt b/src/main/java/org/apache/commons/jexl3/parser/Parser.jjt
index fb5ae37..e637d59 100644
--- a/src/main/java/org/apache/commons/jexl3/parser/Parser.jjt
+++ b/src/main/java/org/apache/commons/jexl3/parser/Parser.jjt
@@ -70,8 +70,8 @@ public final class Parser extends JexlParser
         } catch (TokenMgrError xtme) {
             throw new JexlException.Tokenization(info, xtme).clean();
         } catch (ParseException xparse) {
-            Token errortok = errorToken(jj_lastpos, jj_scanpos, token.next, token);
-            throw new JexlException.Parsing(info.at(errortok.beginLine, errortok.beginColumn), errortok.image).clean();
+            Token errortok = errorToken(token, jj_lastpos, jj_scanpos, token.next);
+            throw new JexlException.Parsing(info.at(errortok.beginLine, errortok.beginColumn), jexlSrc).clean();
         } finally {
             token_source.defaultLexState = DEFAULT;
             cleanup(previous);
diff --git a/src/site/xdoc/changes.xml b/src/site/xdoc/changes.xml
index 281d8d4..b09d175 100644
--- a/src/site/xdoc/changes.xml
+++ b/src/site/xdoc/changes.xml
@@ -26,6 +26,9 @@
     </properties>
     <body>
         <release version="3.2" date="unreleased">
+            <action dev="henrib" type="fix" issue="JEXL-330" due-to="David Costanzo">
+                JexlException.Parsing.getMessage() throws exception when parse error is in long expression
+            </action>
             <action dev="henrib" type="fix" issue="JEXL-328">
                 JXLT template scripts evaluation do not process pragmas
             </action>
diff --git a/src/test/java/org/apache/commons/jexl3/Issues300Test.java b/src/test/java/org/apache/commons/jexl3/Issues300Test.java
index 65a4d6a..875c182 100644
--- a/src/test/java/org/apache/commons/jexl3/Issues300Test.java
+++ b/src/test/java/org/apache/commons/jexl3/Issues300Test.java
@@ -529,4 +529,24 @@ public class Issues300Test {
         result = script.execute(jc, map, "42");
         Assert.assertEquals(42, result);
     }
+    
+    @Test
+    public void test330() throws Exception {
+        JexlEngine jexl = new JexlBuilder().create();
+        // Extended form of: 'literal' + VARIABLE   'literal'
+        // missing + operator here ---------------^
+        String longExpression = ""
+                + //
+                "'THIS IS A VERY VERY VERY VERY VERY VERY VERY "
+                + //
+                "VERY VERY LONG STRING CONCATENATION ' + VARIABLE ' <--- "
+                + //
+                "error: missing + between VARIABLE and literal'";
+        try {
+            jexl.createExpression(longExpression);
+            Assert.fail("parsing malformed expression did not throw exception");
+        } catch (JexlException.Parsing exception) {
+            Assert.assertTrue(exception.getMessage().contains("VARIABLE"));
+        }
+    }
 }