diff --git a/hadoop-hdfs-project/hadoop-hdfs/CHANGES.txt b/hadoop-hdfs-project/hadoop-hdfs/CHANGES.txt index 7c1685ccc9..4329d145cb 100644 --- a/hadoop-hdfs-project/hadoop-hdfs/CHANGES.txt +++ b/hadoop-hdfs-project/hadoop-hdfs/CHANGES.txt @@ -273,6 +273,8 @@ Trunk (Unreleased) HDFS-4785. Concat operation does not remove concatenated files from InodeMap. (suresh) + HDFS-4784. NPE in FSDirectory.resolvePath(). (Brandon Li via suresh) + BREAKDOWN OF HADOOP-8562 and HDFS-3602 SUBTASKS AND RELATED JIRAS HDFS-4145. Merge hdfs cmd line scripts from branch-1-win. (David Lao, diff --git a/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/FSDirectory.java b/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/FSDirectory.java index aa7bd609c6..a3150a8b20 100644 --- a/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/FSDirectory.java +++ b/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/FSDirectory.java @@ -1090,7 +1090,7 @@ int unprotectedDelete(String src, BlocksMapUpdateInfo collectedBlocks, NameNode.stateChangeLog.debug("DIR* FSDirectory.unprotectedDelete: " +src+" is removed"); } - remvoedAllFromInodesFromMap(targetNode); + removeAllFromInodesFromMap(targetNode); return filesRemoved; } @@ -1783,14 +1783,14 @@ private final void removeFromInodeMap(INode inode) { } /** Remove all the inodes under given inode from the map */ - private void remvoedAllFromInodesFromMap(INode inode) { + private void removeAllFromInodesFromMap(INode inode) { removeFromInodeMap(inode); if (!inode.isDirectory()) { return; } INodeDirectory dir = (INodeDirectory) inode; for (INode child : dir.getChildrenList()) { - remvoedAllFromInodesFromMap(child); + removeAllFromInodesFromMap(child); } dir.clearChildren(); } @@ -2258,14 +2258,18 @@ static String resolvePath(String src, byte[][] pathComponents, FSDirectory fsd) try { id = Long.valueOf(inodeId); } catch (NumberFormatException e) { - throw new FileNotFoundException( - "File for given inode path does not exist: " + src); + throw new FileNotFoundException("Invalid inode path: " + src); } if (id == INodeId.ROOT_INODE_ID && pathComponents.length == 4) { return Path.SEPARATOR; } + INode inode = fsd.getInode(id); + if (inode == null) { + throw new FileNotFoundException( + "File for given inode path does not exist: " + src); + } StringBuilder path = id == INodeId.ROOT_INODE_ID ? new StringBuilder() - : new StringBuilder(fsd.getInode(id).getFullPathName()); + : new StringBuilder(inode.getFullPathName()); for (int i = 4; i < pathComponents.length; i++) { path.append(Path.SEPARATOR).append(DFSUtil.bytes2String(pathComponents[i])); } diff --git a/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/namenode/TestINodeFile.java b/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/namenode/TestINodeFile.java index 01003a6671..3b6491f6e5 100644 --- a/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/namenode/TestINodeFile.java +++ b/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/namenode/TestINodeFile.java @@ -909,6 +909,17 @@ public void testInodePath() throws FileNotFoundException { components = INode.getPathComponents(testPath); resolvedPath = FSDirectory.resolvePath(testPath, components, fsd); assertEquals(testPath, resolvedPath); + + // Test path with nonexistent(deleted or wrong id) inode + Mockito.doReturn(null).when(fsd).getInode(Mockito.anyLong()); + testPath = "/.reserved/.inodes/1234"; + components = INode.getPathComponents(testPath); + try { + String realPath = FSDirectory.resolvePath(testPath, components, fsd); + fail("Path should not be resolved:" + realPath); + } catch (IOException e) { + assertTrue(e instanceof FileNotFoundException); + } } /**