commons-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Colin Lear (JIRA)" <j...@apache.org>
Subject [jira] Created: (JEXL-26) ASTArrayAccess messes up on fallback to JexlContext
Date Sat, 04 Nov 2006 07:24:16 GMT
ASTArrayAccess messes up on fallback to JexlContext
---------------------------------------------------

                 Key: JEXL-26
                 URL: http://issues.apache.org/jira/browse/JEXL-26
             Project: Commons JEXL
          Issue Type: Bug
    Affects Versions: 1.1
         Environment: N/A
            Reporter: Colin Lear


When executing an expression if a null comes up (unresolved object) it attempts to build an
identifier to query the JexlContext directly. However it only works on sequential ASTIdentifier
nodes. If there is another sort of node then it ends up searching the JexlContext for a mangled
or malformed variable.

I think this is a bug because subobjects with properties or methods that are null can "inherit"
the value of objects or properties in the base JexlContext scope. It's too unpredictable to
be a legitimate feature.

for example in the expression: objects[23].status

if (objects[23] != null && objects[23].status == null) then it will search for the
bare expression "status" in the JexlContext. Ideally it would query the JexlContext map for
the full expression, however the details of that are difficult to implement and can produce
odd results.

Even worse with an expression like: base.objects[23].status.
if (base != null && base.objects[23] != null && base.objects[23].status ==
null) then this expression will evaluate look for "base.status" in the JexlContext map.

It currently works as expected for expressions like base.object.status by searching for "base.object.status"
in the JexlContext if status is null. Although I'm not entirely convinced that it is a good
idea to do this.

Simple Fix:

in ASTReference.java change the function getIdentifierToDepth() to return an empty string
if there are non ASTIdentifier Nodes in the expression (in my case it's ASTArrayAccess nodes).
This is the simplest solution and stops subobjects effectively assuming values of objects
in the base JexlContext while still allowing you to bind objects into the JexlContext with
identifiers with "." in the name.

So you could add "object.tracking.status" directly into the JexlContext and it would work.
However you couldn't add object.tracking[23].status because one of the Nodes is an ArrayAccess
node and it can't be translated back into a string by the current implementation.

/* patched function */

    private String getIdentifierToDepth(int i) {
        StringBuffer varName = new StringBuffer();
        for (int j = 0; j <= i; j++) {
            SimpleNode node = (SimpleNode) jjtGetChild(j);
            if (node instanceof ASTIdentifier) {
                varName.append(((ASTIdentifier) node).getIdentifierString());
                if (j != i) {
                    varName.append('.');
                }
            } else {
                /* expression is unresolvable and variable name is invalid */
                return "";
            }
        }
        return varName.toString();
    }

You could always add some code to support ASTArrayAccess nodes. However you'd also have to
support either evaluating, or reducing to a string, the index expression. Which is messy.

-- 
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators: http://issues.apache.org/jira/secure/Administrators.jspa
-
For more information on JIRA, see: http://www.atlassian.com/software/jira

        

---------------------------------------------------------------------
To unsubscribe, e-mail: commons-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-dev-help@jakarta.apache.org


Mime
View raw message