Re: Odd observation during debugging

Christopher Schultz <[email protected]>
Newsgroups gmane.comp.jakarta.velocity.user
Message-ID <[email protected]>
Nathan,

On 7/11/12 12:28 PM, Nathan Bubna wrote:
> Just set:
> directive.if.tostring.nullcheck = false

As always, thanks for the quick, response. I had gotten this far in my
code reading:

ASTReference.evaluate():
    public boolean evaluate(InternalContextAdapter context)
        throws MethodInvocationException
    {
        Object value = execute(null, context);

        if (value == null)
        {
            return false;
        }
        else if (value instanceof Boolean)
        {
            if (((Boolean) value).booleanValue())
                return true;
            else
                return false;
        }
        else if (toStringNullCheck)
        {
            try
            {
                return value.toString() != null;
            }
            catch(Exception e)
            {
                throw new VelocityException("Reference evaluation threw
an exception at "
                    + Log.formatFileString(this), e);
            }
        }
        else
        {
            return true;
        }
    }

I was almost there when you wrote ;)

> See VELOCITY-731 and VELOCITY-692 and others...

Those were good to read: 1.6 introduced more consistent (if slower)
treatment of references and then a setting was added to get the old
behavior.

Any idea if a future version of Velocity (maybe 2.x) will have the
default value of that directive set to "false" so that toString will
only be called for users who actually want that?

While backward-compatibility is certainly a reasonable goal, this
behavior kind of sucks... and I can't really think of too many cases
where it makes sense. Good that there is a setting for it ;)

Thanks,
-chris
signature.asc (application/pgp-signature, 307 B)
-----BEGIN PGP SIGNATURE-----
Version: GnuPG/MacGPG2 v2.0.17 (Darwin)
Comment: GPGTools - http://gpgtools.org
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/

iEYEARECAAYFAk/9sKwACgkQ9CaO5/Lv0PA4ZQCdHliDKdH3L5CwAn3sD9qBsjIO
owIAniDCibmtqmN6/AV80Gc/Hvtd4KC4
=h4d2
-----END PGP SIGNATURE-----
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.