HADOOP-17689. Avoid Potential NPE in org.apache.hadoop.fs (#3008)
Signed-off-by: Takanobu Asanuma <tasanuma@apache.org>
This commit is contained in:
parent
626be24c3e
commit
fdd20a3cf4
@ -24,6 +24,7 @@
|
|||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
import java.util.EnumSet;
|
import java.util.EnumSet;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.Optional;
|
||||||
import java.util.concurrent.CompletableFuture;
|
import java.util.concurrent.CompletableFuture;
|
||||||
|
|
||||||
import org.apache.hadoop.classification.InterfaceAudience;
|
import org.apache.hadoop.classification.InterfaceAudience;
|
||||||
@ -90,7 +91,11 @@ public FSDataOutputStream createInternal (Path f,
|
|||||||
if (!createParent) { // parent must exist.
|
if (!createParent) { // parent must exist.
|
||||||
// since this.create makes parent dirs automatically
|
// since this.create makes parent dirs automatically
|
||||||
// we must throw exception if parent does not exist.
|
// 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) {
|
if (stat == null) {
|
||||||
throw new FileNotFoundException("Missing parent:" + f);
|
throw new FileNotFoundException("Missing parent:" + f);
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user