Revert "HADOOP-13353. LdapGroupsMapping getPassward shouldn't return null when IOException throws. Contributed by Zhaohao Liang and Wei-Chiu Chuang."

This reverts commit 7dbfe2f099.
This commit is contained in:
Wei-Chiu Chuang 2016-08-05 19:05:52 -07:00
parent 7dbfe2f099
commit e7863da095
2 changed files with 8 additions and 25 deletions

View File

@ -398,15 +398,19 @@ public synchronized void setConf(Configuration conf) {
}
String getPassword(Configuration conf, String alias, String defaultPass) {
String password = defaultPass;
String password = null;
try {
char[] passchars = conf.getPassword(alias);
if (passchars != null) {
password = new String(passchars);
}
} catch (IOException ioe) {
LOG.warn("Exception while trying to get password for alias " + alias
+ ": ", ioe);
else {
password = defaultPass;
}
}
catch (IOException ioe) {
LOG.warn("Exception while trying to password for alias " + alias + ": "
+ ioe.getMessage());
}
return password;
}

View File

@ -52,7 +52,6 @@
import org.junit.Before;
import org.junit.Test;
import org.mockito.Mockito;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@ -315,24 +314,4 @@ public void run() {
}
}
/**
* Make sure that when
* {@link Configuration#getPassword(String)} throws an IOException,
* {@link LdapGroupsMapping#setConf(Configuration)} does not throw an NPE.
*
* @throws Exception
*/
@Test(timeout = 10000)
public void testSetConf() throws Exception {
Configuration conf = new Configuration();
Configuration mockConf = Mockito.spy(conf);
when(mockConf.getPassword(anyString()))
.thenThrow(new IOException("injected IOException"));
// Set a dummy LDAP server URL.
mockConf.set(LdapGroupsMapping.LDAP_URL_KEY, "ldap://test");
LdapGroupsMapping groupsMapping = getGroupsMapping();
groupsMapping.setConf(mockConf);
}
}