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/538757ed
Tree: http://git-wip-us.apache.org/repos/asf/hadoop/tree/538757ed
Diff: http://git-wip-us.apache.org/repos/asf/hadoop/diff/538757ed

Branch: refs/heads/branch-3.2
Commit: 538757ed49b084a8dc73d4843833bd2ad58fbee5
Parents: 1b937d7
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:09 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/538757ed/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 7e22ae1..01de236 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
@@ -565,6 +565,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/538757ed/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 b16782c..1c4855f 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

Reply via email to