Description
sort()
does not work on arrays that contain null
values.
To Reproduce
Steps to reproduce the behavior:
- Perform a Transform on the following GREL expression
[ null, "E09000002", "E05000036", null, "E14000540", null, "E30000234", "E38000004" ].sort()
Current Results
In Expression preview the following is shown:
Error: java.lang.NullPointerException
Expected Behavior
sort()
should still work and perhaps default to nulls last as a convenience for users.
Optionally, a Boolean parameter could be added to sort()
for users to override the default nulls last behavior.
Screenshots
Versions
- Operating System: Windows 10
- Browser Version: Firefox latest
- JRE or JDK Version: JDK8
- OpenRefine: openrefine-3.4-beta-514-gaa43445
Datasets
Additional context
I think instead of defaulting to the NullPointerException, instead we could still allow sorting of arrays that contain null values and place nulls first or last with a new sort() Boolean parameter for nullsLast.
https://github.com/OpenRefine/OpenRefine/blob/master/main/src/com/google/refine/expr/functions/arrays/Sort.java#L55
To do that we could use java.util.Comparator https://www.tutorialspoint.com/How-to-sort-an-array-of-objects-containing-null-elements-in-java