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 9 months ago
parent
commit
eac554e2ff
No known key found for this signature in database
  1. 2
      pf4j/src/main/java/org/pf4j/PluginWrapper.java

2
pf4j/src/main/java/org/pf4j/PluginWrapper.java

@ -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