[ 
https://issues.apache.org/jira/browse/VELOCITY-911?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
 ]

M. Luppi updated VELOCITY-911:
------------------------------
    Description: 
With Velocity 2.0 the logic of evaluation for IF-Directives changed and now 
uses an extended approach to determine whether it is true. This bug report only 
refers to the case where $foo is an +object+. The documentation for 2.0 and 2.1 
state as follows:
{quote}The variable $foo is evaluated to determine whether it is true, which 
will happen under one of those circumstances: [...]
 $foo is an object (other than a string, a number or a collection) which is not 
null

_Source: 
[http://velocity.apache.org/engine/2.0/user-guide.html#if-elseif-else|http://velocity.apache.org/engine/2.0/user-guide.html#if-elseif-else]_
{quote}
After a long debugging session I have found that objects with a public 
isEmpty-method are not being handled according to the documentation cited 
above. Thereby, such objects are evaluated as false if there is an 
isEmpty-method that returns false. The correct evaluation result according to 
the documentation should be true since the object is not null and not a string, 
a number or a collection.

It gets even more confusing when we take access modifiers into account. If the 
access of the isEmpty-method is not public, the behaviour is as it should be. 
When we make it public, however, the above explained bug occurs in version 2.0 
as well as 2.1.

See the attached classes and the template or the whole project of the MCVE 
(minimal, complete, and verifiable example) as ZIP.

_The output of the test is as follows:_
{code:java}
null object
-----------
[ OK ] Expected.


non-null object with isEmpty-method (public)
--------------------------------------------
isEmpty evaluates to true
[FAIL] Not expected since object is not null.

isEmpty evaluates to false
[ OK ] Expected.


non-null object with isEmpty-method (package-private)
-----------------------------------------------------
isEmpty evaluates to true
[ OK ] Expected.

isEmpty evaluates to false
[ OK ] Expected.
{code}

  was:
With Velocity 2.0 the logic of evaluation for IF-Directives changed and now 
uses an extended approach to determine whether it is true. This bug report only 
refers to the case where $foo is an +object+. The documentation for 2.0 and 2.1 
state as follows:
{quote}The variable $foo is evaluated to determine whether it is true, which 
will happen under one of those circumstances: [...]
 $foo is an object (other than a string, a number or a collection) which is not 
null

_Source: 
[http://velocity.apache.org/engine/2.0/user-guide.html#if-elseif-else|http://velocity.apache.org/engine/2.0/user-guide.html#if-elseif-else_]_
{quote}
After a long debugging session I have found that objects with a public 
isEmpty-method are not being handled according to the documentation cited 
above. Thereby, such objects are evaluated as false if there is an 
isEmpty-method that returns false. The correct evaluation result according to 
the documentation should be true since the object is not null and not a string, 
a number or a collection.

It gets even more confusing when we take access modifiers into account. If the 
access of the isEmpty-method is not public, the behaviour is as it should be. 
When we make it public, however, the above explained bug occurs in version 2.0 
as well as 2.1.

See the attached classes and the template or the whole project of the MCVE 
(minimal, complete, and verifiable example) as ZIP.

_The output of the test is as follows:_
{code:java}
null object
-----------
[ OK ] Expected.


non-null object with isEmpty-method (public)
--------------------------------------------
isEmpty evaluates to true
[FAIL] Not expected since object is not null.

isEmpty evaluates to false
[ OK ] Expected.


non-null object with isEmpty-method (package-private)
-----------------------------------------------------
isEmpty evaluates to true
[ OK ] Expected.

isEmpty evaluates to false
[ OK ] Expected.
{code}


> Incorrect evaluation of IF-Directive for objects with isEmpty-method
> --------------------------------------------------------------------
>
>                 Key: VELOCITY-911
>                 URL: https://issues.apache.org/jira/browse/VELOCITY-911
>             Project: Velocity
>          Issue Type: Bug
>    Affects Versions: 2.0, 2.1
>            Reporter: M. Luppi
>            Priority: Major
>         Attachments: VelocityIsEmptyBugMCVE.java, mcve-project.zip, 
> template.vm
>
>
> With Velocity 2.0 the logic of evaluation for IF-Directives changed and now 
> uses an extended approach to determine whether it is true. This bug report 
> only refers to the case where $foo is an +object+. The documentation for 2.0 
> and 2.1 state as follows:
> {quote}The variable $foo is evaluated to determine whether it is true, which 
> will happen under one of those circumstances: [...]
>  $foo is an object (other than a string, a number or a collection) which is 
> not null
> _Source: 
> [http://velocity.apache.org/engine/2.0/user-guide.html#if-elseif-else|http://velocity.apache.org/engine/2.0/user-guide.html#if-elseif-else]_
> {quote}
> After a long debugging session I have found that objects with a public 
> isEmpty-method are not being handled according to the documentation cited 
> above. Thereby, such objects are evaluated as false if there is an 
> isEmpty-method that returns false. The correct evaluation result according to 
> the documentation should be true since the object is not null and not a 
> string, a number or a collection.
> It gets even more confusing when we take access modifiers into account. If 
> the access of the isEmpty-method is not public, the behaviour is as it should 
> be. When we make it public, however, the above explained bug occurs in 
> version 2.0 as well as 2.1.
> See the attached classes and the template or the whole project of the MCVE 
> (minimal, complete, and verifiable example) as ZIP.
> _The output of the test is as follows:_
> {code:java}
> null object
> -----------
> [ OK ] Expected.
> non-null object with isEmpty-method (public)
> --------------------------------------------
> isEmpty evaluates to true
> [FAIL] Not expected since object is not null.
> isEmpty evaluates to false
> [ OK ] Expected.
> non-null object with isEmpty-method (package-private)
> -----------------------------------------------------
> isEmpty evaluates to true
> [ OK ] Expected.
> isEmpty evaluates to false
> [ OK ] Expected.
> {code}



--
This message was sent by Atlassian JIRA
(v7.6.3#76005)

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscr...@velocity.apache.org
For additional commands, e-mail: dev-h...@velocity.apache.org

Reply via email to