Deprecate API methods added by 'Close Plugin Class Loaders on Disable' (#6737)
This commit is contained in:
parent
a4199412fc
commit
8e661c6b6e
|
@ -5,7 +5,7 @@ Subject: [PATCH] Automatically disable plugins that fail to load
|
||||||
|
|
||||||
|
|
||||||
diff --git a/src/main/java/org/bukkit/plugin/java/JavaPluginLoader.java b/src/main/java/org/bukkit/plugin/java/JavaPluginLoader.java
|
diff --git a/src/main/java/org/bukkit/plugin/java/JavaPluginLoader.java b/src/main/java/org/bukkit/plugin/java/JavaPluginLoader.java
|
||||||
index cf2f517765d8f2a23cc4a17d9ee2dcd81f841b1b..2e306c7b984a02e12a74fac14589bf29ab6488bf 100644
|
index cf2f517765d8f2a23cc4a17d9ee2dcd81f841b1b..a3bc4155536f612ee2ae38ec7f16b974bdd24ab2 100644
|
||||||
--- a/src/main/java/org/bukkit/plugin/java/JavaPluginLoader.java
|
--- a/src/main/java/org/bukkit/plugin/java/JavaPluginLoader.java
|
||||||
+++ b/src/main/java/org/bukkit/plugin/java/JavaPluginLoader.java
|
+++ b/src/main/java/org/bukkit/plugin/java/JavaPluginLoader.java
|
||||||
@@ -335,6 +335,10 @@ public final class JavaPluginLoader implements PluginLoader {
|
@@ -335,6 +335,10 @@ public final class JavaPluginLoader implements PluginLoader {
|
||||||
|
@ -13,7 +13,7 @@ index cf2f517765d8f2a23cc4a17d9ee2dcd81f841b1b..2e306c7b984a02e12a74fac14589bf29
|
||||||
} catch (Throwable ex) {
|
} catch (Throwable ex) {
|
||||||
server.getLogger().log(Level.SEVERE, "Error occurred while enabling " + plugin.getDescription().getFullName() + " (Is it up to date?)", ex);
|
server.getLogger().log(Level.SEVERE, "Error occurred while enabling " + plugin.getDescription().getFullName() + " (Is it up to date?)", ex);
|
||||||
+ // Paper start - Disable plugins that fail to load
|
+ // Paper start - Disable plugins that fail to load
|
||||||
+ disablePlugin(jPlugin);
|
+ this.server.getPluginManager().disablePlugin(jPlugin);
|
||||||
+ return;
|
+ return;
|
||||||
+ // Paper end
|
+ // Paper end
|
||||||
}
|
}
|
||||||
|
|
|
@ -6,23 +6,32 @@ Subject: [PATCH] Close Plugin Class Loaders on Disable
|
||||||
This should close more memory leaks from /reload and disabling plugins,
|
This should close more memory leaks from /reload and disabling plugins,
|
||||||
by closing the class loader and the jar file.
|
by closing the class loader and the jar file.
|
||||||
|
|
||||||
|
Note: This patch is no longer necessary as upstream now also closes
|
||||||
|
PluginClassLoaders on disable. This patch is now only to keep around
|
||||||
|
API methods it previously added, and to add back the log message when a
|
||||||
|
PluginClassLoader fails to disable, as upstream decided to ignore the
|
||||||
|
exception.
|
||||||
|
|
||||||
diff --git a/src/main/java/org/bukkit/plugin/PluginLoader.java b/src/main/java/org/bukkit/plugin/PluginLoader.java
|
diff --git a/src/main/java/org/bukkit/plugin/PluginLoader.java b/src/main/java/org/bukkit/plugin/PluginLoader.java
|
||||||
index a88733f1cd1ddb5d85ab1b0e6af4fd5b80bbc1c6..6ab9cd8213cbe35943748dcf42948d5fc048c84c 100644
|
index a88733f1cd1ddb5d85ab1b0e6af4fd5b80bbc1c6..256e440e699942e3c9da4205bb964bdc10ec92c4 100644
|
||||||
--- a/src/main/java/org/bukkit/plugin/PluginLoader.java
|
--- a/src/main/java/org/bukkit/plugin/PluginLoader.java
|
||||||
+++ b/src/main/java/org/bukkit/plugin/PluginLoader.java
|
+++ b/src/main/java/org/bukkit/plugin/PluginLoader.java
|
||||||
@@ -77,4 +77,18 @@ public interface PluginLoader {
|
@@ -77,4 +77,21 @@ public interface PluginLoader {
|
||||||
* @param plugin Plugin to disable
|
* @param plugin Plugin to disable
|
||||||
*/
|
*/
|
||||||
public void disablePlugin(@NotNull Plugin plugin);
|
public void disablePlugin(@NotNull Plugin plugin);
|
||||||
|
+
|
||||||
+ // Paper start - close Classloader on disable
|
+ // Paper start - close Classloader on disable
|
||||||
+ /**
|
+ /**
|
||||||
+ * Disables the specified plugin
|
+ * This method is no longer useful as upstream has
|
||||||
+ * <p>
|
+ * made it so plugin classloaders are always closed on disable.
|
||||||
+ * Attempting to disable a plugin that is not enabled will have no effect
|
+ * Use {@link #disablePlugin(Plugin)} instead.
|
||||||
+ *
|
+ *
|
||||||
+ * @param plugin Plugin to disable
|
+ * @param plugin Plugin to disable
|
||||||
+ * @param closeClassloader if the classloader for the Plugin should be closed
|
+ * @param closeClassloader unused
|
||||||
|
+ * @deprecated Classloader is always closed by upstream now.
|
||||||
+ */
|
+ */
|
||||||
|
+ @Deprecated(forRemoval = true)
|
||||||
+ // provide default to allow other PluginLoader implementations to work
|
+ // provide default to allow other PluginLoader implementations to work
|
||||||
+ default public void disablePlugin(@NotNull Plugin plugin, boolean closeClassloader) {
|
+ default public void disablePlugin(@NotNull Plugin plugin, boolean closeClassloader) {
|
||||||
+ disablePlugin(plugin);
|
+ disablePlugin(plugin);
|
||||||
|
@ -30,112 +39,67 @@ index a88733f1cd1ddb5d85ab1b0e6af4fd5b80bbc1c6..6ab9cd8213cbe35943748dcf42948d5f
|
||||||
+ // Paper end - close Classloader on disable
|
+ // Paper end - close Classloader on disable
|
||||||
}
|
}
|
||||||
diff --git a/src/main/java/org/bukkit/plugin/PluginManager.java b/src/main/java/org/bukkit/plugin/PluginManager.java
|
diff --git a/src/main/java/org/bukkit/plugin/PluginManager.java b/src/main/java/org/bukkit/plugin/PluginManager.java
|
||||||
index 41e26451fe12d8e6e0ef73c85731b24b4e3f200c..86cc5025ad98f7a752c51713b7cd6a39d5136ecc 100644
|
index 41e26451fe12d8e6e0ef73c85731b24b4e3f200c..0d1b20f2b5580ea5505ccc2f003925dbcee67199 100644
|
||||||
--- a/src/main/java/org/bukkit/plugin/PluginManager.java
|
--- a/src/main/java/org/bukkit/plugin/PluginManager.java
|
||||||
+++ b/src/main/java/org/bukkit/plugin/PluginManager.java
|
+++ b/src/main/java/org/bukkit/plugin/PluginManager.java
|
||||||
@@ -161,6 +161,18 @@ public interface PluginManager {
|
@@ -161,6 +161,22 @@ public interface PluginManager {
|
||||||
*/
|
*/
|
||||||
public void disablePlugin(@NotNull Plugin plugin);
|
public void disablePlugin(@NotNull Plugin plugin);
|
||||||
|
|
||||||
+ // Paper start - close Classloader on disable
|
+ // Paper start - close Classloader on disable
|
||||||
+ /**
|
+ /**
|
||||||
+ * Disables the specified plugin
|
+ * This method is no longer useful as upstream has
|
||||||
+ * <p>
|
+ * made it so plugin classloaders are always closed on disable.
|
||||||
+ * Attempting to disable a plugin that is not enabled will have no effect
|
+ * Use {@link #disablePlugin(Plugin)} instead.
|
||||||
+ *
|
+ *
|
||||||
+ * @param plugin Plugin to disable
|
+ * @param plugin Plugin to disable
|
||||||
+ * @param closeClassloader if the classloader for the Plugin should be closed
|
+ * @param closeClassloader unused
|
||||||
|
+ * @deprecated Classloader is always closed by upstream now.
|
||||||
+ */
|
+ */
|
||||||
+ public void disablePlugin(@NotNull Plugin plugin, boolean closeClassloader);
|
+ @Deprecated(forRemoval = true)
|
||||||
|
+ public default void disablePlugin(@NotNull Plugin plugin, boolean closeClassloader) {
|
||||||
|
+ this.disablePlugin(plugin);
|
||||||
|
+ }
|
||||||
+ // Paper end - close Classloader on disable
|
+ // Paper end - close Classloader on disable
|
||||||
+
|
+
|
||||||
/**
|
/**
|
||||||
* Gets a {@link Permission} from its fully qualified name
|
* Gets a {@link Permission} from its fully qualified name
|
||||||
*
|
*
|
||||||
diff --git a/src/main/java/org/bukkit/plugin/SimplePluginManager.java b/src/main/java/org/bukkit/plugin/SimplePluginManager.java
|
diff --git a/src/main/java/org/bukkit/plugin/SimplePluginManager.java b/src/main/java/org/bukkit/plugin/SimplePluginManager.java
|
||||||
index 2d27dfb859c312d46a14d0356c7c3f227e965a67..892ec4b43cc97a235df0819d30391a8a3770cbcb 100644
|
index 2d27dfb859c312d46a14d0356c7c3f227e965a67..7867243a8ed67416895cdcd949ac424f5d29d98b 100644
|
||||||
--- a/src/main/java/org/bukkit/plugin/SimplePluginManager.java
|
--- a/src/main/java/org/bukkit/plugin/SimplePluginManager.java
|
||||||
+++ b/src/main/java/org/bukkit/plugin/SimplePluginManager.java
|
+++ b/src/main/java/org/bukkit/plugin/SimplePluginManager.java
|
||||||
@@ -492,17 +492,28 @@ public final class SimplePluginManager implements PluginManager {
|
@@ -498,6 +498,21 @@ public final class SimplePluginManager implements PluginManager {
|
||||||
|
|
||||||
@Override
|
|
||||||
public void disablePlugins() {
|
|
||||||
+ disablePlugins(false);
|
|
||||||
+ }
|
|
||||||
+
|
|
||||||
+ public void disablePlugins(boolean closeClassloaders) {
|
|
||||||
+ // Paper end - close Classloader on disable
|
|
||||||
Plugin[] plugins = getPlugins();
|
|
||||||
for (int i = plugins.length - 1; i >= 0; i--) {
|
|
||||||
- disablePlugin(plugins[i]);
|
|
||||||
+ disablePlugin(plugins[i], closeClassloaders); // Paper - close Classloader on disable
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
+ // Paper start
|
||||||
|
+ /**
|
||||||
|
+ * This method is no longer useful as upstream has
|
||||||
|
+ * made it so plugin classloaders are always closed on disable.
|
||||||
|
+ * Use {@link #disablePlugins()} instead.
|
||||||
|
+ *
|
||||||
|
+ * @param closeClassloaders unused
|
||||||
|
+ * @deprecated Classloader is always closed by upstream now.
|
||||||
|
+ */
|
||||||
|
+ @Deprecated(forRemoval = true)
|
||||||
|
+ public void disablePlugins(boolean closeClassloaders) {
|
||||||
|
+ this.disablePlugins();
|
||||||
|
+ }
|
||||||
|
+ // Paper end
|
||||||
|
+
|
||||||
@Override
|
@Override
|
||||||
public void disablePlugin(@NotNull final Plugin plugin) {
|
public void disablePlugin(@NotNull final Plugin plugin) {
|
||||||
+ disablePlugin(plugin, false);
|
|
||||||
+ }
|
|
||||||
+
|
|
||||||
+ @Override
|
|
||||||
+ public void disablePlugin(@NotNull final Plugin plugin, boolean closeClassloader) {
|
|
||||||
+ // Paper end - close Classloader on disable
|
|
||||||
if (plugin.isEnabled()) {
|
if (plugin.isEnabled()) {
|
||||||
try {
|
|
||||||
- plugin.getPluginLoader().disablePlugin(plugin);
|
|
||||||
+ plugin.getPluginLoader().disablePlugin(plugin, closeClassloader); // Paper - close Classloader on disable
|
|
||||||
} catch (Throwable ex) {
|
|
||||||
handlePluginException("Error occurred (in the plugin loader) while disabling "
|
|
||||||
+ plugin.getDescription().getFullName() + " (Is it up to date?)", ex, plugin); // Paper
|
|
||||||
@@ -557,7 +568,7 @@ public final class SimplePluginManager implements PluginManager {
|
|
||||||
@Override
|
|
||||||
public void clearPlugins() {
|
|
||||||
synchronized (this) {
|
|
||||||
- disablePlugins();
|
|
||||||
+ disablePlugins(true); // Paper - close Classloader on disable
|
|
||||||
plugins.clear();
|
|
||||||
lookupNames.clear();
|
|
||||||
dependencyGraph = GraphBuilder.directed().build();
|
|
||||||
diff --git a/src/main/java/org/bukkit/plugin/java/JavaPluginLoader.java b/src/main/java/org/bukkit/plugin/java/JavaPluginLoader.java
|
diff --git a/src/main/java/org/bukkit/plugin/java/JavaPluginLoader.java b/src/main/java/org/bukkit/plugin/java/JavaPluginLoader.java
|
||||||
index 79ac529017aac059d13fe342f279e9c8faeba599..816c2b1797447ab315ceb6eda89d25f27d2bce98 100644
|
index b7cd98f20de3421cd3b8a95cfa2155fa77afa8b1..7483ceff298cafa244bd99316a0338aa075267d4 100644
|
||||||
--- a/src/main/java/org/bukkit/plugin/java/JavaPluginLoader.java
|
--- a/src/main/java/org/bukkit/plugin/java/JavaPluginLoader.java
|
||||||
+++ b/src/main/java/org/bukkit/plugin/java/JavaPluginLoader.java
|
+++ b/src/main/java/org/bukkit/plugin/java/JavaPluginLoader.java
|
||||||
@@ -322,7 +322,7 @@ public final class JavaPluginLoader implements PluginLoader {
|
@@ -366,6 +366,7 @@ public final class JavaPluginLoader implements PluginLoader {
|
||||||
} catch (Throwable ex) {
|
loader.close();
|
||||||
server.getLogger().log(Level.SEVERE, "Error occurred while enabling " + plugin.getDescription().getFullName() + " (Is it up to date?)", ex);
|
|
||||||
// Paper start - Disable plugins that fail to load
|
|
||||||
- disablePlugin(jPlugin);
|
|
||||||
+ server.getPluginManager().disablePlugin(jPlugin, true); // Paper - close Classloader on disable - She's dead jim
|
|
||||||
return;
|
|
||||||
// Paper end
|
|
||||||
}
|
|
||||||
@@ -335,6 +335,12 @@ public final class JavaPluginLoader implements PluginLoader {
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void disablePlugin(@NotNull Plugin plugin) {
|
|
||||||
+ // Paper start - close Classloader on disable
|
|
||||||
+ disablePlugin(plugin, false); // Retain old behavior unless requested
|
|
||||||
+ }
|
|
||||||
+
|
|
||||||
+ public void disablePlugin(@NotNull Plugin plugin, boolean closeClassloader) {
|
|
||||||
+ // Paper end - close Class Loader on disable
|
|
||||||
Validate.isTrue(plugin instanceof JavaPlugin, "Plugin is not associated with this PluginLoader");
|
|
||||||
|
|
||||||
if (plugin.isEnabled()) {
|
|
||||||
@@ -367,6 +373,16 @@ public final class JavaPluginLoader implements PluginLoader {
|
|
||||||
} catch (IOException ex) {
|
} catch (IOException ex) {
|
||||||
//
|
//
|
||||||
|
+ this.server.getLogger().log(Level.WARNING, "Error closing the PluginClassLoader for '" + plugin.getDescription().getFullName() + "'", ex); // Paper - log exception
|
||||||
}
|
}
|
||||||
+ // Paper start - close Class Loader on disable
|
|
||||||
+ try {
|
|
||||||
+ if (closeClassloader) {
|
|
||||||
+ loader.close();
|
|
||||||
+ }
|
|
||||||
+ } catch (IOException e) {
|
|
||||||
+ server.getLogger().log(Level.WARNING, "Error closing the Plugin Class Loader for " + plugin.getDescription().getFullName());
|
|
||||||
+ e.printStackTrace();
|
|
||||||
+ }
|
|
||||||
+ // Paper end
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
|
@ -16,7 +16,7 @@ which results in a hard crash.
|
||||||
This change removes the synchronize and adds some protection around enable/disable
|
This change removes the synchronize and adds some protection around enable/disable
|
||||||
|
|
||||||
diff --git a/src/main/java/org/bukkit/plugin/SimplePluginManager.java b/src/main/java/org/bukkit/plugin/SimplePluginManager.java
|
diff --git a/src/main/java/org/bukkit/plugin/SimplePluginManager.java b/src/main/java/org/bukkit/plugin/SimplePluginManager.java
|
||||||
index 892ec4b43cc97a235df0819d30391a8a3770cbcb..b83637f872be5fc73500b10c917d71802976b340 100644
|
index 7867243a8ed67416895cdcd949ac424f5d29d98b..a3027c1c6109bcb20d0468f6d0cd37182bb279ea 100644
|
||||||
--- a/src/main/java/org/bukkit/plugin/SimplePluginManager.java
|
--- a/src/main/java/org/bukkit/plugin/SimplePluginManager.java
|
||||||
+++ b/src/main/java/org/bukkit/plugin/SimplePluginManager.java
|
+++ b/src/main/java/org/bukkit/plugin/SimplePluginManager.java
|
||||||
@@ -462,7 +462,7 @@ public final class SimplePluginManager implements PluginManager {
|
@@ -462,7 +462,7 @@ public final class SimplePluginManager implements PluginManager {
|
||||||
|
@ -37,16 +37,16 @@ index 892ec4b43cc97a235df0819d30391a8a3770cbcb..b83637f872be5fc73500b10c917d7180
|
||||||
if (!plugin.isEnabled()) {
|
if (!plugin.isEnabled()) {
|
||||||
List<Command> pluginCommands = PluginCommandYamlParser.parse(plugin);
|
List<Command> pluginCommands = PluginCommandYamlParser.parse(plugin);
|
||||||
|
|
||||||
@@ -509,7 +509,7 @@ public final class SimplePluginManager implements PluginManager {
|
@@ -514,7 +514,7 @@ public final class SimplePluginManager implements PluginManager {
|
||||||
}
|
// Paper end
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
- public void disablePlugin(@NotNull final Plugin plugin, boolean closeClassloader) {
|
- public void disablePlugin(@NotNull final Plugin plugin) {
|
||||||
+ public synchronized void disablePlugin(@NotNull final Plugin plugin, boolean closeClassloader) { // Paper - synchronize
|
+ public synchronized void disablePlugin(@NotNull final Plugin plugin) { // Paper - synchronize
|
||||||
// Paper end - close Classloader on disable
|
|
||||||
if (plugin.isEnabled()) {
|
if (plugin.isEnabled()) {
|
||||||
try {
|
try {
|
||||||
@@ -579,6 +579,7 @@ public final class SimplePluginManager implements PluginManager {
|
plugin.getPluginLoader().disablePlugin(plugin);
|
||||||
|
@@ -583,6 +583,7 @@ public final class SimplePluginManager implements PluginManager {
|
||||||
defaultPerms.get(false).clear();
|
defaultPerms.get(false).clear();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -54,7 +54,7 @@ index 892ec4b43cc97a235df0819d30391a8a3770cbcb..b83637f872be5fc73500b10c917d7180
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Calls an event with the given details.
|
* Calls an event with the given details.
|
||||||
@@ -587,23 +588,13 @@ public final class SimplePluginManager implements PluginManager {
|
@@ -591,23 +592,13 @@ public final class SimplePluginManager implements PluginManager {
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public void callEvent(@NotNull Event event) {
|
public void callEvent(@NotNull Event event) {
|
||||||
|
|
|
@ -11,10 +11,10 @@ errors.
|
||||||
This isn't an issue on Spigot
|
This isn't an issue on Spigot
|
||||||
|
|
||||||
diff --git a/src/main/java/org/bukkit/plugin/SimplePluginManager.java b/src/main/java/org/bukkit/plugin/SimplePluginManager.java
|
diff --git a/src/main/java/org/bukkit/plugin/SimplePluginManager.java b/src/main/java/org/bukkit/plugin/SimplePluginManager.java
|
||||||
index b83637f872be5fc73500b10c917d71802976b340..49e5d49eb09bb966e47d6a03ac08a527c963b43d 100644
|
index a3027c1c6109bcb20d0468f6d0cd37182bb279ea..20b4ef7a94e00d9264b8ecc126ce5853b584ea8c 100644
|
||||||
--- a/src/main/java/org/bukkit/plugin/SimplePluginManager.java
|
--- a/src/main/java/org/bukkit/plugin/SimplePluginManager.java
|
||||||
+++ b/src/main/java/org/bukkit/plugin/SimplePluginManager.java
|
+++ b/src/main/java/org/bukkit/plugin/SimplePluginManager.java
|
||||||
@@ -591,7 +591,7 @@ public final class SimplePluginManager implements PluginManager {
|
@@ -595,7 +595,7 @@ public final class SimplePluginManager implements PluginManager {
|
||||||
// Paper - replace callEvent by merging to below method
|
// Paper - replace callEvent by merging to below method
|
||||||
if (event.isAsynchronous() && server.isPrimaryThread()) {
|
if (event.isAsynchronous() && server.isPrimaryThread()) {
|
||||||
throw new IllegalStateException(event.getEventName() + " may only be triggered asynchronously.");
|
throw new IllegalStateException(event.getEventName() + " may only be triggered asynchronously.");
|
||||||
|
|
Loading…
Reference in New Issue