[
https://issues.apache.org/jira/browse/JEXL-256?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16435349#comment-16435349
]
Dmitri Blinov commented on JEXL-256:
------------------------------------
Thanks for suggestion. I'm going to use {{JexlException.Assignment}} as it more
close to the case. Now I think we may close the issue. Thanks for your time
once again!
> 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)