HADOOP-12252. LocalDirAllocator should not throw NPE with empty string configuration. Contributed by Zhihai Xu

(cherry picked from commit 52c1f272ec)

Conflicts:
	hadoop-common-project/hadoop-common/CHANGES.txt
This commit is contained in:
Zhihai Xu 2015-09-24 11:48:11 -07:00
parent 9bb6fba759
commit 4ba0febd58
3 changed files with 30 additions and 3 deletions

View File

@ -579,6 +579,9 @@ Release 2.8.0 - UNRELEASED
required context item is not configured required context item is not configured
(Brahma Reddy Battula via harsh) (Brahma Reddy Battula via harsh)
HADOOP-12252. LocalDirAllocator should not throw NPE with empty string
configuration. (Zhihai Xu)
OPTIMIZATIONS OPTIMIZATIONS
HADOOP-12051. ProtobufRpcEngine.invoke() should use Exception.toString() HADOOP-12051. ProtobufRpcEngine.invoke() should use Exception.toString()

View File

@ -250,9 +250,9 @@ public class LocalDirAllocator {
private int dirNumLastAccessed; private int dirNumLastAccessed;
private Random dirIndexRandomizer = new Random(); private Random dirIndexRandomizer = new Random();
private FileSystem localFS; private FileSystem localFS;
private DF[] dirDF; private DF[] dirDF = new DF[0];
private String contextCfgItemName; private String contextCfgItemName;
private String[] localDirs; private String[] localDirs = new String[0];
private String savedLocalDirs = ""; private String savedLocalDirs = "";
public AllocatorPerContext(String contextCfgItemName) { public AllocatorPerContext(String contextCfgItemName) {

View File

@ -26,6 +26,7 @@ import java.util.Iterator;
import java.util.NoSuchElementException; import java.util.NoSuchElementException;
import org.apache.hadoop.conf.Configuration; import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.util.DiskChecker.DiskErrorException;
import org.apache.hadoop.util.Shell; import org.apache.hadoop.util.Shell;
import org.junit.runner.RunWith; import org.junit.runner.RunWith;
@ -312,7 +313,30 @@ public class TestLocalDirAllocator {
} catch (IOException e) { } catch (IOException e) {
assertEquals(CONTEXT + " not configured", e.getMessage()); assertEquals(CONTEXT + " not configured", e.getMessage());
} catch (NullPointerException e) { } catch (NullPointerException e) {
fail("Lack of configuration should not have thrown an NPE."); fail("Lack of configuration should not have thrown a NPE.");
}
String NEW_CONTEXT = CONTEXT + ".new";
conf1.set(NEW_CONTEXT, "");
LocalDirAllocator newDirAllocator = new LocalDirAllocator(NEW_CONTEXT);
try {
newDirAllocator.getLocalPathForWrite("/test", conf1);
fail("Exception not thrown when " + NEW_CONTEXT +
" is set to empty string");
} catch (IOException e) {
assertTrue(e instanceof DiskErrorException);
} catch (NullPointerException e) {
fail("Wrong configuration should not have thrown a NPE.");
}
try {
newDirAllocator.getLocalPathToRead("/test", conf1);
fail("Exception not thrown when " + NEW_CONTEXT +
" is set to empty string");
} catch (IOException e) {
assertTrue(e instanceof DiskErrorException);
} catch (NullPointerException e) {
fail("Wrong configuration should not have thrown a NPE.");
} }
} }