From eb8f0edd4d60a3a68d6c8cd8305c8a4120e3e94f Mon Sep 17 00:00:00 2001 From: Ben Fry Date: Wed, 2 May 2018 11:03:12 -0400 Subject: [PATCH] prevent Table.sort() from throwing NPE with empty cells --- core/src/processing/data/Table.java | 10 +++++++++- core/todo.txt | 1 + 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/core/src/processing/data/Table.java b/core/src/processing/data/Table.java index 7d8f03d48..4d18651cc 100644 --- a/core/src/processing/data/Table.java +++ b/core/src/processing/data/Table.java @@ -4350,7 +4350,15 @@ public class Table { double diffd = getDouble(a, column) - getDouble(b, column); return diffd == 0 ? 0 : (diffd < 0 ? -1 : 1); case STRING: - return getString(a, column).compareToIgnoreCase(getString(b, column)); + String string1 = getString(a, column); + if (string1 == null) { + string1 = ""; // avoid NPE when cells are left empty + } + String string2 = getString(b, column); + if (string2 == null) { + string2 = ""; + } + return string1.compareToIgnoreCase(string2); case CATEGORY: return getInt(a, column) - getInt(b, column); default: diff --git a/core/todo.txt b/core/todo.txt index 503514e2a..8df149b5f 100644 --- a/core/todo.txt +++ b/core/todo.txt @@ -10,6 +10,7 @@ X sort only uses the sign of the value X more accurate than float, especially when using double and long values X consistently implement write(PrintWriter) in the List and Dict classes X add save(File) to the List and Dict classes +X prevent Table.sort() from throwing NPE with empty cells _ Dict.remove() should return value, not index (for consistency w/ others) _ check again whether element 0,0 in a Table is working _ https://github.com/processing/processing/issues/3011