You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@commons.apache.org by se...@apache.org on 2009/08/05 21:08:50 UTC

svn commit: r801362 - in /commons/proper/jexl/branches/2.0/src: main/java/org/apache/commons/jexl/Interpreter.java test/java/org/apache/commons/jexl/IssuesTest.java

Author: sebb
Date: Wed Aug  5 19:08:49 2009
New Revision: 801362

URL: http://svn.apache.org/viewvc?rev=801362&view=rev
Log:
JEXL-73 Undefined variables not reported correctly

Modified:
    commons/proper/jexl/branches/2.0/src/main/java/org/apache/commons/jexl/Interpreter.java
    commons/proper/jexl/branches/2.0/src/test/java/org/apache/commons/jexl/IssuesTest.java

Modified: commons/proper/jexl/branches/2.0/src/main/java/org/apache/commons/jexl/Interpreter.java
URL: http://svn.apache.org/viewvc/commons/proper/jexl/branches/2.0/src/main/java/org/apache/commons/jexl/Interpreter.java?rev=801362&r1=801361&r2=801362&view=diff
==============================================================================
--- commons/proper/jexl/branches/2.0/src/main/java/org/apache/commons/jexl/Interpreter.java (original)
+++ commons/proper/jexl/branches/2.0/src/main/java/org/apache/commons/jexl/Interpreter.java Wed Aug  5 19:08:49 2009
@@ -292,14 +292,13 @@
             isVariable &= objectNode instanceof ASTIdentifier;
             // if we get null back as a result, check for an ant variable
             if (isVariable) {
-                String name = ((ASTIdentifier) objectNode).image;
                 if (v == 0) {
-                    variableName = new StringBuilder(name);
+                    variableName = new StringBuilder(left.jjtGetChild(0).image);
                     v = 1;
                 }
                 for(; v <= c; ++v) {
                     variableName.append('.');
-                    variableName.append(name);
+                    variableName.append(left.jjtGetChild(v).image);
                 }
                 object = context.getVars().get(variableName.toString());
                 // disallow mixing ant & bean with same root; avoid ambiguity
@@ -964,14 +963,13 @@
             result = theNode.jjtAccept(this, result);
             // if we get null back a result, check for an ant variable
             if (result == null && isVariable) {
-                String name = ((ASTIdentifier) theNode).image;
                 if (v == 0) {
-                    variableName = new StringBuilder(name);
+                    variableName = new StringBuilder(node.jjtGetChild(0).image);
                     v = 1;
                 }
                 for(; v <= i; ++v) {
                     variableName.append('.');
-                    variableName.append(name);
+                    variableName.append(node.jjtGetChild(v).image);
                 }
                 result = vars.get(variableName.toString());
             }
@@ -1254,7 +1252,7 @@
     }
 
     /**
-     * Unused, satisfy PArserVisitor interface.
+     * Unused, satisfy ParserVisitor interface.
      * @param node a node
      * @param data the date
      * @return does not return,

Modified: commons/proper/jexl/branches/2.0/src/test/java/org/apache/commons/jexl/IssuesTest.java
URL: http://svn.apache.org/viewvc/commons/proper/jexl/branches/2.0/src/test/java/org/apache/commons/jexl/IssuesTest.java?rev=801362&r1=801361&r2=801362&view=diff
==============================================================================
--- commons/proper/jexl/branches/2.0/src/test/java/org/apache/commons/jexl/IssuesTest.java (original)
+++ commons/proper/jexl/branches/2.0/src/test/java/org/apache/commons/jexl/IssuesTest.java Wed Aug  5 19:08:49 2009
@@ -213,4 +213,29 @@
         assertEquals(jexpr.getExpression(), null, jexpr.evaluate(ctxt)); // OK
     }
 
+    // JEXL-73
+    public void test73() throws Exception {
+        JexlContext ctxt = JexlHelper.createContext();
+        JexlEngine jexl = new JexlEngine();
+        jexl.setSilent(false);
+        jexl.setLenient(false);
+        Expression e;
+        e = jexl.createExpression("c.e");
+        try {
+            /* Object o = */ e.evaluate(ctxt);
+        } catch(JexlException xjexl) {
+            String msg = xjexl.getMessage();
+            assertTrue(msg.indexOf("variable c.e") > 0);
+        }
+
+        ctxt.getVars().put("c", "{ 'a' : 3, 'b' : 5}");
+        ctxt.getVars().put("e", Integer.valueOf(2));
+        try {
+            /* Object o = */ e.evaluate(ctxt);
+        } catch(JexlException xjexl) {
+            String msg = xjexl.getMessage();
+            assertTrue(msg.indexOf("variable c.e") > 0);
+        }
+
+    }
 }
\ No newline at end of file