Browse Source

Avoid instantiating Plugin class if a plugin is already unloaded

Given the following preconditions:
- `PluginClassLoader` is configured to use `ClassLoadingStrategy` `PDA`, `DPA` or `DAP`.
- There is a `PluginStateListener` that calls `event.getPlugin().getPlugin()`.
- A plugin (`plugin-a`) with a missing dependency is loaded (`plugin-a`).
- The `Plugin` class in `plugin-a` extends, implements or references a class in either
  `plugin-b` or in the main application.

In that scenario, when `plugin-a` is unloaded by pf4j, and the `PluginStateListener`
is run, the `event.getPlugin().getPlugin()` call will fail with a `NullPointerException`.
This is caused by the class loading done when instantiating the `Plugin` class in
`plugin-a`. Because not all classes needed are found in `plugin-a` itself, pf4j will
continue by looking up classes in `plugin-a`'s dependencies. Because `plugin-b` is
missing and has no associated `ClassLoader`.
pull/570/head
Sebastian Lövdahl 2 months ago
parent
commit
3a467dead6
Failed to extract signature
1 changed files with 1 additions and 1 deletions
  1. 1
    1
      pf4j/src/main/java/org/pf4j/PluginWrapper.java

+ 1
- 1
pf4j/src/main/java/org/pf4j/PluginWrapper.java View File

@@ -90,7 +90,7 @@ public class PluginWrapper {
* @return the plugin instance
*/
public Plugin getPlugin() {
if (plugin == null) {
if (plugin == null && pluginState != PluginState.UNLOADED) {
plugin = pluginFactory.create(this);
}


Loading…
Cancel
Save