diff options
author | Decebal Suiu <decebal.suiu@gmail.com> | 2023-01-16 00:17:33 +0200 |
---|---|---|
committer | Decebal Suiu <decebal.suiu@gmail.com> | 2023-01-16 00:17:33 +0200 |
commit | 5b7705d86b6386786f8232ae8a3ff6273914a69a (patch) | |
tree | d824ef5c8dd93264a4b99ed9bf3704540d73ce76 /pf4j/src | |
parent | 2a4df4e3c638bd2783d8977d5e5979cabfa155c7 (diff) | |
download | pf4j-5b7705d86b6386786f8232ae8a3ff6273914a69a.tar.gz pf4j-5b7705d86b6386786f8232ae8a3ff6273914a69a.zip |
Fix Sonar warningplugin_context
Diffstat (limited to 'pf4j/src')
-rw-r--r-- | pf4j/src/main/java/org/pf4j/DefaultPluginFactory.java | 25 |
1 files changed, 15 insertions, 10 deletions
diff --git a/pf4j/src/main/java/org/pf4j/DefaultPluginFactory.java b/pf4j/src/main/java/org/pf4j/DefaultPluginFactory.java index db86006..310c791 100644 --- a/pf4j/src/main/java/org/pf4j/DefaultPluginFactory.java +++ b/pf4j/src/main/java/org/pf4j/DefaultPluginFactory.java @@ -59,18 +59,23 @@ public class DefaultPluginFactory implements PluginFactory { return createInstance(pluginClass, pluginWrapper); } - /** - * Creates a plugin instance. If an error occurs than that error is logged and the method returns {@code null}. - */ protected Plugin createInstance(Class<?> pluginClass, PluginWrapper pluginWrapper) { try { - try { - Constructor<?> constructor = pluginClass.getConstructor(PluginWrapper.class); - return (Plugin) constructor.newInstance(pluginWrapper); - } catch (NoSuchMethodException e) { - Constructor<?> constructor = pluginClass.getConstructor(); - return (Plugin) constructor.newInstance(); - } + Constructor<?> constructor = pluginClass.getConstructor(PluginWrapper.class); + return (Plugin) constructor.newInstance(pluginWrapper); + } catch (NoSuchMethodException e) { + return createUsingNoParametersConstructor(pluginClass); + } catch (Exception e) { + log.error(e.getMessage(), e); + } + + return null; + } + + protected Plugin createUsingNoParametersConstructor(Class<?> pluginClass) { + try { + Constructor<?> constructor = pluginClass.getConstructor(); + return (Plugin) constructor.newInstance(); } catch (Exception e) { log.error(e.getMessage(), e); } |