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

Henri Biestro commented on JEXL-256:
------------------------------------

I must be missing the point; the current code only checks 'has' if the 'get' 
returns null. This allows having only 1 call to 'get' in the general (non null) 
case. If your context returns a non-null value to a 'get' when it returns false 
for the same 'has' call, I'm tempted to say embed the logic in your context 
implementation...And we probably should document that there is an expectation 
that 'has' can not return false when 'get' does not return null.
I'm obviously not understanding your case correctly... :-/

> Jexl should not try to resolve a variable from Context when Context.has() 
> returns false
> ---------------------------------------------------------------------------------------
>
>                 Key: JEXL-256
>                 URL: https://issues.apache.org/jira/browse/JEXL-256
>             Project: Commons JEXL
>          Issue Type: Improvement
>    Affects Versions: 3.1
>            Reporter: Dmitri Blinov
>            Priority: Major
>
> I have bumped into the problem when my {{Context.get()}} sometimes reports 
> access to variables that are reported by the {{Context.has()}} method as not 
> existent, and are not supposed to be in the context, mainly parts of ant-ish 
> variable paths. I assume that once {{Context.has()}} have reported {{false}} 
> no attempt from the Jexl to call {{Context.get()}} with the same parameter 
> should be made.
> I think the problem lies in {{Interpreter.java}} which first calls 
> {{Context.get()}} and only if it returns null, which should not necceserily 
> mean the variable does not exist, checks {{Context.has()}}. 
> {code}
>     @Override
>     protected Object visit(ASTIdentifier node, Object data) {
>         cancelCheck(node);
>         String name = node.getName();
>         if (data == null) {
>             int symbol = node.getSymbol();
>             if (symbol >= 0) {
>                 return frame.get(symbol);
>             }
>             Object value = context.get(name);
>             if (value == null
>                     && !(node.jjtGetParent() instanceof ASTReference)
>                     && !context.has(name)
>                     && !node.isTernaryProtected()) {
>                 return unsolvableVariable(node, name, true);
>             }
>             return value;
>         } else {
>             return getAttribute(data, name, node);
>         }
>     }
> {code}
> So I suggest to change the code to something like this
> {code}
>     @Override
>     protected Object visit(ASTIdentifier node, Object data) {
>         cancelCheck(node);
>         String name = node.getName();
>         if (data == null) {
>             int symbol = node.getSymbol();
>             if (symbol >= 0) {
>                 return frame.get(symbol);
>             }
>             if (!context.has(name)
>                     && !(node.jjtGetParent() instanceof ASTReference)
>                     && !node.isTernaryProtected()) {
>                 return unsolvableVariable(node, name, true);
>             }
>             return context.get(name);
>         } else {
>             return getAttribute(data, name, node);
>         }
>     }
> {code}



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

Reply via email to