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
  • Loading branch information
bplb committed Nov 2, 2020
1 parent 05bcd67 commit 7230ae9
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 2 deletions.
3 changes: 3 additions & 0 deletions src/java.base/unix/classes/sun/nio/fs/UnixFileSystem.java
Original file line number Diff line number Diff line change
Expand Up @@ -261,6 +261,9 @@ public final Path getPath(String first, String... more) {
if (more.length == 0) {
path = first;
} else {
if (first == null) {
throw new NullPointerException();
}
StringBuilder sb = new StringBuilder();
sb.append(first);
for (String segment: more) {
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 @@ -215,6 +215,9 @@ public final Path getPath(String first, String... more) {
if (more.length == 0) {
path = first;
} else {
if (first == null) {
throw new NullPointerException();
}
StringBuilder sb = new StringBuilder();
sb.append(first);
for (String segment: more) {
Expand Down
8 changes: 7 additions & 1 deletion 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 Down Expand Up @@ -2042,6 +2042,12 @@ static void doUnixTests() {
static void npes() {
header("NullPointerException");

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

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

try {
Expand Down

0 comments on commit 7230ae9

Please sign in to comment.