From 52d0544726bfcec04da757ead73320b01f15a0c9 Mon Sep 17 00:00:00 2001 From: tastybento Date: Tue, 27 Aug 2019 09:08:22 -0700 Subject: [PATCH] Rewrote JSON object loading to avoid throwing exception Related to 68f90edb2fc74c24527015dbeb57704c8bfe1fb3 --- .../bentobox/database/json/JSONDatabaseHandler.java | 8 +++++--- .../world/bentobox/bentobox/database/DatabaseTest.java | 3 --- 2 files changed, 5 insertions(+), 6 deletions(-) diff --git a/src/main/java/world/bentobox/bentobox/database/json/JSONDatabaseHandler.java b/src/main/java/world/bentobox/bentobox/database/json/JSONDatabaseHandler.java index 9ec4dfc73..3b8cb8a15 100644 --- a/src/main/java/world/bentobox/bentobox/database/json/JSONDatabaseHandler.java +++ b/src/main/java/world/bentobox/bentobox/database/json/JSONDatabaseHandler.java @@ -58,10 +58,12 @@ public class JSONDatabaseHandler extends AbstractJSONDatabaseHandler { for (File file: Objects.requireNonNull(tableFolder.listFiles((dir, name) -> name.toLowerCase(Locale.ENGLISH).endsWith(JSON)))) { try (FileReader reader = new FileReader(file)){ T object = getGson().fromJson(reader, dataObject); - if (object == null) { - throw new IOException("JSON file created a null object: " + file.getPath()); + if (object != null) { + list.add(object); + } else { + plugin.logError("JSON file created a null object: " + file.getPath()); + reader.close(); } - list.add(object); } catch (FileNotFoundException e) { plugin.logError("Could not load file '" + file.getName() + "': File not found."); diff --git a/src/test/java/world/bentobox/bentobox/database/DatabaseTest.java b/src/test/java/world/bentobox/bentobox/database/DatabaseTest.java index 2342bc6f2..fb74ac9f5 100644 --- a/src/test/java/world/bentobox/bentobox/database/DatabaseTest.java +++ b/src/test/java/world/bentobox/bentobox/database/DatabaseTest.java @@ -1,6 +1,3 @@ -/** - * - */ package world.bentobox.bentobox.database; import static org.junit.Assert.assertEquals;