This is an automated email from the ASF dual-hosted git repository.
mawiesne pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/opennlp.git
The following commit(s) were added to refs/heads/main by this push:
new cab8b54e OPENNLP-1477 Modernize ExtensionLoader to avoid deprecated
Class API (#513)
cab8b54e is described below
commit cab8b54e217b7160f87830aa8e5025f2524b7437
Author: Martin Wiesner <[email protected]>
AuthorDate: Mon Mar 6 19:24:11 2023 +0100
OPENNLP-1477 Modernize ExtensionLoader to avoid deprecated Class API (#513)
---
.../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 {