diff --git a/hadoop-common-project/hadoop-common/CHANGES.txt b/hadoop-common-project/hadoop-common/CHANGES.txt index b36d1636b9..5b4066b80f 100644 --- a/hadoop-common-project/hadoop-common/CHANGES.txt +++ b/hadoop-common-project/hadoop-common/CHANGES.txt @@ -234,6 +234,10 @@ Trunk (Unreleased) HADOOP-8815. RandomDatum needs to override hashCode(). (Brandon Li via suresh) + HADOOP-8436. NPE In getLocalPathForWrite ( path, conf ) when the + required context item is not configured + (Brahma Reddy Battula via harsh) + OPTIMIZATIONS HADOOP-7761. Improve the performance of raw comparisons. (todd) diff --git a/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/fs/LocalDirAllocator.java b/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/fs/LocalDirAllocator.java index 3e305930fd..16a1c99b5c 100644 --- a/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/fs/LocalDirAllocator.java +++ b/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/fs/LocalDirAllocator.java @@ -265,6 +265,9 @@ public AllocatorPerContext(String contextCfgItemName) { private synchronized void confChanged(Configuration conf) throws IOException { String newLocalDirs = conf.get(contextCfgItemName); + if (null == newLocalDirs) { + throw new IOException(contextCfgItemName + " not configured"); + } if (!newLocalDirs.equals(savedLocalDirs)) { localDirs = StringUtils.getTrimmedStrings(newLocalDirs); localFS = FileSystem.getLocal(conf); diff --git a/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/fs/TestLocalDirAllocator.java b/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/fs/TestLocalDirAllocator.java index 3b76a56feb..7a4618e650 100644 --- a/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/fs/TestLocalDirAllocator.java +++ b/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/fs/TestLocalDirAllocator.java @@ -293,6 +293,23 @@ public void testLocalPathForWriteDirCreation() throws IOException { } } + /* + * Test when mapred.local.dir not configured and called + * getLocalPathForWrite + */ + @Test + public void testShouldNotthrowNPE() throws Exception { + Configuration conf1 = new Configuration(); + try { + dirAllocator.getLocalPathForWrite("/test", conf1); + fail("Exception not thrown when " + CONTEXT + " is not set"); + } catch (IOException e) { + assertEquals(CONTEXT + " not configured", e.getMessage()); + } catch (NullPointerException e) { + fail("Lack of configuration should not have thrown an NPE."); + } + } + /** Test no side effect files are left over. After creating a temp * temp file, remove both the temp file and its parent. Verify that * no files or directories are left over as can happen when File objects