commons-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Eric Gravel" <Eric.Gra...@intervalintl.com>
Subject [jexl] Question about checking for undefined properties versus null value properties
Date Mon, 30 Apr 2012 22:26:06 GMT
I'm in the process of improving the details of our logs when an error is
encountered when compiling or evaluating a JEXL.  I'm mainly outputting
the JexlException information, what the script was, what objects were in
the context; that kind of stuff.  To do this, I decided to let
JexlEngine throw exceptions but setting lenient to false (strict-mode)
and silent to true (I want my code to be the only part output to the
log).

 

One side effect of doing this has been that if a property return null,
the engine seems to think it's an undefined property.  Is there no way
to have JexlEngine only throw an exception if a property is undefined
when strict-mode is on?

 

 

Looking through the code, I believe this difficulty arises from
visit(ASTReference).  Btw, my simply jexl was something like
"journal.serviceAmount != null"  since we use BigDecimale objects.  

 

In visit(ASTReference), in Interpreter class, there is this block of
code towards the end:

 

        if (result == null) {

            if (isVariable && !isTernaryProtected(node)

                    // variable unknow in context and not (from) a
register

                    && !(context.has(variableName.toString())

                    || (numChildren == 1

                    && node.jjtGetChild(0) instanceof ASTIdentifier

                    && ((ASTIdentifier)
node.jjtGetChild(0)).getRegister() >= 0))) {

                JexlException xjexl = propertyName != null

                                      ? new JexlException.Property(node,
propertyName)

                                      : new JexlException.Variable(node,
variableName.toString());

                return unknownVariable(xjexl);

            }

        }

 

This will be triggered since my 2 child node (ASTIdentifier for
serviceAmount) will return null when the journal object's
getServiceAmount() is called and its null value is returned.  So since
it is null, isVariable is true, no Ternary node, property is not in jexl
context, there's 2 children, this throws exception.

 

It would seem to me that this visit() should be able to differentiate
between a null value property and an undefined property.  Could we store
a Boolean of whether a PropertyGet object is retrieved by
uberspect.getProperty(), which is called in getAttribute() from
visit(ASTIdentifier), and then modify the IF mentioned earlier to says
!hasGetterMethod so that it only throws if the null wasn't linked to a
Getter method?

 

 

Thoughts?

 

 

Eric A. Gravel

Application Architect - IT Application Services

Interval International

6262 Sunset Drive * Miami, Florida 33143

305.666.1861, ext. 7315 * fax 305.668.3409

eric.gravel@intervalintl.com <mailto:eric.gravel@intervalintl.com> 

IntervalWorld.com * ResortDeveloper.com

Please consider the environment before printing this e-mail.

 


_____________________________________________________________________________
Scanned by IBM Email Security Management Services powered by MessageLabs. For more information
please visit http://www.ers.ibm.com
_____________________________________________________________________________
Mime
  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message