Rewrote JSON object loading to avoid throwing exception

Related to 68f90edb2f
This commit is contained in:
tastybento 2019-08-27 09:08:22 -07:00
parent ead0b02454
commit 52d0544726
2 changed files with 5 additions and 6 deletions

View File

@ -58,10 +58,12 @@ public class JSONDatabaseHandler<T> extends AbstractJSONDatabaseHandler<T> {
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.");

View File

@ -1,6 +1,3 @@
/**
*
*/
package world.bentobox.bentobox.database;
import static org.junit.Assert.assertEquals;