geforkt von Mirrors/Paper
SPIGOT-2629: Better thread safety for plugin class loading
By: md_5 <git@md-5.net>
Dieser Commit ist enthalten in:
Ursprung
497a87b5b5
Commit
4be07ca07a
@ -7,6 +7,7 @@ import java.io.InputStream;
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
import java.lang.reflect.Method;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.LinkedHashMap;
|
||||
@ -48,7 +49,7 @@ public final class JavaPluginLoader implements PluginLoader {
|
||||
final Server server;
|
||||
private final Pattern[] fileFilters = new Pattern[] { Pattern.compile("\\.jar$"), };
|
||||
private final Map<String, Class<?>> classes = new HashMap<String, Class<?>>();
|
||||
private final Map<String, PluginClassLoader> loaders = new LinkedHashMap<String, PluginClassLoader>();
|
||||
private final Map<String, PluginClassLoader> loaders = Collections.synchronizedMap(new LinkedHashMap<String, PluginClassLoader>());
|
||||
|
||||
/**
|
||||
* This class was not meant to be constructed explicitly
|
||||
@ -114,9 +115,6 @@ public final class JavaPluginLoader implements PluginLoader {
|
||||
}
|
||||
|
||||
for (final String pluginName : description.getDepend()) {
|
||||
if (loaders == null) {
|
||||
throw new UnknownDependencyException(pluginName);
|
||||
}
|
||||
PluginClassLoader current = loaders.get(pluginName);
|
||||
|
||||
if (current == null) {
|
||||
@ -186,14 +184,14 @@ public final class JavaPluginLoader implements PluginLoader {
|
||||
if (cachedClass != null) {
|
||||
return cachedClass;
|
||||
} else {
|
||||
for (String current : loaders.keySet()) {
|
||||
PluginClassLoader loader = loaders.get(current);
|
||||
|
||||
try {
|
||||
cachedClass = loader.findClass(name, false);
|
||||
} catch (ClassNotFoundException cnfe) {}
|
||||
if (cachedClass != null) {
|
||||
return cachedClass;
|
||||
synchronized (loaders) {
|
||||
for (PluginClassLoader loader : loaders.values()) {
|
||||
try {
|
||||
cachedClass = loader.findClass(name, false);
|
||||
} catch (ClassNotFoundException cnfe) {}
|
||||
if (cachedClass != null) {
|
||||
return cachedClass;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Laden…
In neuem Issue referenzieren
Einen Benutzer sperren