[ 
https://issues.apache.org/jira/browse/VELOCITY-656?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12655308#action_12655308
 ] 

Byron Foster commented on VELOCITY-656:
---------------------------------------

This issue came up when referring to a Hibernate object wrapped with a proxy 
object which is a standard pattern that Hibernate uses for working with POJOs.  
 If any methods are called on the proxy outside of the originating Hibernate 
session, then Hibernate throws the dreaded LazyIntializationException, this 
includes the toString() method.  The stack trace in this case is deep within 
Hibernate.  

I guess I have two points, the first is that I think that Velocity should 
always report accurately where in a template a problem has occurred. The 
second, as far as I know, currently any error encountered while processing a 
template generates some sort of velocity exception, and the location of the 
problem within the template file is reported in the exception message.  This 
patch was attempting to be consistent with that trend. 

My only concern with calling toString() is that on some object this may be 
non-trivial, and may be surprising behavior from #if($foo).  But, it's probably 
not a big deal.

Let me know if you think another approach would be better, and I'll provide a 
new patch.  I don't think this has a high priority which is why I marked it as 
an improvement, so I don't think it's necessary for 1.6.1.

> Wrap ref evaluate exception so vm location is revealed
> ------------------------------------------------------
>
>                 Key: VELOCITY-656
>                 URL: https://issues.apache.org/jira/browse/VELOCITY-656
>             Project: Velocity
>          Issue Type: Improvement
>    Affects Versions: 1.6.1
>            Reporter: Byron Foster
>         Attachments: 656.patch
>
>
> The following VTL calls the toString() method on the object in $foo:
> #if($foo)#end  
> If the toString() method throws an exception, the exception is thrown all the 
> way out of velocity without any indication of where the vtl reference 
> occurred.  This patch wraps the exception with a VelocityException with a 
> message that indicates the location of the offending reference.
> However, I wonder why toString() is called at all...  the code tests for 
> toString() == null and returns false if so, and true otherwise in the above 
> example vtl.  Why is this test necessary, and why isn't just a non-null 
> object enough for testing?

-- 
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]

Reply via email to