Skip to content

Commit

Permalink
8254876: (fs) NullPointerException not thrown when first argument to …
Browse files Browse the repository at this point in the history
…Path.of or Paths.get is null

Reviewed-by: rriggs, alanb
  • Loading branch information
Brian Burkhalter committed Nov 3, 2020
1 parent b46d73b commit 450452b
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 3 deletions.
1 change: 1 addition & 0 deletions src/java.base/unix/classes/sun/nio/fs/UnixFileSystem.java
Original file line number Diff line number Diff line change
Expand Up @@ -257,6 +257,7 @@ public Iterator<FileStore> iterator() {

@Override
public final Path getPath(String first, String... more) {
Objects.requireNonNull(first);
String path;
if (more.length == 0) {
path = first;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2008, 2015, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2008, 2020, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
Expand Down Expand Up @@ -211,6 +211,7 @@ public Set<String> supportedFileAttributeViews() {

@Override
public final Path getPath(String first, String... more) {
Objects.requireNonNull(first);
String path;
if (more.length == 0) {
path = first;
Expand Down
16 changes: 14 additions & 2 deletions test/jdk/java/nio/file/Path/PathOps.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2008, 2016, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2008, 2020, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
Expand All @@ -22,7 +22,7 @@
*/

/* @test
* @bug 4313887 6838333 6925932 7006126 8037945 8072495 8140449
* @bug 4313887 6838333 6925932 7006126 8037945 8072495 8140449 8254876
* @summary Unit test for java.nio.file.Path path operations
*/

Expand Down Expand Up @@ -2042,6 +2042,18 @@ static void doUnixTests() {
static void npes() {
header("NullPointerException");

try {
Path.of(null, "foo");
throw new RuntimeException("NullPointerException not thrown");
} catch (NullPointerException npe) {
}

try {
Path.of("foo", null);
throw new RuntimeException("NullPointerException not thrown");
} catch (NullPointerException npe) {
}

Path path = FileSystems.getDefault().getPath("foo");

try {
Expand Down

1 comment on commit 450452b

@openjdk-notifier
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.