This is an automated email from the ASF dual-hosted git repository.

gabota pushed a commit to branch trunk
in repository https://gitbox.apache.org/repos/asf/hadoop.git


The following commit(s) were added to refs/heads/trunk by this push:
     new aa664d7  HADOOP-16138. hadoop fs mkdir / of nonexistent abfs container 
raises NPE (#1302). Contributed by Gabor Bota.
aa664d7 is described below

commit aa664d72595ddfcb1a1bf082381bb222e59db354
Author: Gabor Bota <gabor.b...@cloudera.com>
AuthorDate: Mon Sep 23 13:29:01 2019 +0200

    HADOOP-16138. hadoop fs mkdir / of nonexistent abfs container raises NPE 
(#1302). Contributed by Gabor Bota.
    
    Change-Id: I2f637865c871e400b95fe7ddaa24bf99fa192023
---
 .../java/org/apache/hadoop/fs/shell/Mkdir.java     | 11 +++-
 .../fs/azurebfs/ITestAzureBlobFileSystemCLI.java   | 65 ++++++++++++++++++++++
 2 files changed, 75 insertions(+), 1 deletion(-)

diff --git 
a/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/fs/shell/Mkdir.java
 
b/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/fs/shell/Mkdir.java
index 5828b0b..1780cda 100644
--- 
a/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/fs/shell/Mkdir.java
+++ 
b/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/fs/shell/Mkdir.java
@@ -73,8 +73,17 @@ class Mkdir extends FsCommand {
       // we want a/b
       final Path itemPath = new Path(item.path.toString());
       final Path itemParentPath = itemPath.getParent();
+
+      if(itemParentPath == null) {
+        throw new PathNotFoundException(String.format(
+            "Item: %s parent's path is null. This can happen if mkdir is " +
+                "called on root, so there's no parent.", itemPath.toString()));
+      }
+
       if (!item.fs.exists(itemParentPath)) {
-        throw new PathNotFoundException(itemParentPath.toString());
+        throw new PathNotFoundException(String.format(
+            "mkdir failed for path: %s. Item parent path not found: %s.",
+        itemPath.toString(), itemParentPath.toString()));
       }
     }
     if (!item.fs.mkdirs(item.path)) {
diff --git 
a/hadoop-tools/hadoop-azure/src/test/java/org/apache/hadoop/fs/azurebfs/ITestAzureBlobFileSystemCLI.java
 
b/hadoop-tools/hadoop-azure/src/test/java/org/apache/hadoop/fs/azurebfs/ITestAzureBlobFileSystemCLI.java
new file mode 100644
index 0000000..c88b545
--- /dev/null
+++ 
b/hadoop-tools/hadoop-azure/src/test/java/org/apache/hadoop/fs/azurebfs/ITestAzureBlobFileSystemCLI.java
@@ -0,0 +1,65 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.hadoop.fs.azurebfs;
+
+import java.util.UUID;
+
+import org.junit.Test;
+
+import org.apache.hadoop.fs.FsShell;
+import org.apache.hadoop.conf.Configuration;
+
+import static 
org.apache.hadoop.fs.azurebfs.constants.ConfigurationKeys.AZURE_CREATE_REMOTE_FILESYSTEM_DURING_INITIALIZATION;
+import static 
org.apache.hadoop.fs.azurebfs.constants.FileSystemUriSchemes.ABFS_SCHEME;
+import static 
org.apache.hadoop.fs.azurebfs.constants.TestConfigurationKeys.FS_AZURE_ABFS_ACCOUNT_NAME;
+
+/**
+ * Tests for Azure Blob FileSystem CLI.
+ */
+public class ITestAzureBlobFileSystemCLI extends AbstractAbfsIntegrationTest {
+
+  public  ITestAzureBlobFileSystemCLI() throws Exception {
+    super();
+    final AbfsConfiguration conf = getConfiguration();
+    conf.setBoolean(AZURE_CREATE_REMOTE_FILESYSTEM_DURING_INITIALIZATION, 
false);
+  }
+
+  /**
+   * Test for HADOOP-16138: hadoop fs mkdir / of nonexistent abfs
+   * container raises NPE.
+   *
+   * The command should return with 1 exit status, but there should be no NPE.
+   *
+   * @throws Exception
+   */
+  @Test
+  public void testMkdirRootNonExistentContainer() throws Exception {
+    final Configuration rawConf = getRawConfiguration();
+    FsShell fsShell = new FsShell(rawConf);
+    final String account =
+        rawConf.get(FS_AZURE_ABFS_ACCOUNT_NAME, null);
+
+    String nonExistentContainer = "nonexistent-" + UUID.randomUUID();
+
+    int result = fsShell.run(new String[] { "-mkdir",
+        ABFS_SCHEME + "://" + nonExistentContainer + "@" + account + "/" });
+
+    assertEquals(1, result);
+  }
+}


---------------------------------------------------------------------
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