aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorhannibal2 <24389977+hannibal00212@users.noreply.github.com>2024-04-07 10:29:45 +0200
committerhannibal2 <24389977+hannibal00212@users.noreply.github.com>2024-04-07 10:29:45 +0200
commit290ec20019977dfb1dbd3a8e6c152693c3337918 (patch)
treec328c211adaff7db96a33386736c492793f8a0d1
parentd0587a449ca47ad13788672bb9d014a6d9289d15 (diff)
downloadskyhanni-290ec20019977dfb1dbd3a8e6c152693c3337918.tar.gz
skyhanni-290ec20019977dfb1dbd3a8e6c152693c3337918.tar.bz2
skyhanni-290ec20019977dfb1dbd3a8e6c152693c3337918.zip
fix config read errors
-rw-r--r--src/main/java/at/hannibal2/skyhanni/utils/FeatureTogglesByDefaultAdapter.kt16
-rw-r--r--src/main/java/at/hannibal2/skyhanni/utils/ReflectionUtils.kt1
2 files changed, 14 insertions, 3 deletions
diff --git a/src/main/java/at/hannibal2/skyhanni/utils/FeatureTogglesByDefaultAdapter.kt b/src/main/java/at/hannibal2/skyhanni/utils/FeatureTogglesByDefaultAdapter.kt
index 011dcc10c..f78a0c4dc 100644
--- a/src/main/java/at/hannibal2/skyhanni/utils/FeatureTogglesByDefaultAdapter.kt
+++ b/src/main/java/at/hannibal2/skyhanni/utils/FeatureTogglesByDefaultAdapter.kt
@@ -1,6 +1,7 @@
package at.hannibal2.skyhanni.utils
import at.hannibal2.skyhanni.config.FeatureToggle
+import at.hannibal2.skyhanni.utils.ReflectionUtils.getDeclaredFieldOrNull
import com.google.gson.Gson
import com.google.gson.JsonObject
import com.google.gson.JsonPrimitive
@@ -49,8 +50,17 @@ object FeatureTogglesByDefaultAdapter : TypeAdapterFactory {
// Read the actual JSON Object
while (reader.peek() != JsonToken.END_OBJECT) {
+ // IllegalStateException: Expected NAME but was BOOLEAN
+ if (reader.peek() != JsonToken.NAME) {
+ reader.skipValue()
+ continue
+ }
val name = reader.nextName()
- val field = clazz.getDeclaredField(name)
+ val field = clazz.getDeclaredFieldOrNull(name)
+ if (field == null) {
+ println("field is in config file, but not in object file: $name")
+ continue
+ }
val fieldType = gson.getAdapter(TypeToken.get(getType(type, field)))
// Read the field data
val data = fieldType.read(reader)
@@ -70,10 +80,10 @@ object FeatureTogglesByDefaultAdapter : TypeAdapterFactory {
// Check if this object has any feature toggles present
if (t.fields.none {
it.isAnnotationPresent(FeatureToggle::class.java) ||
- gson.getAdapter(TypeToken.get(getType(type, it))) is Adapter
+ gson.getAdapter(TypeToken.get(getType(type, it))) is Adapter
}) return null
val originalWrite = gson.getDelegateAdapter(this, type)
return Adapter(originalWrite, t as Class<T>, gson, type)
}
-} \ No newline at end of file
+}
diff --git a/src/main/java/at/hannibal2/skyhanni/utils/ReflectionUtils.kt b/src/main/java/at/hannibal2/skyhanni/utils/ReflectionUtils.kt
index d8ebbaf68..1fe8b882c 100644
--- a/src/main/java/at/hannibal2/skyhanni/utils/ReflectionUtils.kt
+++ b/src/main/java/at/hannibal2/skyhanni/utils/ReflectionUtils.kt
@@ -80,4 +80,5 @@ object ReflectionUtils {
return packageLookup[shPackageName]
}
+ fun Class<*>.getDeclaredFieldOrNull(name: String): Field? = declaredFields.firstOrNull { it.name == name }
}