From e0daf830e56fa32e8a702c57a7f09e9230ec9747 Mon Sep 17 00:00:00 2001
From: Karlatemp <karlatemp@vip.qq.com>
Date: Tue, 29 Dec 2020 11:42:29 +0800
Subject: [PATCH] Fix plugin classes loading

---
 .../internal/plugin/JvmPluginClassLoader.kt   | 31 ++++++-------------
 1 file changed, 10 insertions(+), 21 deletions(-)

diff --git a/backend/mirai-console/src/internal/plugin/JvmPluginClassLoader.kt b/backend/mirai-console/src/internal/plugin/JvmPluginClassLoader.kt
index 33c9e0584..bff6c9fa3 100644
--- a/backend/mirai-console/src/internal/plugin/JvmPluginClassLoader.kt
+++ b/backend/mirai-console/src/internal/plugin/JvmPluginClassLoader.kt
@@ -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)
     }
 }