From a8275f1011104b2dc55bd7836e5b8bd3d5208ece Mon Sep 17 00:00:00 2001 From: Philip Durbin Date: Tue, 24 Jan 2017 12:51:18 -0500 Subject: [PATCH] prevent NullPointerException #1612 #2290 --- .../datasetutility/OptionalFileParams.java | 2 +- .../OptionalFileParamsTest.java | 23 +++++++++++++++++-- 2 files changed, 22 insertions(+), 3 deletions(-) diff --git a/src/main/java/edu/harvard/iq/dataverse/datasetutility/OptionalFileParams.java b/src/main/java/edu/harvard/iq/dataverse/datasetutility/OptionalFileParams.java index c2da395d979..f58d9412011 100644 --- a/src/main/java/edu/harvard/iq/dataverse/datasetutility/OptionalFileParams.java +++ b/src/main/java/edu/harvard/iq/dataverse/datasetutility/OptionalFileParams.java @@ -147,7 +147,7 @@ public List getDataFileTags(){ private void loadParamsFromJson(String jsonData) throws DataFileTagException{ msgt("jsonData: " + jsonData); - if (jsonData == null){ + if (jsonData == null || jsonData.isEmpty()){ return; // logger.log(Level.SEVERE, "jsonData is null"); } diff --git a/src/test/java/edu/harvard/iq/dataverse/datasetutility/OptionalFileParamsTest.java b/src/test/java/edu/harvard/iq/dataverse/datasetutility/OptionalFileParamsTest.java index 02b435aa7fe..a2ea216f6df 100644 --- a/src/test/java/edu/harvard/iq/dataverse/datasetutility/OptionalFileParamsTest.java +++ b/src/test/java/edu/harvard/iq/dataverse/datasetutility/OptionalFileParamsTest.java @@ -199,8 +199,27 @@ public void test_09_unusedParamsGood() throws DataFileTagException { assertFalse(instance.hasFileDataTags()); } - - + + @Test + public void test_10_emptyString() throws DataFileTagException { + + msgt("test_10_emptyString"); + + String jsonParams = ""; + + OptionalFileParams instance = new OptionalFileParams(jsonParams); + + assertNull(instance.getDescription()); + assertFalse(instance.hasDescription()); + + assertNull(instance.getCategories()); + assertFalse(instance.hasCategories()); + + assertNull(instance.getDataFileTags()); + assertFalse(instance.hasFileDataTags()); + + } + private void msg(String s){ System.out.println(s); }