Skip to content

Commit 450452b

Browse files
author
Brian Burkhalter
committed
8254876: (fs) NullPointerException not thrown when first argument to Path.of or Paths.get is null
Reviewed-by: rriggs, alanb
1 parent b46d73b commit 450452b

File tree

3 files changed

+17
-3
lines changed

3 files changed

+17
-3
lines changed

src/java.base/unix/classes/sun/nio/fs/UnixFileSystem.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -257,6 +257,7 @@ public Iterator<FileStore> iterator() {
257257

258258
@Override
259259
public final Path getPath(String first, String... more) {
260+
Objects.requireNonNull(first);
260261
String path;
261262
if (more.length == 0) {
262263
path = first;

src/java.base/windows/classes/sun/nio/fs/WindowsFileSystem.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2008, 2015, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2008, 2020, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* This code is free software; you can redistribute it and/or modify it
@@ -211,6 +211,7 @@ public Set<String> supportedFileAttributeViews() {
211211

212212
@Override
213213
public final Path getPath(String first, String... more) {
214+
Objects.requireNonNull(first);
214215
String path;
215216
if (more.length == 0) {
216217
path = first;

test/jdk/java/nio/file/Path/PathOps.java

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2008, 2016, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2008, 2020, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* This code is free software; you can redistribute it and/or modify it
@@ -22,7 +22,7 @@
2222
*/
2323

2424
/* @test
25-
* @bug 4313887 6838333 6925932 7006126 8037945 8072495 8140449
25+
* @bug 4313887 6838333 6925932 7006126 8037945 8072495 8140449 8254876
2626
* @summary Unit test for java.nio.file.Path path operations
2727
*/
2828

@@ -2042,6 +2042,18 @@ static void doUnixTests() {
20422042
static void npes() {
20432043
header("NullPointerException");
20442044

2045+
try {
2046+
Path.of(null, "foo");
2047+
throw new RuntimeException("NullPointerException not thrown");
2048+
} catch (NullPointerException npe) {
2049+
}
2050+
2051+
try {
2052+
Path.of("foo", null);
2053+
throw new RuntimeException("NullPointerException not thrown");
2054+
} catch (NullPointerException npe) {
2055+
}
2056+
20452057
Path path = FileSystems.getDefault().getPath("foo");
20462058

20472059
try {

0 commit comments

Comments
 (0)