Dmitri Blinov created JEXL-256:
----------------------------------
Summary: 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
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.get()}}.
{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)