From 4715257de1e0d49fca734698ca417c5e841248c5 Mon Sep 17 00:00:00 2001 From: finn0s <90374296+finn0s@users.noreply.github.com> Date: Fri, 15 Sep 2023 09:40:45 +0200 Subject: Unload broken plugins fix (#545) --- .../src/main/java/org/pf4j/AbstractPluginManager.java | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) (limited to 'pf4j/src/main') diff --git a/pf4j/src/main/java/org/pf4j/AbstractPluginManager.java b/pf4j/src/main/java/org/pf4j/AbstractPluginManager.java index f56a94f..a23fc6a 100644 --- a/pf4j/src/main/java/org/pf4j/AbstractPluginManager.java +++ b/pf4j/src/main/java/org/pf4j/AbstractPluginManager.java @@ -280,15 +280,22 @@ public abstract class AbstractPluginManager implements PluginManager { dependents.addAll(0, dependencyResolver.getDependents(dependent)); } } + PluginWrapper pluginWrapper = getPlugin(pluginId); + PluginState pluginState; + try { + pluginState = stopPlugin(pluginId, false); + if (PluginState.STARTED == pluginState) { + return false; + } - PluginState pluginState = stopPlugin(pluginId, false); - if (PluginState.STARTED == pluginState) { - return false; + log.info("Unload plugin '{}'", getPluginLabel(pluginWrapper.getDescriptor())); + } catch (Exception e) { + if (pluginWrapper == null) { + return false; + } + pluginState = PluginState.FAILED; } - PluginWrapper pluginWrapper = getPlugin(pluginId); - log.info("Unload plugin '{}'", getPluginLabel(pluginWrapper.getDescriptor())); - // remove the plugin plugins.remove(pluginId); getResolvedPlugins().remove(pluginWrapper); -- cgit v1.2.3