[console] 修复 JvmPluginInternal 在 Android java.lang.NoSuchMethodError (#2354)

* fix java.lang.NoSuchMethodError

fix java.lang.NoSuchMethodError: No virtual method getDeclaredAnnotation(Ljava/lang/Class;)L

* fix formatting

Co-authored-by: Him188 <Him188@mamoe.net>
This commit is contained in:
赵怡然 2022-11-19 07:26:52 +08:00 committed by GitHub
parent 372c25024c
commit 0e4d5efd38
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -126,7 +126,12 @@ internal abstract class JvmPluginInternal(
parentPermission
if (!firstRun) refreshCoroutineContext()
val except = javaClass.getDeclaredAnnotation(ConsoleJvmPluginFuncCallbackStatusExcept.OnEnable::class.java)
val except = try {
javaClass.getDeclaredAnnotation(ConsoleJvmPluginFuncCallbackStatusExcept.OnEnable::class.java)
} catch (e: Throwable) {
null
}
kotlin.runCatching {
onEnable()
}.fold(
@ -244,4 +249,4 @@ internal inline fun AtomicLong.updateWhen(condition: (Long) -> Boolean, update:
}
}
internal val Throwable.rootCauseOrSelf: Throwable get() = generateSequence(this) { it.cause }.lastOrNull() ?: this
internal val Throwable.rootCauseOrSelf: Throwable get() = generateSequence(this) { it.cause }.lastOrNull() ?: this