Skip to content

Commit

Permalink
Fix SecurityException on getStaticObjectOrNull
Browse files Browse the repository at this point in the history
KyuubiRan committed May 22, 2023
1 parent bd25a5d commit 2d66682
Showing 1 changed file with 3 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -93,7 +93,9 @@ object ClassUtils {
@Throws(NoSuchFieldException::class)
fun getStaticObjectOrNull(clazz: Class<*>, fieldName: String): Any? =
clazz.declaredFields.firstOrNull { it.isStatic && fieldName == it.name }
.let { it ?: throw NoSuchFieldException("No such static field $fieldName in class ${clazz.name}.") }
.let {
it?.also { f -> f.isAccessible = true } ?: throw NoSuchFieldException("No such static field $fieldName in class ${clazz.name}.")
}
.get(null)


0 comments on commit 2d66682

Please sign in to comment.