[
https://issues.apache.org/jira/browse/GROOVY-10318?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17430771#comment-17430771
]
Eric Milles commented on GROOVY-10318:
--------------------------------------
The expression "it.key.toString() !in ['class']" produces a java.lang.String
instance. Then when this is coerced to a java.lang.Boolean, you get true
because it is non-empty. You can work around this issue with:
{code:groovy}
Boolean.valueOf(it.key.toString() !in ['class'])
{code}
> Weird behavior of !in operator
> ------------------------------
>
> Key: GROOVY-10318
> URL: https://issues.apache.org/jira/browse/GROOVY-10318
> Project: Groovy
> Issue Type: Bug
> Affects Versions: 3.0.9
> Reporter: Damir Murat
> Assignee: Eric Milles
> Priority: Major
>
> After upgrading to 3.0.9, I've noticed some unexpected behavior around the
> "!in" operator. Consider the following example:
> {code:java}
> import groovy.transform.CompileStatic
> @CompileStatic
> class MyPogo {
> String firstName
> String lastName
> }
> @CompileStatic
> class Test {
> void testMe() {
> MyPogo myPogo = new MyPogo(firstName: "My First Name", lastName: "My Last
> Name")
> Map<String, ?> filteredProperties = myPogo.properties.findAll {
> Boolean result = it.key as String !in ["class"]
> result
> }
> println filteredProperties
> assert filteredProperties.size() == 2
>
> filteredProperties = myPogo.properties.findAll {
> (it.key as String !in ["class"]) as Boolean
> }
> println filteredProperties
> assert filteredProperties.size() == 2
>
> filteredProperties = myPogo.properties.findAll {
> it.key as String !in ["class"]
> }
> println filteredProperties
> assert filteredProperties.size() == 2
> }
> }
> new Test().testMe()
> {code}
> When running it in GroocyConsole, the third assertion will fail without
> apparent reason.
> It looks like for "!in" to work correctly, some additional operation is
> required.
> The same code works for the 3.0.8 and 3.0.7 versions.
> Tnx
--
This message was sent by Atlassian Jira
(v8.3.4#803005)