Ver código fonte

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

Karlatemp 4 anos atrás
pai
commit
894b8a9c2e

+ 5 - 1
mirai-console/backend/integration-test/testers/plugin-depend-on-other/src/PluginDependOnOther.kt

@@ -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
     }
 }

+ 23 - 0
mirai-console/backend/integration-test/testers/plugin-depend-on-other/src/issue1920/OtherClass1.kt

@@ -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")
+        }
+    }
+}

+ 23 - 0
mirai-console/backend/integration-test/testers/plugin-depend-on-other/src/issue1920/OtherClass2.kt

@@ -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")
+        }
+    }
+}

+ 3 - 1
mirai-console/backend/mirai-console/src/internal/plugin/JvmPluginClassLoader.kt

@@ -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