Fix plugin classes loading

This commit is contained in:
Karlatemp 2020-12-29 11:42:29 +08:00
parent d2965c87f5
commit e0daf830e5
No known key found for this signature in database
GPG Key ID: 21FBDDF664FF06F8

View File

@ -97,28 +97,17 @@ internal class JvmPluginClassLoader(
} else throw LoadingDeniedException("$name was not exported by $otherClassloader")
}
}
// If no cache...
return kotlin.runCatching {
// Try load this class direct....
super.findClass(name).also { cache[name] = it }
}.getOrElse { exception ->
if (exception is ClassNotFoundException) {
// Cannot load the class from this, try others.
classLoaders.forEach { otherClassloader ->
if (otherClassloader === this) return@forEach
val other = kotlin.runCatching {
otherClassloader.findClass(name, true)
}.onFailure { err ->
if (err is LoadingDeniedException || err !is ClassNotFoundException)
throw err
}.getOrNull()
if (other != null) return other
}
}
// Great, nobody known what is the class.
throw exception
classLoaders.forEach { otherClassloader ->
val other = kotlin.runCatching {
if (otherClassloader === this) super.findClass(name).also { cache[name] = it }
else otherClassloader.findClass(name, true)
}.onFailure { err ->
if (err is LoadingDeniedException || err !is ClassNotFoundException)
throw err
}.getOrNull()
if (other != null) return other
}
throw ClassNotFoundException(name)
}
}