Skip to content
Permalink
Browse files
8242292: (fs) FileSystems.getFileSystem(URI) should throw IAE if the …
…URI scheme is null

Reviewed-by: lancea, alanb
  • Loading branch information
Brian Burkhalter committed Apr 13, 2020
1 parent 83a1d70 commit 447d6499f1fccd9f10058e6275dd8964657b67a1
Showing 2 changed files with 25 additions and 3 deletions.
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2007, 2019, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2007, 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
@@ -226,6 +226,9 @@ public static FileSystem getDefault() {
*/
public static FileSystem getFileSystem(URI uri) {
String scheme = uri.getScheme();
if (scheme == null) {
throw new IllegalArgumentException(uri.toString());
}
for (FileSystemProvider provider: FileSystemProvider.installedProviders()) {
if (scheme.equalsIgnoreCase(provider.getScheme())) {
return provider.getFileSystem(uri);
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2008, 2017, 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
@@ -22,7 +22,7 @@
*/

/* @test
* @bug 4313887 6838333 8132497
* @bug 4313887 6838333 8132497 8242292
* @summary Unit test for java.nio.file.FileSystem
* @library .. /test/lib
* @build jdk.test.lib.Platform
@@ -91,6 +91,21 @@ static void checkNoUOE() throws IOException, URISyntaxException {
}
}

static void checkIAE() throws IOException {
URI absoluteUri = Path.of("foo.bar").toUri();
URI relativeUri = URI.create(absoluteUri.getSchemeSpecificPart());
System.out.println(relativeUri);
try {
FileSystem fs = FileSystems.getFileSystem(relativeUri);
throw new RuntimeException("IllegalArgumentException expected");
} catch (IllegalArgumentException iae) {
System.out.println("Expected IllegalArgumentException caught: "
+ "\"" + iae.getMessage() + "\"");
} catch (Exception e) {
throw new RuntimeException("IllegalArgumentException expected", e);
}
}

public static void main(String[] args)
throws IOException, URISyntaxException {
String os = System.getProperty("os.name");
@@ -122,6 +137,10 @@ public static void main(String[] args)
if (os.equals("Windows"))
checkSupported(fs, "owner", "dos", "acl", "user");

// sanity check throwing of IllegalArgumentException by
// FileSystems.getFileSystem(URI) if the URI scheme is null
checkIAE();

// sanity check non-throwing of UnsupportedOperationException by
// FileSystems.newFileSystem(URI, ..)
checkNoUOE();

0 comments on commit 447d649

Please sign in to comment.