mirror of
https://github.com/PaperMC/Paper.git
synced 2025-02-05 23:21:38 +01:00
Increase clarity of errors when loading malformed plugin main classes
By: md_5 <git@md-5.net>
This commit is contained in:
parent
943fb1db3d
commit
a1daa7077c
@ -5,6 +5,8 @@ import com.google.common.io.ByteStreams;
|
|||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.io.InputStream;
|
import java.io.InputStream;
|
||||||
|
import java.lang.reflect.Constructor;
|
||||||
|
import java.lang.reflect.InvocationTargetException;
|
||||||
import java.net.MalformedURLException;
|
import java.net.MalformedURLException;
|
||||||
import java.net.URL;
|
import java.net.URL;
|
||||||
import java.net.URLClassLoader;
|
import java.net.URLClassLoader;
|
||||||
@ -61,26 +63,37 @@ final class PluginClassLoader extends URLClassLoader {
|
|||||||
this.url = file.toURI().toURL();
|
this.url = file.toURI().toURL();
|
||||||
this.libraryLoader = libraryLoader;
|
this.libraryLoader = libraryLoader;
|
||||||
|
|
||||||
|
Class<?> jarClass;
|
||||||
try {
|
try {
|
||||||
Class<?> jarClass;
|
jarClass = Class.forName(description.getMain(), true, this);
|
||||||
try {
|
} catch (ClassNotFoundException ex) {
|
||||||
jarClass = Class.forName(description.getMain(), true, this);
|
throw new InvalidPluginException("Cannot find main class `" + description.getMain() + "'", ex);
|
||||||
} catch (ClassNotFoundException ex) {
|
}
|
||||||
throw new InvalidPluginException("Cannot find main class `" + description.getMain() + "'", ex);
|
|
||||||
}
|
|
||||||
|
|
||||||
Class<? extends JavaPlugin> pluginClass;
|
Class<? extends JavaPlugin> pluginClass;
|
||||||
try {
|
try {
|
||||||
pluginClass = jarClass.asSubclass(JavaPlugin.class);
|
pluginClass = jarClass.asSubclass(JavaPlugin.class);
|
||||||
} catch (ClassCastException ex) {
|
} catch (ClassCastException ex) {
|
||||||
throw new InvalidPluginException("main class `" + description.getMain() + "' does not extend JavaPlugin", ex);
|
throw new InvalidPluginException("main class `" + description.getMain() + "' must extend JavaPlugin", ex);
|
||||||
}
|
}
|
||||||
|
|
||||||
plugin = pluginClass.newInstance();
|
Constructor<? extends JavaPlugin> pluginConstructor;
|
||||||
|
try {
|
||||||
|
pluginConstructor = pluginClass.getDeclaredConstructor();
|
||||||
|
} catch (NoSuchMethodException ex) {
|
||||||
|
throw new InvalidPluginException("main class `" + description.getMain() + "' must have a public no-args constructor", ex);
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
plugin = pluginConstructor.newInstance();
|
||||||
} catch (IllegalAccessException ex) {
|
} catch (IllegalAccessException ex) {
|
||||||
throw new InvalidPluginException("No public constructor", ex);
|
throw new InvalidPluginException("main class `" + description.getMain() + "' constructor must be public", ex);
|
||||||
} catch (InstantiationException ex) {
|
} catch (InstantiationException ex) {
|
||||||
throw new InvalidPluginException("Abnormal plugin type", ex);
|
throw new InvalidPluginException("main class `" + description.getMain() + "' must not be abstract", ex);
|
||||||
|
} catch (IllegalArgumentException ex) {
|
||||||
|
throw new InvalidPluginException("Could not invoke main class `" + description.getMain() + "' constructor", ex);
|
||||||
|
} catch (ExceptionInInitializerError | InvocationTargetException ex) {
|
||||||
|
throw new InvalidPluginException("Exception initializing main class `" + description.getMain() + "'", ex);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user