You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@orc.apache.org by wi...@apache.org on 2022/07/26 05:33:48 UTC
[orc] branch branch-1.7 updated: ORC-1227: Use `Constructor.newInstance` instead of `Class.newInstance`
This is an automated email from the ASF dual-hosted git repository.
william pushed a commit to branch branch-1.7
in repository https://gitbox.apache.org/repos/asf/orc.git
The following commit(s) were added to refs/heads/branch-1.7 by this push:
new 2ee53111b ORC-1227: Use `Constructor.newInstance` instead of `Class.newInstance`
2ee53111b is described below
commit 2ee53111be9fc049774752e5d1ace730bff335c9
Author: William Hyun <wi...@apache.org>
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 <wi...@apache.org>
Signed-off-by: William Hyun <wi...@apache.org>
(cherry picked from commit 2cac4a152d70dff6bf4c93f96e93149af6486268)
Signed-off-by: William Hyun <wi...@apache.org>
---
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);
}
}