HDFS-13816. dfs.getQuotaUsage() throws NPE on non-existent dir instead of FileNotFoundException. Contributed by Vinayakumar B.
(cherry picked from commit b09828145432c8d986ac8f05ec33608d8e611328) Project: http://git-wip-us.apache.org/repos/asf/hadoop/repo Commit: http://git-wip-us.apache.org/repos/asf/hadoop/commit/8569555f Tree: http://git-wip-us.apache.org/repos/asf/hadoop/tree/8569555f Diff: http://git-wip-us.apache.org/repos/asf/hadoop/diff/8569555f Branch: refs/heads/branch-3.0 Commit: 8569555fd1f244b298c7d025d2fc7d2ac6b181f7 Parents: c2e65ca Author: Vinayakumar B <vinayakum...@apache.org> Authored: Mon Nov 26 18:22:32 2018 +0530 Committer: Vinayakumar B <vinayakum...@apache.org> Committed: Mon Nov 26 18:23:20 2018 +0530 ---------------------------------------------------------------------- .../hadoop/hdfs/server/namenode/FSDirStatAndListingOp.java | 4 ++++ .../src/test/java/org/apache/hadoop/hdfs/TestQuota.java | 8 ++++++++ 2 files changed, 12 insertions(+) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/hadoop/blob/8569555f/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/FSDirStatAndListingOp.java ---------------------------------------------------------------------- diff --git a/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/FSDirStatAndListingOp.java b/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/FSDirStatAndListingOp.java index c5fa4c7..4baf8b5 100644 --- a/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/FSDirStatAndListingOp.java +++ b/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/FSDirStatAndListingOp.java @@ -563,6 +563,10 @@ class FSDirStatAndListingOp { fsd.readLock(); try { INode targetNode = iip.getLastINode(); + if (targetNode == null) { + throw new FileNotFoundException( + "File/Directory does not exist: " + iip.getPath()); + } QuotaUsage usage = null; if (targetNode.isDirectory()) { DirectoryWithQuotaFeature feature = http://git-wip-us.apache.org/repos/asf/hadoop/blob/8569555f/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/TestQuota.java ---------------------------------------------------------------------- diff --git a/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/TestQuota.java b/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/TestQuota.java index 2e99aa3..5398aea 100644 --- a/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/TestQuota.java +++ b/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/TestQuota.java @@ -28,6 +28,7 @@ import static org.junit.Assert.assertTrue; import static org.junit.Assert.fail; import java.io.ByteArrayOutputStream; +import java.io.FileNotFoundException; import java.io.IOException; import java.io.OutputStream; import java.io.PrintStream; @@ -332,6 +333,13 @@ public class TestQuota { // 14a: set quota on a non-existent directory Path nonExistentPath = new Path(dir, "test1"); assertFalse(dfs.exists(nonExistentPath)); + try { + compareQuotaUsage(null, dfs, nonExistentPath); + fail("Expected FileNotFoundException"); + } catch (FileNotFoundException fnfe) { + GenericTestUtils.assertExceptionContains( + "File/Directory does not exist: " + nonExistentPath, fnfe); + } args = new String[]{"-setQuota", "1", nonExistentPath.toString()}; runCommand(admin, args, true); runCommand(admin, true, "-setSpaceQuota", "1g", // for space quota --------------------------------------------------------------------- To unsubscribe, e-mail: common-commits-unsubscr...@hadoop.apache.org For additional commands, e-mail: common-commits-h...@hadoop.apache.org