[jira] [Commented] (VELOCITY-911) Incorrect evaluation of IF-Directive for objects with isEmpty-method

2019-04-05 Thread Claude Brisson (JIRA)


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

Claude Brisson commented on VELOCITY-911:
-

Docs updated with your suggestions. The user guide now states:
{code}
...
- $foo is an object (other than a string, a number or a collection) which is 
not null (and for which the standard public methods for querying the object 
size, length or boolean/string representations, if they exist, indicate a 
non-empty, non-zero, non-false object).
...
{code}
 
and the #if directive configuration reference has been reworded as suggested.


> 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
>Assignee: Claude Brisson
>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



[jira] [Commented] (VELOCITY-911) Incorrect evaluation of IF-Directive for objects with isEmpty-method

2019-04-03 Thread Sergiu Dumitriu (JIRA)


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

Sergiu Dumitriu commented on VELOCITY-911:
--

[~luppim] I closed the issue because as it is stated, it is not valid. The 
evaluation is correct, according to the intended behavior.

If you feel that the documentation needs to be further enhanced to be less 
ambiguous about how being "empty" is defined, then feel free to create another 
issue.

About "and other objects that have a public isEmpty() method", this applies to 
all the other checks as well. In general, Velocity only calls public methods by 
default, so it's not relevant to mention that the method must be public here. 
And all method checks work simply by checking if such a method exists and is 
accessible, the actual type of the object isn't considered. I like your wording 
here: "$foo is an object with an isEmpty() method which evaluates to a true 
value". How about this instead: "$foo is an object with a public isEmpty() 
method which evaluates to true", and similar for all the other checks.

One option would be to put the longer technical description from the 
{{directive.if.empty_check}} definition into the {{If / ElseIf / Else}} 
definition in the user guide, but I feel that it is too technical for the user 
guide, which is supposed to be short and simple.

> 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
>Assignee: Claude Brisson
>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



[jira] [Commented] (VELOCITY-911) Incorrect evaluation of IF-Directive for objects with isEmpty-method

2019-04-03 Thread M. Luppi (JIRA)


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

M. Luppi commented on VELOCITY-911:
---

Thanks for your reply, [~claude]. I was aware of the 
_directive.if.emptycheck_-property that gives me the behavior of version 1.7. 
However, we would like to use this new feature in our project.

My suggestion is to extend and correct the documentation to reflect the actual 
behavior more accurately. This way the users get a clear reference and knows 
exactly how the engine evaluates objects in a boolean context. In fact, using 
such logic on custom objects is a (yet undocumented) feature and worth 
addressing. Maybe a remark concerning visibility (method needs to be public) 
would be appropriate as well.

Maybe something along the lines of in the user guide 
([http://velocity.apache.org/engine/2.1/user-guide.html#if-elseif-else]):
{panel}
 * ...
 * $foo is an object with a getAsBoolean() method which evaluates to a true 
value
 * $foo is an object with an isEmpty() method which evaluates to a true value
 * $foo is an object without a getAsBoolean() or isEmpty() method which is not 
null{panel}
I do not know about the precedence of getAsBoolean() and isEmpty() and whether 
getAsBoolean()==false would preemptively stop evaluation. So the above might 
not be correct and could need adjustment.

In the configuration page 
([https://velocity.apache.org/engine/2.1/configuration.html#if-directive]) this 
could look like this:
{panel}
 * ... 
 * return whether isEmpty() is false (covers String, all Collection classes and 
other objects that have a public isEmpty() method).
 * ...{panel}
Of course the cases with length() and size() should also be adopted if 
necessary. The getAsBoolean() is already well-documented there.


[~sdumitriu]: I do not understand why this issue was closed as "not a problem" 
at this point, unless I need to raise a new issue to address the documentation 
itself.

> 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
>Assignee: Claude Brisson
>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



[jira] [Commented] (VELOCITY-911) Incorrect evaluation of IF-Directive for objects with isEmpty-method

2019-04-01 Thread Claude Brisson (JIRA)


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

Claude Brisson commented on VELOCITY-911:
-

It is a documentation problem.

When evaluated in a boolean context, objects are tested with:
 * getAsBoolean() method if it exists
 * isEmpty() method if it exists

and although this is not explicitly stated in the docs, this is the expected 
behavior: when an object provides a mean to tell the outside world that it is 
empty, it generally means that it won't render anything.

If you want `#if($obj)` to return true while `$obj.isEmpty()` returns true, you 
can set:
{code:java}
directive.if.emptychek = false
{code}
in your velocity.properties file so that the behavior , or resort to a more 
explicit test like:
{code:java}
#if( $obj != $null )
{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