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] [Commented] (JEXL-256) Jexl should not try to resolve a variable from Context when Context.has() returns false
Date Sat, 07 Apr 2018 11:45:00 GMT

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

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

Side comment, ConcurrentHashMap throws NPE for null key on get .
Anyway, the current behavior is inspired by handling maps that allow null values; on get,
if the result is null, the only way to know why is to call containsKey. And this disambiguation
is not needed in the general most frequent case. Since determining if a key exists is as costly
as trying to get the value, the runtime cost / disputable functional gain seems unwarranted.
If you’ve noticed odd behaviors wrt antish vars, a test case would be much appreciated.

> 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)

Mime
View raw message