[ 
http://issues.apache.org/jira/browse/VELOCITY-375?page=comments#action_12329862 
] 

Henning Schmiedehausen commented on VELOCITY-375:
-------------------------------------------------

The problem here is pretty much obvious: The whole toolbox loading mechanism 
flies without any checks for valid parameters and objects. I was pretty 
surprised to see when I looked at the toolbox loading code.

Attached is a patch which got some testing (I've tested out the border 
conditions of empty tool, tool without class, tool without name etc) and that 
should report errors and keep incomplete tools out of the toolbox). It does the 
following thing:

- Split up the adding of "real" tools and data objects in the ToolboxManager. 
It adds a method addData() to the ToolboxManager interface and also makes sure
   that the digester rules call addData() when a data object is added to the 
toolbox. Also added implementations to XMLToolboxManager and
   ServletToolboxManager

- adds a ToolInfo validation routine to XMLToolboxManager which checks whether 
a ToolInfo has a valid key (non-empty) and also a class set. Use this 
  validation method throughout the toolbox managers to check the ToolInfo 
objects before adding

- clean up setClassname()/getClassname() in ViewToolInfo

- Rework the object promotion logic in DataInfo to make sure that the internal 
state of the object is always valid (even directly after object creation and
   without calling any setters by the digester. This makes even incompletely 
configured data objects valid (though probably useless))

I also made sure that most methods that I've touched behave sanely when null 
objects are passed and also make sure that no internal objects are dereferenced 
that might be null. Lots of this code simply throws NPE on simple configuration 
errors, which is not only misleading (some of these errors don't happen at 
obvious locations and you would need internal knowledge of velocity-tools to 
understand why the error was thrown. 

I know that this patch is a bit largeish but it definitely improves the 
behaviour of Velocity Tools (and also fixes VELOCITY-375, it now throws an 
error in the log file) and it is also pretty obvious in what it does. Nathan, 
please apply. :-)

> bad errors description
> ----------------------
>
>          Key: VELOCITY-375
>          URL: http://issues.apache.org/jira/browse/VELOCITY-375
>      Project: Velocity
>         Type: Improvement
>   Components: Tools
>     Versions: 1.1
>  Environment: Operating System: All
> Platform: All
>     Reporter: Stepan Koltsov
>     Priority: Minor
>      Fix For: Tools-1.2
>  Attachments: velocity-tools.patch
>
> Hello,
> I've created toolbox.xml like this:
> <toolbox><tool/></toolbox>
> (yes, empty <tool/> tag). I got exception
> java.lang.NullPointerException
> org.apache.velocity.tools.view.ViewToolInfo.getInstance(ViewToolInfo.java:115)
> org.apache.velocity.tools.view.servlet.ServletToolboxManager.getToolboxContext(ServletToolboxManager.java:354)
> org.springframework.web.servlet.view.velocity.VelocityToolboxView.createVelocityContext(VelocityToolboxView.java:106)
> ...
> Yes, I know, it's my fault, but I think that errors in toolbox.xml should be
> 1. Not fatal;
> 2. Should be better explained.
> I used velocity-tools-1.1.
> And also I have a request -- could you please compile velocity-tools with
> debugging info? I had to compile velocity-tools by myself to find error. (I 
> did
> this before I've looked at my toolbox.xml :-)
> Thanks.

-- 
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators:
   http://issues.apache.org/jira/secure/Administrators.jspa
-
For more information on JIRA, see:
   http://www.atlassian.com/software/jira


---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to