Skip to content

GREL sort() throws NullPointerException when used on arrays that contain nulls #3152

Closed
@thadguidry

Description

@thadguidry

sort() does not work on arrays that contain null values.

To Reproduce

Steps to reproduce the behavior:

  1. 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

Metadata

Metadata

Assignees

Labels

Type: BugIssues related to software defects or unexpected behavior, which require resolution.grelThe default expression language, GREL, could be improved in many ways!

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions