This is an automated email from the ASF dual-hosted git repository.
william pushed a commit to branch branch-1.8
in repository https://gitbox.apache.org/repos/asf/orc.git
The following commit(s) were added to refs/heads/branch-1.8 by this push:
new 7ca5188e6 ORC-1227: Use `Constructor.newInstance` instead of
`Class.newInstance`
7ca5188e6 is described below
commit 7ca5188e6dda033f5d5df06bee61a075d9492517
Author: William Hyun <[email protected]>
AuthorDate: Mon Jul 25 22:33:06 2022 -0700
ORC-1227: Use `Constructor.newInstance` instead of `Class.newInstance`
### What changes were proposed in this pull request?
This PR aims to use `Constructor.newInstance` instead of
`Class.newInstance`.
### Why are the changes needed?
`Class.newInstance` is deprecated at Java 9.
### How was this patch tested?
Pass the CIs.
Closes #1195 from williamhyun/getdeclaredconstructor.
Authored-by: William Hyun <[email protected]>
Signed-off-by: William Hyun <[email protected]>
(cherry picked from commit 2cac4a152d70dff6bf4c93f96e93149af6486268)
Signed-off-by: William Hyun <[email protected]>
---
java/core/src/java/org/apache/orc/impl/HadoopShimsFactory.java | 8 ++++++--
1 file changed, 6 insertions(+), 2 deletions(-)
diff --git a/java/core/src/java/org/apache/orc/impl/HadoopShimsFactory.java
b/java/core/src/java/org/apache/orc/impl/HadoopShimsFactory.java
index f146c7fd8..1cd98e067 100644
--- a/java/core/src/java/org/apache/orc/impl/HadoopShimsFactory.java
+++ b/java/core/src/java/org/apache/orc/impl/HadoopShimsFactory.java
@@ -22,6 +22,8 @@ import org.apache.hadoop.util.VersionInfo;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
+import java.lang.reflect.InvocationTargetException;
+
/**
* The factory for getting the proper version of the Hadoop shims.
*/
@@ -41,8 +43,10 @@ public class HadoopShimsFactory {
try {
Class<? extends HadoopShims> cls =
(Class<? extends HadoopShims>) Class.forName(name);
- return cls.newInstance();
- } catch (InstantiationException | IllegalAccessException |
ClassNotFoundException e) {
+ return cls.getDeclaredConstructor().newInstance();
+ } catch (ClassNotFoundException | NoSuchMethodException |
SecurityException |
+ InstantiationException | IllegalAccessException |
IllegalArgumentException |
+ InvocationTargetException e) {
throw new IllegalStateException("Can't create shims for " + name, e);
}
}