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

Dmitri Blinov commented on JEXL-256:
------------------------------------

I have figured out how to overcome this issue without changing Jexl, I simply 
need to restrict the usage of context variable names that, in my case, are 
well-known prefixes of my ant-ish variables, which makes sence to do anyway. 
So, for example, when {{java.lang.Double}} is need to be resolved, I should 
restrict the use of {{java}} variable name, and return {{null}} in {{get()}} 
and {{false}} in {{has()}}. The only problem now is that I also want to restict 
assigning anything to such a variable, so {{java = 1}} would be illegal to use 
inside script. I tried to throw {{IllegalArgumentException}} inside 
{{Context.set()}} but somehow Jexl does not catch this and passes this 
exception without wrapping it with JexlException, which makes me suspect this 
is not right thing to do. Is there a better way we can prevent context from 
setting values to certain names?

> 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