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

weichiu pushed a commit to branch branch-2
in repository https://gitbox.apache.org/repos/asf/hbase.git


The following commit(s) were added to refs/heads/branch-2 by this push:
     new 669ff7b  Remove the reflection and call Configuration.getPassword() 
directly. (#3408)
669ff7b is described below

commit 669ff7be82fad0b94b2053099bf775025c451d8d
Author: Wei-Chiu Chuang <weic...@apache.org>
AuthorDate: Tue Jun 22 18:15:02 2021 -0700

    Remove the reflection and call Configuration.getPassword() directly. (#3408)
    
    Reviewed-by: Viraj Jasani <vjas...@apache.org>
    Reviewed-by: Wellington Chevreuil <wchevre...@apache.org>
    Reviewed-by: litao <tomlees...@gmail.com>
    (cherry picked from commit 9a324bd4d07e4e00ac559f245315993155619989)
---
 .../apache/hadoop/hbase/HBaseConfiguration.java    | 37 +++++-----------------
 1 file changed, 8 insertions(+), 29 deletions(-)

diff --git 
a/hbase-common/src/main/java/org/apache/hadoop/hbase/HBaseConfiguration.java 
b/hbase-common/src/main/java/org/apache/hadoop/hbase/HBaseConfiguration.java
index e831774..fab0835 100644
--- a/hbase-common/src/main/java/org/apache/hadoop/hbase/HBaseConfiguration.java
+++ b/hbase-common/src/main/java/org/apache/hadoop/hbase/HBaseConfiguration.java
@@ -254,35 +254,14 @@ public class HBaseConfiguration extends Configuration {
    */
   public static String getPassword(Configuration conf, String alias,
       String defPass) throws IOException {
-    String passwd = null;
-    try {
-      Method m = Configuration.class.getMethod("getPassword", String.class);
-      char[] p = (char[]) m.invoke(conf, alias);
-      if (p != null) {
-        LOG.debug(String.format("Config option \"%s\" was found through" +
-            " the Configuration getPassword method.", alias));
-        passwd = new String(p);
-      } else {
-        LOG.debug(String.format(
-            "Config option \"%s\" was not found. Using provided default value",
-            alias));
-        passwd = defPass;
-      }
-    } catch (NoSuchMethodException e) {
-      // this is a version of Hadoop where the credential
-      //provider API doesn't exist yet
-      LOG.debug(String.format(
-          "Credential.getPassword method is not available." +
-              " Falling back to configuration."));
-      passwd = conf.get(alias, defPass);
-    } catch (SecurityException e) {
-      throw new IOException(e.getMessage(), e);
-    } catch (IllegalAccessException e) {
-      throw new IOException(e.getMessage(), e);
-    } catch (IllegalArgumentException e) {
-      throw new IOException(e.getMessage(), e);
-    } catch (InvocationTargetException e) {
-      throw new IOException(e.getMessage(), e);
+    String passwd;
+    char[] p = conf.getPassword(alias);
+    if (p != null) {
+      LOG.debug("Config option {} was found through the Configuration 
getPassword method.", alias);
+      passwd = new String(p);
+    } else {
+      LOG.debug("Config option {} was not found. Using provided default 
value", alias);
+      passwd = defPass;
     }
     return passwd;
   }

Reply via email to