From 8274b210ffc58a2d88eb6766a935ae01aaa4f2e5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Magnus=20Ulf=20J=C3=B8rgensen?= Date: Sat, 14 Apr 2018 11:27:11 +0200 Subject: [PATCH] Fix migration of EntityInternalMap --- .../massivecore/store/migrator/MigratorUtil.java | 16 ++++++++++++++-- .../massivecore/util/ReflectionUtil.java | 2 ++ 2 files changed, 16 insertions(+), 2 deletions(-) diff --git a/src/com/massivecraft/massivecore/store/migrator/MigratorUtil.java b/src/com/massivecraft/massivecore/store/migrator/MigratorUtil.java index d8f7a72c..baf62003 100644 --- a/src/com/massivecraft/massivecore/store/migrator/MigratorUtil.java +++ b/src/com/massivecraft/massivecore/store/migrator/MigratorUtil.java @@ -2,11 +2,13 @@ package com.massivecraft.massivecore.store.migrator; import com.massivecraft.massivecore.collections.MassiveList; import com.massivecraft.massivecore.collections.MassiveMap; +import com.massivecraft.massivecore.store.EntityInternalMap; import com.massivecraft.massivecore.util.ReflectionUtil; import com.massivecraft.massivecore.util.Txt; import com.massivecraft.massivecore.xlib.gson.JsonElement; import com.massivecraft.massivecore.xlib.gson.JsonObject; import com.massivecraft.massivecore.xlib.gson.annotations.SerializedName; +import com.massivecraft.massivecore.xlib.gson.reflect.TypeToken; import org.bukkit.inventory.Inventory; import java.lang.reflect.Field; @@ -138,6 +140,15 @@ public class MigratorUtil // GET public static Type getJsonRepresentation(Type actualType) { + if (actualType instanceof ParameterizedType && ((ParameterizedType) actualType).getRawType().equals(EntityInternalMap.class)) + { + ParameterizedType parameterizedType = (ParameterizedType) actualType; + Type valueType = parameterizedType.getActualTypeArguments()[0]; + Type keyType = String.class; + return TypeToken.getParameterized(Map.class, keyType, valueType).getType(); + } + + if (!jsonRepresentation.containsKey(actualType)) { return actualType; @@ -237,13 +248,13 @@ public class MigratorUtil public static boolean migrateFields(Type type, JsonObject object) { - if (type == null) throw new NullPointerException("entityClass"); + if (type == null) throw new NullPointerException("type"); if (object == null) throw new NullPointerException("object"); Class entityClass = getClassType(type); // We can't lookup the generic type of a map, so trying to convert the fields is useless - // Furthermore maps are stored as jsopnobjects, and we can't treat them like other objects + // Furthermore maps are stored as jsonobjects, and we can't treat them like other objects // because their "fields" are dynamically made and can't be looked up with reflection if (Map.class.isAssignableFrom(entityClass)) return false; @@ -266,6 +277,7 @@ public class MigratorUtil superClass = entityClass; } } + if (superClass == null) throw new RuntimeException(type.getTypeName() + " : " + name); Type elementType = ReflectionUtil.getField(superClass, name).getGenericType(); migrated = migrate(elementType, element) | migrated; } diff --git a/src/com/massivecraft/massivecore/util/ReflectionUtil.java b/src/com/massivecraft/massivecore/util/ReflectionUtil.java index 636501dc..89c1eb9d 100644 --- a/src/com/massivecraft/massivecore/util/ReflectionUtil.java +++ b/src/com/massivecraft/massivecore/util/ReflectionUtil.java @@ -293,6 +293,8 @@ public class ReflectionUtil public static Field getField(Class clazz, String name) { + if (clazz == null) throw new NullPointerException("clazz"); + if (name == null) throw new NullPointerException("name"); try { Field ret = clazz.getDeclaredField(name);