You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@groovy.apache.org by "Paul King (JIRA)" <ji...@apache.org> on 2016/07/13 10:21:20 UTC

[jira] [Resolved] (GROOVY-7882) NullPointerException in List.toUnique if one element is null

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

Paul King resolved GROOVY-7882.
-------------------------------
    Resolution: Won't Fix
      Assignee: Paul King

I'll close this for now but if you still feel strongly that the existing behavior is too unintuitive or if you feel the javadoc is too unclear, please reopen. PR's welcome too! :-)

> NullPointerException in List.toUnique if one element is null
> ------------------------------------------------------------
>
>                 Key: GROOVY-7882
>                 URL: https://issues.apache.org/jira/browse/GROOVY-7882
>             Project: Groovy
>          Issue Type: Bug
>          Components: groovy-runtime
>    Affects Versions: 2.4.7
>         Environment: Mac OS X 10.11.5, Groovy 2.4.7 installed via sdkman
>            Reporter: Alexander Franke
>            Assignee: Paul King
>
> When using toUnique() on a List I was encountering a NullPointerException when one of the elements is null. This does not happen when using .unique() which is a quite odd behavior. So except from one being in-place and the other returning the sorted List I would expect the same result from both methods. 
> Following is the output from GroovyConsole that shows the issue.
> {code}
> groovy> List a = [1,4,2,3,3,2,1,4, null] 
> groovy> List b = [1,4,2,3,3,2,1,4, null] 
> groovy> println a.unique() 
> groovy> println a 
> groovy> println b.toUnique() 
> groovy> println b 
>  
> [1, 4, 2, 3, null]
> [1, 4, 2, 3, null]
> Exception thrown
> java.lang.NullPointerException
> 	at ConsoleScript6.run(ConsoleScript6:6)
> {code}
> {code}
> // Interestingly enough, using .toUnique { it } gives the proper result: 
> groovy> List b = [1,4,2,3,3,2,1,4, null] 
> groovy> println b.toUnique { it } 
> groovy> println b 
>  
> [1, 4, 2, 3, null]
> [1, 4, 2, 3, 3, 2, 1, 4, null]
> {code}



--
This message was sent by Atlassian JIRA
(v6.3.4#6332)