[jira] [Commented] (JEXL-302) JexlScript.getVariables returns strange values for array access

2020-02-14 Thread Henri Biestro (Jira)


[ 
https://issues.apache.org/jira/browse/JEXL-302?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel=17037331#comment-17037331
 ] 

Henri Biestro commented on JEXL-302:


Changeset: 8dee2ad6abe88213625dc126cf811d43925c6317
Author:henrib 
Date:  2020-02-14 23:12
Message:   JEXL-302: added a capture mode to further refine how getVariable 
should behave wrt constants in array references

> JexlScript.getVariables returns strange values for array access
> ---
>
> Key: JEXL-302
> URL: https://issues.apache.org/jira/browse/JEXL-302
> Project: Commons JEXL
>  Issue Type: Bug
>Affects Versions: 3.1
>Reporter: Dmitri Blinov
>Assignee: Henri Biestro
>Priority: Minor
> Fix For: 3.2
>
>
> I can not understand the logic behind the current implementation of 
> {{JexlScript.getVariables()}} method. From the documentation we know that the 
> result should be the set of script variables. For the code
> {code:java}
> a[b][c]{code}
> it gives three variables {{a}}, {{b}}, {{c}}. So far so good. But for the code
> {code:java}
> a[b]['c']{code}
> it returns {{a}} and {{b c}}, where second variable has two fragments {{b}} 
> and {{c}}. The documentation states that variables with multiple fragments 
> are ant-ish variables, but I don't have any of ant-ish variables in the 
> example, and {{'c'}} is not a variable, but a constant. I expect to get {{a}} 
> and {{b}} as a result.



--
This message was sent by Atlassian Jira
(v8.3.4#803005)


[jira] [Commented] (JEXL-302) JexlScript.getVariables returns strange values for array access

2020-02-12 Thread Dmitri Blinov (Jira)


[ 
https://issues.apache.org/jira/browse/JEXL-302?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel=17035185#comment-17035185
 ] 

Dmitri Blinov commented on JEXL-302:


Thanks for the clarification, it was the transion from {{a[['b', 'c']]}} to 
{{[a.b, a.c]}} that I wasn't able to figure out. This is not obvious because 
getting list of properties via array access is not supported anywhere in the 
basic implementation. Not sure whether it's worth adding such a feature though. 
But one thing that I think is strange here is that \{{getVariables()}}  in fact 
*relies* on the hypotesis that one should implement array access to support 
sets and arrays in such a way.

> JexlScript.getVariables returns strange values for array access
> ---
>
> Key: JEXL-302
> URL: https://issues.apache.org/jira/browse/JEXL-302
> Project: Commons JEXL
>  Issue Type: Bug
>Affects Versions: 3.1
>Reporter: Dmitri Blinov
>Assignee: Henri Biestro
>Priority: Minor
> Fix For: 3.2
>
>
> I can not understand the logic behind the current implementation of 
> {{JexlScript.getVariables()}} method. From the documentation we know that the 
> result should be the set of script variables. For the code
> {code:java}
> a[b][c]{code}
> it gives three variables {{a}}, {{b}}, {{c}}. So far so good. But for the code
> {code:java}
> a[b]['c']{code}
> it returns {{a}} and {{b c}}, where second variable has two fragments {{b}} 
> and {{c}}. The documentation states that variables with multiple fragments 
> are ant-ish variables, but I don't have any of ant-ish variables in the 
> example, and {{'c'}} is not a variable, but a constant. I expect to get {{a}} 
> and {{b}} as a result.



--
This message was sent by Atlassian Jira
(v8.3.4#803005)


[jira] [Commented] (JEXL-302) JexlScript.getVariables returns strange values for array access

2020-02-11 Thread Henri Biestro (Jira)


[ 
https://issues.apache.org/jira/browse/JEXL-302?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel=17034586#comment-17034586
 ] 

Henri Biestro commented on JEXL-302:


That subject is moot if you use a JexBuilder().captureAll(false) as in:
{code:java}
JexlEngine jexld = new JexlBuilder().collectAll(false).create();
e = jexld.createScript("x.y[{'z': 't'}]");
vars = e.getVariables();
Assert.assertEquals(1, vars.size());
Assert.assertTrue(eq(mkref(new String[][]{{"x", "y"}}), vars));}
 {code}
In the captureAll(true) case, the logic is in the actual intent of getVariables 
; statically capture the elements that will potentially influence the script 
execution flow, ie all variables. Since one can configure JEXL so that a.b is 
equivalent to a['b'], it stands to reason that a a[['b', 'c’]] can be 
interpreted as [a.b, a.c]. , thus the a, ['b', 'c'] resulting of getVariables. 
The same logic can be applied to constant sets and maps.

For instance:
{code:java}
script = JEXL.createScript("moon.landing[['', 'MM', 'dd']]");
result = (List) script.execute(ctxt);
Assert.assertEquals(Arrays.asList("1969", "7", "20"), result);
{code}
In this example, the script
{code:java}
 moon.landing[['', 'MM', 'dd']]{code}
 is equivalent to 
{code:java}
 [ moon.landing., moon.landing.MM, moon.landing.dd ]
{code}
With a bit of added parsing, it becomes possible to determine those from 
getVariables.
 I'm adding a test case to illustrate, [JEXL-302: added a test for 
JexBuilder.captureAll() and 
JexlScript.get…|https://github.com/apache/commons-jexl/commit/09db242b8cffbf63ad4a59d4e62f3ac358d4be24]

> JexlScript.getVariables returns strange values for array access
> ---
>
> Key: JEXL-302
> URL: https://issues.apache.org/jira/browse/JEXL-302
> Project: Commons JEXL
>  Issue Type: Bug
>Affects Versions: 3.1
>Reporter: Dmitri Blinov
>Assignee: Henri Biestro
>Priority: Minor
> Fix For: 3.2
>
>
> I can not understand the logic behind the current implementation of 
> {{JexlScript.getVariables()}} method. From the documentation we know that the 
> result should be the set of script variables. For the code
> {code:java}
> a[b][c]{code}
> it gives three variables {{a}}, {{b}}, {{c}}. So far so good. But for the code
> {code:java}
> a[b]['c']{code}
> it returns {{a}} and {{b c}}, where second variable has two fragments {{b}} 
> and {{c}}. The documentation states that variables with multiple fragments 
> are ant-ish variables, but I don't have any of ant-ish variables in the 
> example, and {{'c'}} is not a variable, but a constant. I expect to get {{a}} 
> and {{b}} as a result.



--
This message was sent by Atlassian Jira
(v8.3.4#803005)


[jira] [Commented] (JEXL-302) JexlScript.getVariables returns strange values for array access

2020-02-05 Thread Dmitri Blinov (Jira)


[ 
https://issues.apache.org/jira/browse/JEXL-302?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel=17030755#comment-17030755
 ] 

Dmitri Blinov commented on JEXL-302:


Maybe I'm kicking a dead horse here, but can you please explain the logic 
behind {{x.y[['z', 't']]}}
{code:java}
@Test
public void testLiteral() throws Exception {
JexlScript e = JEXL.createScript("x.y[['z', 't']]");
Set> vars = e.getVariables();
Assert.assertEquals(1, vars.size());
Assert.assertTrue(eq(mkref(new String[][]{{"x", "y", "[ 'z', 't' ]"}}), 
vars));
} {code}
Why do we expect the last "[ 'z', 't' ]" part? How is it differ from, for 
instance, {{x.y['z' + 't']}} in a sense that both {{'z' + 't'}} and {{['z', 
't']}} are just expressions?

> JexlScript.getVariables returns strange values for array access
> ---
>
> Key: JEXL-302
> URL: https://issues.apache.org/jira/browse/JEXL-302
> Project: Commons JEXL
>  Issue Type: Bug
>Affects Versions: 3.1
>Reporter: Dmitri Blinov
>Assignee: Henri Biestro
>Priority: Minor
> Fix For: 3.2
>
>
> I can not understand the logic behind the current implementation of 
> {{JexlScript.getVariables()}} method. From the documentation we know that the 
> result should be the set of script variables. For the code
> {code:java}
> a[b][c]{code}
> it gives three variables {{a}}, {{b}}, {{c}}. So far so good. But for the code
> {code:java}
> a[b]['c']{code}
> it returns {{a}} and {{b c}}, where second variable has two fragments {{b}} 
> and {{c}}. The documentation states that variables with multiple fragments 
> are ant-ish variables, but I don't have any of ant-ish variables in the 
> example, and {{'c'}} is not a variable, but a constant. I expect to get {{a}} 
> and {{b}} as a result.



--
This message was sent by Atlassian Jira
(v8.3.4#803005)


[jira] [Commented] (JEXL-302) JexlScript.getVariables returns strange values for array access

2019-06-06 Thread Dmitri Blinov (JIRA)


[ 
https://issues.apache.org/jira/browse/JEXL-302?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel=16857942#comment-16857942
 ] 

Dmitri Blinov commented on JEXL-302:


Just as I thought, there is a bug in current implementation. Consider the 
following test case in {{VarTest.testRefs}}
{code:java}
    e = JEXL.createScript("a[b].c");
    vars = e.getVariables();
    expect = mkref(new String[][]{{"a"}, {"b"}});
    Assert.assertTrue(eq(expect, vars));
{code}

> JexlScript.getVariables returns strange values for array access
> ---
>
> Key: JEXL-302
> URL: https://issues.apache.org/jira/browse/JEXL-302
> Project: Commons JEXL
>  Issue Type: Bug
>Affects Versions: 3.1
>Reporter: Dmitri Blinov
>Assignee: Henri Biestro
>Priority: Minor
> Fix For: 3.2
>
>
> I can not understand the logic behind the current implementation of 
> {{JexlScript.getVariables()}} method. From the documentation we know that the 
> result should be the set of script variables. For the code
> {code:java}
> a[b][c]{code}
> it gives three variables {{a}}, {{b}}, {{c}}. So far so good. But for the code
> {code:java}
> a[b]['c']{code}
> it returns {{a}} and {{b c}}, where second variable has two fragments {{b}} 
> and {{c}}. The documentation states that variables with multiple fragments 
> are ant-ish variables, but I don't have any of ant-ish variables in the 
> example, and {{'c'}} is not a variable, but a constant. I expect to get {{a}} 
> and {{b}} as a result.



--
This message was sent by Atlassian JIRA
(v7.6.3#76005)


[jira] [Commented] (JEXL-302) JexlScript.getVariables returns strange values for array access

2019-06-06 Thread Dmitri Blinov (JIRA)


[ 
https://issues.apache.org/jira/browse/JEXL-302?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel=16857849#comment-16857849
 ] 

Dmitri Blinov commented on JEXL-302:


I think the idea of having an option at the Engine level is more preferrable 
than a parameter of the {{getVariables()}}. I can not imagine a situation where 
one needs to analyze variables both ways at once, so we can have the engine to 
be in compatible mode by default, and allow to trigger it on during engine 
creation in case one sees its more appropriate.

> JexlScript.getVariables returns strange values for array access
> ---
>
> Key: JEXL-302
> URL: https://issues.apache.org/jira/browse/JEXL-302
> Project: Commons JEXL
>  Issue Type: Bug
>Affects Versions: 3.1
>Reporter: Dmitri Blinov
>Assignee: Henri Biestro
>Priority: Minor
> Fix For: 3.2
>
>
> I can not understand the logic behind the current implementation of 
> {{JexlScript.getVariables()}} method. From the documentation we know that the 
> result should be the set of script variables. For the code
> {code:java}
> a[b][c]{code}
> it gives three variables {{a}}, {{b}}, {{c}}. So far so good. But for the code
> {code:java}
> a[b]['c']{code}
> it returns {{a}} and {{b c}}, where second variable has two fragments {{b}} 
> and {{c}}. The documentation states that variables with multiple fragments 
> are ant-ish variables, but I don't have any of ant-ish variables in the 
> example, and {{'c'}} is not a variable, but a constant. I expect to get {{a}} 
> and {{b}} as a result.



--
This message was sent by Atlassian JIRA
(v7.6.3#76005)


[jira] [Commented] (JEXL-302) JexlScript.getVariables returns strange values for array access

2019-06-04 Thread Henri Biestro (JIRA)


[ 
https://issues.apache.org/jira/browse/JEXL-302?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel=16856126#comment-16856126
 ] 

Henri Biestro commented on JEXL-302:


I'm sorry, I must have been unclear; let me try again.

The intended purpose of getVariable is to retrieve the list of variables 
susceptible to change the outcome of a script/expression evaluation. The output 
is a set of list of strings. Each list is at least a (top level) variable 
followed by properties; if one of this list is {{\{"a", "b"\}}}, it means if 
there is a solvable variable {{'a'}} - and more precisely a solvable property 
{{"b"}} of  a variable {{"a"}}, varying its value is susceptible to change the 
outcome of the script evaluation. If one list is {{\{"a", "b", "c"\}}}, it 
means the solvable property {{"c"}} of the solvable property {{"b"}} of the 
solvable variable {{"a"}} may have an effect etc. You get the idea.
It also means in that latest form case, that {{a['b']['c']}} may behave the 
same way and thus generates the same list..
A side effect is that the method also picks up the (evil) antish-variables but 
I suspect (and hope) anyone using those in their environment knows them and 
should have no difficulty reconciling the output of getVariables and the 
potential antish vars.

As for you example, {{a[b]['c']}} is not equivalent to {{a[b.c]}} ; the latter 
is equivalent to {{a[b['c']]}}. I've added 2 more examples in VarTest.testRefs 
( 
https://github.com/apache/commons-jexl/commit/66d5f6e69992a6473c94bff2cf17889a428ab622
 ).

All that being said, I think the feature still works as intended (per 
JEXL-113). But I hear you, things have changed wrt to property/array resolution 
so we may want to add an option to that feature to only consider dotted 
identifiers - not their array counterparts. That's fairly easy (Engine.java, 
lline 588, add a condition), we just need to specify how to pass it down. I 
prototried with a boolean argument to getVariable, that works but changes lots 
of code, adding overloads; may be the Engine could be configured through an 
option since it is probably related to resolver strategies.

Share your thoughts.

> JexlScript.getVariables returns strange values for array access
> ---
>
> Key: JEXL-302
> URL: https://issues.apache.org/jira/browse/JEXL-302
> Project: Commons JEXL
>  Issue Type: Bug
>Affects Versions: 3.1
>Reporter: Dmitri Blinov
>Assignee: Henri Biestro
>Priority: Minor
> Fix For: 3.2
>
>
> I can not understand the logic behind the current implementation of 
> {{JexlScript.getVariables()}} method. From the documentation we know that the 
> result should be the set of script variables. For the code
> {code:java}
> a[b][c]{code}
> it gives three variables {{a}}, {{b}}, {{c}}. So far so good. But for the code
> {code:java}
> a[b]['c']{code}
> it returns {{a}} and {{b c}}, where second variable has two fragments {{b}} 
> and {{c}}. The documentation states that variables with multiple fragments 
> are ant-ish variables, but I don't have any of ant-ish variables in the 
> example, and {{'c'}} is not a variable, but a constant. I expect to get {{a}} 
> and {{b}} as a result.



--
This message was sent by Atlassian JIRA
(v7.6.3#76005)


[jira] [Commented] (JEXL-302) JexlScript.getVariables returns strange values for array access

2019-06-03 Thread Dmitri Blinov (JIRA)


[ 
https://issues.apache.org/jira/browse/JEXL-302?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel=16854569#comment-16854569
 ] 

Dmitri Blinov commented on JEXL-302:


I have got your point, but for the sake of argument, as of now - {{a.b}} is not 
equivalent to {{a["b"]}}. First because of ant-ish variables. One can only 
address anti-sh variable as {{a.b}}, not as {{a["b"]}}. And second - because we 
can have {{propertyGet()/propertySet()}} and {{arrayGet()/arraySet()}} to be 
overloaded separately.

I understand that what {{a.b}} is resolved into (whether this a variable 
{{a.b}} or only {{a}} is a variable, and {{b}} is property name) is decided 
during runtime, so this can not be defined from syntax representation tree - a 
tough task for {{JexlScript.getVariables()}}.

Still, the example of issue
{code:java}
a[b]['c']{code}
does not follow the pattern in question. From your explanation, and from what I 
get from the {{JexlScript.getVariables(),}} the code {{a[b]['c']}} is 
equivalent to {{a[b.c]}}, which in fact should be equivalent to {{a[b["c"]]}}. 
Something is wrong here...

> JexlScript.getVariables returns strange values for array access
> ---
>
> Key: JEXL-302
> URL: https://issues.apache.org/jira/browse/JEXL-302
> Project: Commons JEXL
>  Issue Type: Bug
>Affects Versions: 3.1
>Reporter: Dmitri Blinov
>Assignee: Henri Biestro
>Priority: Minor
> Fix For: 3.2
>
>
> I can not understand the logic behind the current implementation of 
> {{JexlScript.getVariables()}} method. From the documentation we know that the 
> result should be the set of script variables. For the code
> {code:java}
> a[b][c]{code}
> it gives three variables {{a}}, {{b}}, {{c}}. So far so good. But for the code
> {code:java}
> a[b]['c']{code}
> it returns {{a}} and {{b c}}, where second variable has two fragments {{b}} 
> and {{c}}. The documentation states that variables with multiple fragments 
> are ant-ish variables, but I don't have any of ant-ish variables in the 
> example, and {{'c'}} is not a variable, but a constant. I expect to get {{a}} 
> and {{b}} as a result.



--
This message was sent by Atlassian JIRA
(v7.6.3#76005)


[jira] [Commented] (JEXL-302) JexlScript.getVariables returns strange values for array access

2019-05-22 Thread Henri Biestro (JIRA)


[ 
https://issues.apache.org/jira/browse/JEXL-302?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel=16845983#comment-16845983
 ] 

Henri Biestro commented on JEXL-302:


I suspect your (failing) example is: why does {{a['b'][c]}} generate 
{{["a",”b"]}} and {{["c"]}} as the variable set of lists ?

This probably stems from the current behaviour where {[a.b]] is equivalent 
to{{a["b"]}} or {{a.0}} is equivalent to {{a[0]}}. There are plenty of tests in 
VarTests.testRef(...) that indicate the intent for getVariable to collect that 
equivalence.
It is guaranteed that the 1st member of each segment (list) is the name of a 
variable; one can consider the whole segment as the actual varying element ( as 
in a.b value changes with a and a.b ).
Does this make more sense?

> JexlScript.getVariables returns strange values for array access
> ---
>
> Key: JEXL-302
> URL: https://issues.apache.org/jira/browse/JEXL-302
> Project: Commons JEXL
>  Issue Type: Bug
>Affects Versions: 3.1
>Reporter: Dmitri Blinov
>Priority: Minor
>
> I can not understand the logic behind the current implementation of 
> {{JexlScript.getVariables()}} method. From the documentation we know that the 
> result should be the set of script variables. For the code
> {code:java}
> a[b][c]{code}
> it gives three variables {{a}}, {{b}}, {{c}}. So far so good. But for the code
> {code:java}
> a[b]['c']{code}
> it returns {{a}} and {{b c}}, where second variable has two fragments {{b}} 
> and {{c}}. The documentation states that variables with multiple fragments 
> are ant-ish variables, but I don't have any of ant-ish variables in the 
> example, and {{'c'}} is not a variable, but a constant. I expect to get {{a}} 
> and {{b}} as a result.



--
This message was sent by Atlassian JIRA
(v7.6.3#76005)