You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@groovy.apache.org by "Alexander Franke (JIRA)" <ji...@apache.org> on 2016/07/07 07:33:11 UTC
[jira] [Created] (GROOVY-7882) NullPointerException in
List.toUnique if one element is null
Alexander Franke created GROOVY-7882:
----------------------------------------
Summary: 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
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.
```
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)
```
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]
```
--
This message was sent by Atlassian JIRA
(v6.3.4#6332)