From 0c9154899b014fa0810d4be1a345e87755686bca Mon Sep 17 00:00:00 2001 From: md_5 Date: Thu, 24 Jan 2013 09:33:34 +1100 Subject: [PATCH] Make the plugin classloader a bit more thread safe to prevent class not found errors when a class is loaded at the same time from another thread. --- ...-the-plugin-class-loader-thread-safe.patch | 65 +++++++++++++++++++ 1 file changed, 65 insertions(+) create mode 100644 Bukkit-Patches/0004-Make-the-plugin-class-loader-thread-safe.patch diff --git a/Bukkit-Patches/0004-Make-the-plugin-class-loader-thread-safe.patch b/Bukkit-Patches/0004-Make-the-plugin-class-loader-thread-safe.patch new file mode 100644 index 000000000..bbefcfd08 --- /dev/null +++ b/Bukkit-Patches/0004-Make-the-plugin-class-loader-thread-safe.patch @@ -0,0 +1,65 @@ +From a62dabb02fe7405059ceb42495ed5dbc9704c1ea Mon Sep 17 00:00:00 2001 +From: snowleo +Date: Wed, 17 Oct 2012 22:30:45 +0200 +Subject: [PATCH] Make the plugin class loader thread safe + +--- + .../org/bukkit/plugin/java/JavaPluginLoader.java | 21 ++++++++++++--------- + 1 file changed, 12 insertions(+), 9 deletions(-) + +diff --git a/src/main/java/org/bukkit/plugin/java/JavaPluginLoader.java b/src/main/java/org/bukkit/plugin/java/JavaPluginLoader.java +index 10fc26a..f9a09ef 100644 +--- a/src/main/java/org/bukkit/plugin/java/JavaPluginLoader.java ++++ b/src/main/java/org/bukkit/plugin/java/JavaPluginLoader.java +@@ -45,6 +45,7 @@ import org.bukkit.plugin.UnknownDependencyException; + import org.yaml.snakeyaml.error.YAMLException; + + import com.google.common.collect.ImmutableList; ++import java.util.concurrent.ConcurrentHashMap; + + /** + * Represents a Java plugin loader, allowing plugins in the form of .jar +@@ -61,14 +62,14 @@ public class JavaPluginLoader implements PluginLoader { + @Deprecated + protected final Pattern[] fileFilters = fileFilters0; + +- private final Map> classes0 = new HashMap>(); ++ private final Map> classes0 = new ConcurrentHashMap>(); + /** + * @deprecated Internal field that wasn't intended to be exposed + */ + @Deprecated + protected final Map> classes = classes0; + +- private final Map loaders0 = new LinkedHashMap(); ++ private final Map loaders0 = new ConcurrentHashMap(); + /** + * @deprecated Internal field that wasn't intended to be exposed + */ +@@ -293,14 +294,16 @@ public class JavaPluginLoader implements PluginLoader { + if (cachedClass != null) { + return cachedClass; + } else { +- for (String current : loaders0.keySet()) { +- PluginClassLoader loader = loaders0.get(current); ++ synchronized (loaders) { ++ for (String current : loaders0.keySet()) { ++ PluginClassLoader loader = loaders0.get(current); + +- try { +- cachedClass = loader.extended ? loader.findClass(name, false) : loader.findClass0(name, false); // Don't warn on deprecation, but maintain overridability +- } catch (ClassNotFoundException cnfe) {} +- if (cachedClass != null) { +- return cachedClass; ++ try { ++ cachedClass = loader.extended ? loader.findClass(name, false) : loader.findClass0(name, false); // Don't warn on deprecation, but maintain overridability ++ } catch (ClassNotFoundException cnfe) {} ++ if (cachedClass != null) { ++ return cachedClass; ++ } + } + } + } +-- +1.8.1-rc2 +