From: Decebal Suiu Date: Sun, 15 Jan 2023 22:17:33 +0000 (+0200) Subject: Fix Sonar warning X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=refs%2Fpull%2F512%2Fhead;p=pf4j.git Fix Sonar warning --- 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); }