HADOOP-17689. Avoid Potential NPE in org.apache.hadoop.fs (#3008)

Signed-off-by: Takanobu Asanuma <tasanuma@apache.org>
This commit is contained in:
Viraj Jasani 2021-05-12 20:35:58 +05:30 committed by GitHub
parent 626be24c3e
commit fdd20a3cf4
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -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<Path> 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);
}