On 10/29/10 5:31 PM, Felix Knecht wrote:
Imagine following test:

String str="(objectClass=)";
ExprNode node = FilterParser.parse( str );
assertEquals( str, node.toString() );

This test will fail ATM because we do
'return value == null ? "null" : value;'

In fact, the node.toString() is throwing a NPE. There are two problems here : - first we don't check that the wrapped value is null before returning an escapedValue when we try to create one => NPE - second, if we do, as the Value will be null, the toString() applied on this value will return "null".

So what's closer to what we really want to show?
We should fix the filter toString() method plus the AbstractExprNode escapeFilterValue() method :

    protected static Value<?> escapeFilterValue( Value<?> value )
    {
        if ( value.isNull() )
        {
            return value;
        }
...

and in EqualityNode :

    public String toString()
    {
        StringBuilder buf = new StringBuilder();

        buf.append( '(' );

...
        Value<?> escapedValue = getEscapedValue();

        buf.append( "=" );

        if ( !escapedValue.isNull() )
        {
            buf.append( escapedValue );
        }

Note that it won't be enough. We have to do the same thing in other XXXNode classes.


--
Regards,
Cordialement,
Emmanuel Lécharny
www.iktek.com

Reply via email to