Skip to content

Commit

Permalink
Ignoring plugin files containing duplicate runtime classes
Browse files Browse the repository at this point in the history
  • Loading branch information
huanmeng-qwq committed Dec 6, 2023
1 parent 045289e commit 9b83794
Showing 1 changed file with 8 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ public class SimplePluginClassLoader extends PluginClassLoader {
private final KBCClient client;
@Nullable
private final AccessClassLoader parentClassLoader;
private File file;

public SimplePluginClassLoader(KBCClient client, @Nullable AccessClassLoader parent) {
super(new URL[0], parent != null ? null : SimplePluginManager.class.getClassLoader());
Expand Down Expand Up @@ -101,6 +102,7 @@ protected Class<? extends Plugin> lookForMainClass(String mainClassName, File fi
if (parentClassLoader != null) {
parentClassLoader.addURL(file.toURI().toURL());
}
this.file = file;
Class<?> loadClass = this.loadClass(mainClassName, true);
Class<? extends Plugin> main = loadClass.asSubclass(Plugin.class);
if (main.getDeclaredConstructors().length != 1) {
Expand All @@ -125,6 +127,11 @@ public final Class<?> findClass0(String name, boolean dontCallOther) throws Clas
if (cache.containsKey(name)) {
return cache.get(name);
}
if (parentClassLoader != null && (name.startsWith("snw.kookbc.") || name.startsWith("snw.jkook"))) {
Class<?> clazz = parentClassLoader.findClass(name);
cache.put(name, clazz);
return clazz;
}
Throwable throwable = null;
try {
Class<?> result = super.findClass(name);
Expand Down Expand Up @@ -186,7 +193,7 @@ protected Class<?> loadFromOther(String name) throws ClassNotFoundException {
public void close() throws IOException {
INSTANCES.remove(this);
for (Class<?> clazz : cache.values()) {
if (ConfigurationSerializable.class.isAssignableFrom(clazz)) {
if (clazz.getClassLoader() == this && ConfigurationSerializable.class.isAssignableFrom(clazz)) {
//noinspection unchecked
ConfigurationSerialization.unregisterClass((Class<? extends ConfigurationSerializable>) clazz);
}
Expand Down

0 comments on commit 9b83794

Please sign in to comment.