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

Renato Steiner commented on VELOCITY-553:
-----------------------------------------

I have noticed that Velocity makes a difference between accessing a property 
vs. accessing the property via a property accessor method:
Note: $util.isNull is a simple utility  method in one of the classes I 
unfortunately cannot attach. But you can simply create a utility method in one 
of your own classes which returns true if the params value is null.

=> The code below results in the invocation of 
InvalidReferenceEventHandler::invalidGetMethod(Context, String, Object, String, 
Info). 

         #set ($objRef = $util.getTestObject())
         #if ($util.isNull($objRef.nullValueAttribute))
            #debugMsg("@@util.isNull(objRef.nullValueAttribute) => 
isNull==true")
         #else
            #debugMsg("@@objRef.nullValueAttribute=$objRef.nullValueAttribute")
         #end

---------

=> The code below works correctly:

         #set ($objRef = $util.getTestObject())
         #if ($util.isNull($objRef.getNullValueAttribute()))
            #debugMsg("@@util.isNull(objRef.getNullValueAttribute()) => 
isNull==true")
         #else
            #debugMsg("@@objRef.nullValueAttribute=$objRef.nullValueAttribute")
         #end

---------

I have created and attached a new unit test which can be used to verify the 
desired behavior.
If the patch is applied, the InvalidEventHandlerTestCase.java test case should 
run without errors.
If you uncomment the documented code segments, errors will appear until the bug 
is fixed.

Notes: 
Single testcase execution (requires the patch: velocity-661-v1.0.patch -> 
http://issues.apache.org/jira/browse/VELOCITY-661)
$ ant -Dtestcase=org.apache.velocity.test.InvalidEventHandlerTestCase test

Related: 
http://issues.apache.org/jira/browse/VELOCITY-618
https://issues.apache.org/jira/browse/VELOCITY-423
http://wiki.apache.org/velocity/VelocityNullSupport

> Posibility to configure ReportInvalidReferences to don't report report 
> variables,properties and method which exist, but only have null value
> --------------------------------------------------------------------------------------------------------------------------------------------
>
>                 Key: VELOCITY-553
>                 URL: https://issues.apache.org/jira/browse/VELOCITY-553
>             Project: Velocity
>          Issue Type: Improvement
>          Components: Engine
>    Affects Versions: 1.5
>         Environment: any
>            Reporter: Tomáš Procházka
>             Fix For: 1.7
>
>         Attachments: InvalidEventHandlerTestCase.java.patch
>
>
> ReportInvalidReferences has very big imperfection, it report by default all 
> variables, properties and method which has null value.
> This may cause many problems for developer.
> I for example need only validate template without any data, only check which 
> contain right variables, properties or method (which exist), it's value is 
> not important for me.
> I tried use my own ReferenceInsertionEventHandler for replace null value with 
> "" (empty String) but Velocity call InvalidReference handler before 
> ReferenceInsertionEventHandler.
> I suggest configuration options for this (repor or doesn't report null value)

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