commons-issues mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Henri Biestro (JIRA)" <j...@apache.org>
Subject [jira] [Comment Edited] (JEXL-225) Incorrect invoking methods with ObjectContext
Date Sat, 27 May 2017 08:55:04 GMT

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

Henri Biestro edited comment on JEXL-225 at 5/27/17 8:54 AM:
-------------------------------------------------------------

ObjectContext is not really meant to work with a map as inner object; the 'has' method in
particular is not precise enough in this case since it only verifies it can muster a JexlPropertyGet.
That is fine for getting an actual bean/property but in case of a map, we'd need to call containsKey.
Anyhow, we try to resolve a variable ('bar'), think we can ('has') and get a null and fail.


It seems it would be easier in the current case to just develop a tailored JexlContext.



was (Author: henrib):
ObjectContext is not really meant to work with a map as inner object; the 'has' method in
particular is not 'precise' enough since it only verifies it can muster a JexlPropertyGet.


> Incorrect invoking methods with ObjectContext
> ---------------------------------------------
>
>                 Key: JEXL-225
>                 URL: https://issues.apache.org/jira/browse/JEXL-225
>             Project: Commons JEXL
>          Issue Type: Bug
>    Affects Versions: 3.1
>            Reporter: Vyacheslav Shago
>            Assignee: Henri Biestro
>
> After apply fix in [JEXL-190|https://issues.apache.org/jira/browse/JEXL-190] folowing
code doesn't work anymore:
> {code}
> public class Example {
>     public static void main(String[] args) {
>         JexlEngine jexl = new JexlBuilder().create();
>         ObjectContext<Foo> context = new ObjectContext<>(jexl, new Foo());
>         JexlExpression expression = jexl.createExpression("bar()");
>         System.out.println(expression.evaluate(context));
>     }
>     public static class Foo extends HashMap<String, Object>{
>         public String bar(){
>             return "bar";
>         }
>     }
> }
> {code}
> Also doesn't work this code:
> {code}
> public class Example {
>     public static void main(String[] args) {
>         HashMap<String, Object> functions = new HashMap<>();
>         functions.put(null, new DefaultFunctions());
>         JexlEngine jexl = new JexlBuilder()
>                 .namespaces(functions)
>                 .create();
>         ObjectContext<Object> context = new ObjectContext<>(jexl, new Object());
>         JexlExpression expression = jexl.createExpression("bar()");
>         System.out.println(expression.evaluate(context));
>     }
>     public static class DefaultFunctions {
>         public String bar(){
>             return "bar";
>         }
>     }
> }
> {code}
> Output:
> {code}
> Example.main@1:4 unsolvable function/method 'bar'
> {code}
> note: with MapContext all working correct



--
This message was sent by Atlassian JIRA
(v6.3.15#6346)

Mime
View raw message