Fix class resolving when package duplicated in dependent plugins. Fix #1920

This commit is contained in:
Karlatemp 2022-03-10 17:51:30 +08:00
parent 9bdbe30522
commit 894b8a9c2e
No known key found for this signature in database
GPG Key ID: C6B606FF23D8FED7
4 changed files with 54 additions and 2 deletions

View File

@ -13,7 +13,6 @@ import net.mamoe.console.integrationtest.ep.mcitselftest.MCITSelfTestPlugin
import net.mamoe.mirai.console.plugin.jvm.JvmPluginDescription
import net.mamoe.mirai.console.plugin.jvm.KotlinPlugin
import net.mamoe.mirai.utils.info
import kotlin.test.assertFails
import kotlin.test.assertFailsWith
import kotlin.test.assertNotEquals
import kotlin.test.assertSame
@ -52,5 +51,10 @@ public object PluginDependOnOther : KotlinPlugin(
Class.forName("net.mamoe.assertion.something.not.existing")
}
}
// region https://github.com/mamoe/mirai/issues/1920
Class.forName("net.mamoe.console.integrationtest.ep.pddd.p2.PDOO_OtherClass")
Class.forName("net.mamoe.console.integrationtest.ep.pddd.PDOO_OtherClass")
// endregion
}
}

View File

@ -0,0 +1,23 @@
/*
* Copyright 2019-2022 Mamoe Technologies and contributors.
*
* 此源代码的使用受 GNU AFFERO GENERAL PUBLIC LICENSE version 3 许可证的约束, 可以在以下链接找到该许可证.
* Use of this source code is governed by the GNU AGPLv3 license that can be found through the following link.
*
* https://github.com/mamoe/mirai/blob/dev/LICENSE
*/
@file:Suppress("unused", "PackageDirectoryMismatch", "ClassName")
package net.mamoe.console.integrationtest.ep.pddd
// https://github.com/mamoe/mirai/issues/1920
@PublishedApi
internal class PDOO_OtherClass {
companion object {
init {
Thread.dumpStack()
println("OC Loaded")
}
}
}

View File

@ -0,0 +1,23 @@
/*
* Copyright 2019-2022 Mamoe Technologies and contributors.
*
* 此源代码的使用受 GNU AFFERO GENERAL PUBLIC LICENSE version 3 许可证的约束, 可以在以下链接找到该许可证.
* Use of this source code is governed by the GNU AGPLv3 license that can be found through the following link.
*
* https://github.com/mamoe/mirai/blob/dev/LICENSE
*/
@file:Suppress("unused", "PackageDirectoryMismatch", "ClassName")
package net.mamoe.console.integrationtest.ep.pddd.p2
// https://github.com/mamoe/mirai/issues/1920
@PublishedApi
internal class PDOO_OtherClass {
companion object {
init {
Thread.dumpStack()
println("OC Loaded")
}
}
}

View File

@ -206,7 +206,9 @@ internal class JvmPluginClassLoaderN : URLClassLoader {
if (declaredFilter?.isExported(name) == false) return null
synchronized(getClassLoadingLock(name)) {
findLoadedClass(name)?.let { return it }
return super.findClass(name)
try {
return super.findClass(name)
} catch (ignored: ClassNotFoundException) {}
}
}
return null