Mesagisto / mirai-message-source

A implementation of message source. 消息源的mirai(Tencent-QQ)实现
GNU Affero General Public License v3.0
11 stars 2 forks source link

切换 contextClassLoader 应该使用 try finally 恢复之前的上下文 #5

Closed cssxsh closed 2 years ago

cssxsh commented 2 years ago

https://github.com/MeowCat-Studio/mirai-message-source/blob/849e39ed84ee4853f0ff636197235ab39bd7e805/src/main/kotlin/Plugin.kt#L37-L41

val oc = Thread.currentThread().contextClassLoader
try { 
   Thread.currentThread().contextClassLoader = jvmPluginClasspath.pluginClassLoader 
   ImageIO.scanForPlugins() 
   NativeDB.LIBRARY.load() 
} finally {
   Thread.currentThread().contextClassLoader = oc
}
Itsusinn commented 2 years ago

因为在此处修改contextClassloader会影响onEnable的调用者是么? 有道理