diff --git a/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/fs/DelegateToFileSystem.java b/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/fs/DelegateToFileSystem.java index 3a139781e0..cdb4f3e02c 100644 --- a/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/fs/DelegateToFileSystem.java +++ b/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/fs/DelegateToFileSystem.java @@ -24,6 +24,7 @@ import java.util.Arrays; import java.util.EnumSet; import java.util.List; +import java.util.Optional; import java.util.concurrent.CompletableFuture; import org.apache.hadoop.classification.InterfaceAudience; @@ -90,7 +91,11 @@ public FSDataOutputStream createInternal (Path f, if (!createParent) { // parent must exist. // since this.create makes parent dirs automatically // we must throw exception if parent does not exist. - final FileStatus stat = getFileStatus(f.getParent()); + Optional parentPath = f.getOptionalParentPath(); + if (!parentPath.isPresent()) { + throw new FileNotFoundException("Missing parent:" + f); + } + final FileStatus stat = getFileStatus(parentPath.get()); if (stat == null) { throw new FileNotFoundException("Missing parent:" + f); }