mirror of
https://github.com/openjdk/jdk.git
synced 2025-08-28 15:24:43 +02:00
8254876: (fs) NullPointerException not thrown when first argument to Path.of or Paths.get is null
Reviewed-by: rriggs, alanb
This commit is contained in:
parent
b46d73bee8
commit
450452bb8c
3 changed files with 17 additions and 3 deletions
|
@ -257,6 +257,7 @@ abstract class UnixFileSystem
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public final Path getPath(String first, String... more) {
|
public final Path getPath(String first, String... more) {
|
||||||
|
Objects.requireNonNull(first);
|
||||||
String path;
|
String path;
|
||||||
if (more.length == 0) {
|
if (more.length == 0) {
|
||||||
path = first;
|
path = first;
|
||||||
|
|
|
@ -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.
|
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||||
*
|
*
|
||||||
* This code is free software; you can redistribute it and/or modify it
|
* This code is free software; you can redistribute it and/or modify it
|
||||||
|
@ -211,6 +211,7 @@ class WindowsFileSystem
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public final Path getPath(String first, String... more) {
|
public final Path getPath(String first, String... more) {
|
||||||
|
Objects.requireNonNull(first);
|
||||||
String path;
|
String path;
|
||||||
if (more.length == 0) {
|
if (more.length == 0) {
|
||||||
path = first;
|
path = first;
|
||||||
|
|
|
@ -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.
|
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||||
*
|
*
|
||||||
* This code is free software; you can redistribute it and/or modify it
|
* This code is free software; you can redistribute it and/or modify it
|
||||||
|
@ -22,7 +22,7 @@
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/* @test
|
/* @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
|
* @summary Unit test for java.nio.file.Path path operations
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
@ -2042,6 +2042,18 @@ public class PathOps {
|
||||||
static void npes() {
|
static void npes() {
|
||||||
header("NullPointerException");
|
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");
|
Path path = FileSystems.getDefault().getPath("foo");
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue