Added null checks.

This commit is contained in:
tastybento 2018-02-06 13:33:08 -08:00
parent 1ddf706c68
commit f7c4e5a988

View File

@ -219,7 +219,12 @@ public class FlatFileDatabaseHandler<T> extends AbstractDatabaseHandler<T> {
// TODO: this may not work with all keys. Further serialization may be required.
Map<Object,Object> value = new HashMap<Object, Object>();
for (String key : config.getConfigurationSection(storageLocation).getKeys(false)) {
// Keys cannot be null - skip if they exist
Object mapKey = deserialize(key,Class.forName(keyType.getTypeName()));
if (mapKey == null) {
continue;
}
// Map values can be null - it is allowed here
Object mapValue = deserialize(config.get(storageLocation + "." + key), Class.forName(valueType.getTypeName()));
if (DEBUG) {
plugin.getLogger().info("DEBUG: mapKey = " + mapKey + " (" + mapKey.getClass().getCanonicalName() + ")");
@ -460,6 +465,10 @@ public class FlatFileDatabaseHandler<T> extends AbstractDatabaseHandler<T> {
if (value != null)
plugin.getLogger().info("DEBUG: value class is " + value.getClass().getCanonicalName());
}
// If value is already null, then it can be nothing else
if (value == null) {
return null;
}
if (value instanceof String && value.equals("null")) {
// If the value is null as a string, return null
return null;