8242292: (fs) FileSystems.getFileSystem(URI) should throw IAE if the URI scheme is null

Reviewed-by: lancea, alanb
diff --git a/src/java.base/share/classes/java/nio/file/FileSystems.java b/src/java.base/share/classes/java/nio/file/FileSystems.java
index 03fb460..e492d7e 100644
--- a/src/java.base/share/classes/java/nio/file/FileSystems.java
+++ b/src/java.base/share/classes/java/nio/file/FileSystems.java
@@ -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 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);
diff --git a/test/jdk/java/nio/file/FileSystem/Basic.java b/test/jdk/java/nio/file/FileSystem/Basic.java
index 83f2acb..4613523 100644
--- a/test/jdk/java/nio/file/FileSystem/Basic.java
+++ b/test/jdk/java/nio/file/FileSystem/Basic.java
@@ -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 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 @@
         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();