mirror of
https://github.com/PaperMC/Paper.git
synced 2025-01-02 17:32:03 +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
1 changed files with 28 additions and 15 deletions
|
@ -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,7 +63,6 @@ final class PluginClassLoader extends URLClassLoader {
|
||||||
this.url = file.toURI().toURL();
|
this.url = file.toURI().toURL();
|
||||||
this.libraryLoader = libraryLoader;
|
this.libraryLoader = libraryLoader;
|
||||||
|
|
||||||
try {
|
|
||||||
Class<?> jarClass;
|
Class<?> jarClass;
|
||||||
try {
|
try {
|
||||||
jarClass = Class.forName(description.getMain(), true, this);
|
jarClass = Class.forName(description.getMain(), true, this);
|
||||||
|
@ -73,14 +74,26 @@ final class PluginClassLoader extends URLClassLoader {
|
||||||
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 a new issue