You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@commons.apache.org by "Henri Biestro (JIRA)" <ji...@apache.org> on 2015/06/26 14:17:04 UTC

[jira] [Resolved] (JEXL-159) Difference in handling between Jexl expression evaluation and LazyDynaMap

     [ https://issues.apache.org/jira/browse/JEXL-159?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Henri Biestro resolved JEXL-159.
--------------------------------
    Resolution: Not A Problem

JEXL behaves as intended on this occasion (on 2.0 and 3.0).

When solving doted variable expressions, there are 2 cases: the 'fully nested' case and the 'antish' case.
Using "x.y.z" as an expression:
- Fully nested means that at each step a non-null object or property can be accessed; 'x' must be a variable (defined in the context or as an argument or as a local variable) pointing to an instance having a 'y' property that contains an instance with a 'z' property. Note that such an expression is equivalent to "x['y']['z']".
- Antish variable means a fully qualified name 'x.y.z'; there is a variable in the context where 'x.y.z' - the full path -  is a key in the context map.

When JEXL can solve the top-level (aka the 'x' in our example), it stops considering antish variables as a possibility. This (still) seems like the sane thing to do to avoid confusing a property expression and an antish variable. 

In 3.0, com.nellarmonia.jexl.internal.Interpreter.visit(ASTReference node, Object data) could be modified (or the interpreter derived) to try to implement a different behavior...

> Difference in handling between Jexl expression evaluation and LazyDynaMap
> -------------------------------------------------------------------------
>
>                 Key: JEXL-159
>                 URL: https://issues.apache.org/jira/browse/JEXL-159
>             Project: Commons JEXL
>          Issue Type: Bug
>    Affects Versions: 2.1.1
>            Reporter: Mike Day
>
> LazyDynaMap seems to support a full stop in the attribute name, but the Jexl expression evaluation expects this to signify a nested object.
> The second test below fails, even though the first assertion is correct. Please can you take a look?
> {code}
> public class JexlTest {
> 	@Test
> 	public void testUnderscoreInName() {
>         JexlEngine jexl = new JexlEngine();
>         String jexlExp = "(x.length_mm * x.width)";
>         Expression e = jexl.createExpression( jexlExp );
>         JexlContext jc = new MapContext();
>         LazyDynaMap object = new LazyDynaMap();
>         object.set("length_mm", "10.0"); 
>         object.set("width", "5.0");
>         jc.set("x", object );
> 	    assertEquals(null, ((Double)e.evaluate(jc)).doubleValue(), 50d, 0d);
>    }
> 	@Test
> 	public void testFullStopInName() {
>         JexlEngine jexl = new JexlEngine();
>         String jexlExp = "(x.length.mm * x.width)";
>         Expression e = jexl.createExpression( jexlExp );
>         JexlContext jc = new MapContext();
>         LazyDynaMap object = new LazyDynaMap();
>         object.set("length.mm", "10.0"); 
>         object.set("width", "5.0");
>         
>         assertEquals(null, object.get("length.mm"), "10.0");
>         jc.set("x", object );
> 	    assertEquals(null, ((Double)e.evaluate(jc)).doubleValue(), 50d, 0d);
> 	}
> 	
> 	@Test
> 	public void testFullStopInNameMakingSubObject() {
>         JexlEngine jexl = new JexlEngine();
>         String jexlExp = "(x.length.mm * x.width)";
>         Expression e = jexl.createExpression( jexlExp );
>         JexlContext jc = new MapContext();
>         LazyDynaMap object = new LazyDynaMap();
>         LazyDynaMap subObject = new LazyDynaMap();
>         object.set("length", subObject);
>         subObject.set("mm", "10.0");
>         object.set("width", "5.0");
>         
>         jc.set("x", object );
> 	    assertEquals(null, ((Double)e.evaluate(jc)).doubleValue(), 50d, 0d);
> 	}
> }
> {code}



--
This message was sent by Atlassian JIRA
(v6.3.4#6332)