This is an automated email from the ASF dual-hosted git repository.

mawiesne pushed a commit to branch 
OPENNLP-1477_Modernize_ExtensionLoader_to_avoid_deprecated_Class_API
in repository https://gitbox.apache.org/repos/asf/opennlp.git

commit 6f578d331ca1f50a2fc46facb04dcedc6910a694
Author: Martin Wiesner <[email protected]>
AuthorDate: Fri Mar 3 22:18:32 2023 +0100

    OPENNLP-1477 Modernize ExtensionLoader to avoid deprecated Class API
---
 .../src/main/java/opennlp/tools/util/ext/ExtensionLoader.java      | 7 +++++--
 1 file changed, 5 insertions(+), 2 deletions(-)

diff --git 
a/opennlp-tools/src/main/java/opennlp/tools/util/ext/ExtensionLoader.java 
b/opennlp-tools/src/main/java/opennlp/tools/util/ext/ExtensionLoader.java
index 216b8e78..32aec868 100644
--- a/opennlp-tools/src/main/java/opennlp/tools/util/ext/ExtensionLoader.java
+++ b/opennlp-tools/src/main/java/opennlp/tools/util/ext/ExtensionLoader.java
@@ -18,6 +18,7 @@
 package opennlp.tools.util.ext;
 
 import java.lang.reflect.Field;
+import java.lang.reflect.InvocationTargetException;
 
 import opennlp.tools.commons.Internal;
 
@@ -62,8 +63,8 @@ public class ExtensionLoader {
       if (clazz.isAssignableFrom(extClazz)) {
 
         try {
-          return (T) extClazz.newInstance();
-        } catch (InstantiationException e) {
+          return (T) extClazz.getDeclaredConstructor().newInstance();
+        } catch (InstantiationException | NoSuchMethodException e) {
           throw new ExtensionNotLoadedException(e);
         } catch (IllegalAccessException e) {
           // constructor is private. Try to load using INSTANCE
@@ -81,6 +82,8 @@ public class ExtensionLoader {
             }
           }
           throw new ExtensionNotLoadedException(e);
+        } catch (InvocationTargetException e) {
+          throw new RuntimeException(e);
         }
       }
       else {

Reply via email to