[
https://issues.apache.org/jira/browse/VELOCITY-731?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12757360#action_12757360
]
Nathan Bubna commented on VELOCITY-731:
---------------------------------------
Because Velocity originally decided to rely upon toString() solely, without
providing a fallback like a TemplateString interface or a check for a
getAsString method to allow alternative means of rendering, it became
impossible to implement a simple alternator that could also handle null values.
So any "smart" tool that wants to be asked about the validity of a reference
(i.e. #if) has no recourse but to return null in toString to indicate that its
current state is false/null/whatever. It is not possible for the "smart
reference" to remove/re-add itself and allow the mere context presence check to
communicate properly to #if. Again, the only recourse for such tools (and
VelocityTools has them, as well as my apps) is to return null in toString in
such cases.
The choices i've seen here are:
1: provide the config switch for those who have heavy toString calls to disable
this
2: return the previous inconsistent behavior that $foobar rendered null but
#if( $foobar ) registered as true and have the switch go the other way for
those who need consistent behavior
3: enforce that all tools respect java convention to throw exceptions if
toString returns null despite their usefulness within a different language
(VTL), thus breaking several VelocityTools classes.
4: implement a better solution (getAsString support)
#4 is my eventual goal in 2.0, if not earlier
#3 is unacceptable without changing major version number to indicate the BC
break, but if we're gonna do that, then we might as well do #4
#2 is not out of the question but quite distasteful, as we have already
released a final version that supports consistent behavior here
#1 seemed best for now
> Velocity 1.6 performance is degraded by introduced toString() calls
> -------------------------------------------------------------------
>
> Key: VELOCITY-731
> URL: https://issues.apache.org/jira/browse/VELOCITY-731
> Project: Velocity
> Issue Type: Bug
> Components: Engine
> Affects Versions: 1.6, 1.6.1, 1.6.2
> Environment: Apache Velocity 1.6.2
> Reporter: Jörgen Rydenius
> Fix For: 1.6.x, 1.7
>
> Attachments: configurable_tostring_nullcheck_patch.txt
>
>
> As part of VELOCITY-531, r686428 introduced frequent calls to toString() just
> to check if toString() != null. If toString() implementations are slightly
> complex, and very frequently executed, these calls will degrade the site
> performance. Are they at all necessary? What kind of object would use null as
> a return value for toString()? Is it possible to remove these toString()
> calls from the velocity code again?
--
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]