Check for field type before attempting to read

This commit is contained in:
Mygod
2021-06-05 01:52:14 -04:00
parent 60c299a44a
commit 2e5f5b6192

View File

@@ -12,7 +12,7 @@ class ConstantLookup(private val prefix: String, private val lookup29: Array<out
private val lookup by lazy {
SparseArrayCompat<String>().apply {
for (field in clazz().declaredFields) try {
if (field.name.startsWith(prefix)) put(field.getInt(null), field.name)
if (field.type == Int::class.java && field.name.startsWith(prefix)) put(field.getInt(null), field.name)
} catch (e: Exception) {
Timber.w(e)
}
@@ -40,7 +40,7 @@ inline fun <reified T> ConstantLookup(prefix: String, vararg lookup29: String?)
class LongConstantLookup(private val clazz: Class<*>, private val prefix: String) {
private val lookup = LongSparseArray<String>().apply {
for (field in clazz.declaredFields) try {
if (field.name.startsWith(prefix)) put(field.getLong(null), field.name)
if (field.type == Long::class.java && field.name.startsWith(prefix)) put(field.getLong(null), field.name)
} catch (e: Exception) {
Timber.w(e)
}