Remove the reflection and call Configuration.getPassword() directly. (#3408)

Reviewed-by: Viraj Jasani <vjasani@apache.org>
Reviewed-by: Wellington Chevreuil <wchevreuil@apache.org>
Reviewed-by: litao <tomleescut@gmail.com>
This commit is contained in:
Wei-Chiu Chuang 2021-06-22 18:15:02 -07:00 committed by GitHub
parent d9bd29603b
commit 9a324bd4d0
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 8 additions and 29 deletions

View File

@ -200,35 +200,14 @@ public class HBaseConfiguration extends Configuration {
*/ */
public static String getPassword(Configuration conf, String alias, public static String getPassword(Configuration conf, String alias,
String defPass) throws IOException { String defPass) throws IOException {
String passwd = null; String passwd;
try { char[] p = conf.getPassword(alias);
Method m = Configuration.class.getMethod("getPassword", String.class); if (p != null) {
char[] p = (char[]) m.invoke(conf, alias); LOG.debug("Config option {} was found through the Configuration getPassword method.", alias);
if (p != null) { passwd = new String(p);
LOG.debug(String.format("Config option \"%s\" was found through" + } else {
" the Configuration getPassword method.", alias)); LOG.debug("Config option {} was not found. Using provided default value", alias);
passwd = new String(p); passwd = defPass;
} 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);
} }
return passwd; return passwd;
} }