--- old/src/java.base/linux/classes/sun/nio/fs/LinuxFileSystemProvider.java 2018-03-07 17:30:54.000000000 -0800 +++ new/src/java.base/linux/classes/sun/nio/fs/LinuxFileSystemProvider.java 2018-03-07 17:30:53.000000000 -0800 @@ -103,8 +103,8 @@ @Override FileTypeDetector getFileTypeDetector() { String userHome = GetPropertyAction.privilegedGetProperty("user.home"); - Path userMimeTypes = Paths.get(userHome, ".mime.types"); - Path etcMimeTypes = Paths.get("/etc/mime.types"); + Path userMimeTypes = Path.get(userHome, ".mime.types"); + Path etcMimeTypes = Path.get("/etc/mime.types"); return chain(new MimeTypesFileTypeDetector(userMimeTypes), new MimeTypesFileTypeDetector(etcMimeTypes)); --- old/src/java.base/macosx/classes/sun/nio/fs/MacOSXFileSystemProvider.java 2018-03-07 17:30:54.000000000 -0800 +++ new/src/java.base/macosx/classes/sun/nio/fs/MacOSXFileSystemProvider.java 2018-03-07 17:30:54.000000000 -0800 @@ -26,7 +26,6 @@ package sun.nio.fs; import java.nio.file.Path; -import java.nio.file.Paths; import java.nio.file.spi.FileTypeDetector; import sun.security.action.GetPropertyAction; @@ -46,7 +45,7 @@ @Override FileTypeDetector getFileTypeDetector() { - Path userMimeTypes = Paths.get(GetPropertyAction + Path userMimeTypes = Path.get(GetPropertyAction .privilegedGetProperty("user.home"), ".mime.types"); return chain(new MimeTypesFileTypeDetector(userMimeTypes), --- old/src/java.base/share/classes/java/lang/invoke/ProxyClassesDumper.java 2018-03-07 17:30:55.000000000 -0800 +++ new/src/java.base/share/classes/java/lang/invoke/ProxyClassesDumper.java 2018-03-07 17:30:55.000000000 -0800 @@ -30,7 +30,6 @@ import java.nio.file.Files; import java.nio.file.InvalidPathException; import java.nio.file.Path; -import java.nio.file.Paths; import java.security.AccessController; import java.security.PrivilegedAction; import java.util.Objects; @@ -63,7 +62,7 @@ } try { path = path.trim(); - final Path dir = Paths.get(path.length() == 0 ? "." : path); + final Path dir = Path.get(path.length() == 0 ? "." : path); AccessController.doPrivileged(new PrivilegedAction<>() { @Override public Void run() { --- old/src/java.base/share/classes/java/lang/reflect/ProxyGenerator.java 2018-03-07 17:30:56.000000000 -0800 +++ new/src/java.base/share/classes/java/lang/reflect/ProxyGenerator.java 2018-03-07 17:30:56.000000000 -0800 @@ -34,7 +34,6 @@ import java.lang.reflect.Method; import java.nio.file.Files; import java.nio.file.Path; -import java.nio.file.Paths; import java.util.ArrayList; import java.util.HashMap; import java.util.LinkedList; @@ -346,11 +345,11 @@ int i = name.lastIndexOf('.'); Path path; if (i > 0) { - Path dir = Paths.get(name.substring(0, i).replace('.', File.separatorChar)); + Path dir = Path.get(name.substring(0, i).replace('.', File.separatorChar)); Files.createDirectories(dir); path = dir.resolve(name.substring(i+1, name.length()) + ".class"); } else { - path = Paths.get(name + ".class"); + path = Path.get(name + ".class"); } Files.write(path, classFile); return null; --- old/src/java.base/share/classes/java/nio/file/Path.java 2018-03-07 17:30:57.000000000 -0800 +++ new/src/java.base/share/classes/java/nio/file/Path.java 2018-03-07 17:30:56.000000000 -0800 @@ -1,5 +1,5 @@ /* - * Copyright (c) 2007, 2013, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2007, 2018, 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 @@ -28,6 +28,7 @@ import java.io.File; import java.io.IOException; import java.net.URI; +import java.nio.file.spi.FileSystemProvider; import java.util.Iterator; import java.util.NoSuchElementException; @@ -93,13 +94,121 @@ * multiple concurrent threads. * * @since 1.7 - * @see Paths */ public interface Path extends Comparable, Iterable, Watchable { /** + * Converts a path string, or a sequence of strings that when joined form + * a path string, to a {@code Path}. If {@code more} does not specify any + * elements then the value of the {@code first} parameter is the path string + * to convert. If {@code more} specifies one or more elements then each + * non-empty string, including {@code first}, is considered to be a sequence + * of name elements and is joined to form a path string. + * The details as to how the Strings are joined is provider specific but + * typically they will be joined using the {@link FileSystem#getSeparator + * name-separator} as the separator. For example, if the name separator is + * "{@code /}" and {@code getPath("/foo","bar","gus")} is invoked, then the + * path string {@code "/foo/bar/gus"} is converted to a {@code Path}. + * A {@code Path} representing an empty path is returned if {@code first} + * is the empty string and {@code more} does not contain any non-empty + * strings. + * + *

The {@code Path} is obtained by invoking the {@link FileSystem#getPath + * getPath} method of the {@link FileSystems#getDefault default} {@link + * FileSystem}. + * + *

Note that while this method is very convenient, using it will imply + * an assumed reference to the default {@code FileSystem} and limit the + * utility of the calling code. Hence it should not be used in library code + * intended for flexible reuse. A more flexible alternative is to use an + * existing {@code Path} instance as an anchor, such as: + *

+     *     Path dir = ...
+     *     Path path = dir.resolve("file");
+     * 
+ * + * @param first + * the path string or initial part of the path string + * @param more + * additional strings to be joined to form the path string + * + * @return the resulting {@code Path} + * + * @throws InvalidPathException + * if the path string cannot be converted to a {@code Path} + * + * @see FileSystem#getPath + */ + public static Path get(String first, String... more) { + return FileSystems.getDefault().getPath(first, more); + } + + /** + * Converts the given URI to a {@link Path} object. + * + *

This method iterates over the {@link FileSystemProvider#installedProviders() + * installed} providers to locate the provider that is identified by the + * URI {@link URI#getScheme scheme} of the given URI. URI schemes are + * compared without regard to case. If the provider is found then its {@link + * FileSystemProvider#getPath getPath} method is invoked to convert the + * URI. + * + *

In the case of the default provider, identified by the URI scheme + * "file", the given URI has a non-empty path component, and undefined query + * and fragment components. Whether the authority component may be present + * is platform specific. The returned {@code Path} is associated with the + * {@link FileSystems#getDefault default} file system. + * + *

The default provider provides a similar round-trip guarantee + * to the {@link java.io.File} class. For a given {@code Path} p it + * is guaranteed that + *

{@code + * Path.get(}p{@code .}{@link Path#toUri() toUri}{@code ()).equals(} + * p{@code .}{@link Path#toAbsolutePath() toAbsolutePath}{@code ())} + *
+ * so long as the original {@code Path}, the {@code URI}, and the new {@code + * Path} are all created in (possibly different invocations of) the same + * Java virtual machine. Whether other providers make any guarantees is + * provider specific and therefore unspecified. + * + * @param uri + * the URI to convert + * + * @return the resulting {@code Path} + * + * @throws IllegalArgumentException + * if preconditions on the {@code uri} parameter do not hold. The + * format of the URI is provider specific. + * @throws FileSystemNotFoundException + * The file system, identified by the URI, does not exist and + * cannot be created automatically, or the provider identified by + * the URI's scheme component is not installed + * @throws SecurityException + * if a security manager is installed and it denies an unspecified + * permission to access the file system + */ + public static Path get(URI uri) { + String scheme = uri.getScheme(); + if (scheme == null) + throw new IllegalArgumentException("Missing scheme"); + + // check for default provider to avoid loading of installed providers + if (scheme.equalsIgnoreCase("file")) + return FileSystems.getDefault().provider().getPath(uri); + + // try to find provider + for (FileSystemProvider provider: FileSystemProvider.installedProviders()) { + if (provider.getScheme().equalsIgnoreCase(scheme)) { + return provider.getPath(uri); + } + } + + throw new FileSystemNotFoundException("Provider \"" + scheme + "\" not installed"); + } + + /** * Returns the file system that created this object. * * @return the file system that created this object @@ -527,7 +636,7 @@ * to the {@link java.io.File} class. For a given {@code Path} p it * is guaranteed that *
- * {@link Paths#get(URI) Paths.get}{@code (}p{@code .toUri()).equals(}p + * {@link Path#get(URI) Path.get}{@code (}p{@code .toUri()).equals(}p * {@code .}{@link #toAbsolutePath() toAbsolutePath}{@code ())} *
* so long as the original {@code Path}, the {@code URI}, and the new {@code --- old/src/java.base/share/classes/java/nio/file/Paths.java 2018-03-07 17:30:58.000000000 -0800 +++ new/src/java.base/share/classes/java/nio/file/Paths.java 2018-03-07 17:30:57.000000000 -0800 @@ -1,5 +1,5 @@ /* - * Copyright (c) 2007, 2011, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2007, 2018, 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 @@ -33,6 +33,7 @@ * by converting a path string or {@link URI}. * * @since 1.7 + * @see Path */ public final class Paths { @@ -68,6 +69,10 @@ * Path path = dir.resolve("file"); * * + * @implSpec + * This method simply invokes {@link Path#get(String,String...) + * Path.get(String, String...)} with the given parameters. + * * @param first * the path string or initial part of the path string * @param more @@ -79,9 +84,10 @@ * if the path string cannot be converted to a {@code Path} * * @see FileSystem#getPath + * @see Path#get(String,String...) */ public static Path get(String first, String... more) { - return FileSystems.getDefault().getPath(first, more); + return Path.get(first, more); } /** @@ -112,6 +118,10 @@ * Java virtual machine. Whether other providers make any guarantees is * provider specific and therefore unspecified. * + * @implSpec + *

This method simply invokes {@link Path#get(URI) + * Path.get(URI)} with the given parameter. + * * @param uri * the URI to convert * @@ -127,23 +137,10 @@ * @throws SecurityException * if a security manager is installed and it denies an unspecified * permission to access the file system + * + * @see Path#get(URI) */ public static Path get(URI uri) { - String scheme = uri.getScheme(); - if (scheme == null) - throw new IllegalArgumentException("Missing scheme"); - - // check for default provider to avoid loading of installed providers - if (scheme.equalsIgnoreCase("file")) - return FileSystems.getDefault().provider().getPath(uri); - - // try to find provider - for (FileSystemProvider provider: FileSystemProvider.installedProviders()) { - if (provider.getScheme().equalsIgnoreCase(scheme)) { - return provider.getPath(uri); - } - } - - throw new FileSystemNotFoundException("Provider \"" + scheme + "\" not installed"); + return Path.get(uri); } } --- old/src/java.base/share/classes/java/nio/file/TempFileHelper.java 2018-03-07 17:30:58.000000000 -0800 +++ new/src/java.base/share/classes/java/nio/file/TempFileHelper.java 2018-03-07 17:30:58.000000000 -0800 @@ -46,7 +46,7 @@ // temporary directory location private static final Path tmpdir = - Paths.get(GetPropertyAction.privilegedGetProperty("java.io.tmpdir")); + Path.get(GetPropertyAction.privilegedGetProperty("java.io.tmpdir")); private static final boolean isPosix = FileSystems.getDefault().supportedFileAttributeViews().contains("posix"); --- old/src/java.base/share/classes/java/util/Scanner.java 2018-03-07 17:30:59.000000000 -0800 +++ new/src/java.base/share/classes/java/util/Scanner.java 2018-03-07 17:30:59.000000000 -0800 @@ -2897,7 +2897,7 @@ * letters: * *

{@code
-     * try (Scanner sc = new Scanner(Paths.get("input.txt"))) {
+     * try (Scanner sc = new Scanner(Path.get("input.txt"))) {
      *     Pattern pat = Pattern.compile("[A-Z]{7,}");
      *     List capWords = sc.findAll(pat)
      *                               .map(MatchResult::group)
--- old/src/java.base/share/classes/jdk/internal/loader/BootLoader.java	2018-03-07 17:31:00.000000000 -0800
+++ new/src/java.base/share/classes/jdk/internal/loader/BootLoader.java	2018-03-07 17:30:59.000000000 -0800
@@ -32,7 +32,6 @@
 import java.net.URL;
 import java.nio.file.Files;
 import java.nio.file.Path;
-import java.nio.file.Paths;
 import java.security.AccessController;
 import java.security.PrivilegedAction;
 import java.util.Arrays;
@@ -243,8 +242,8 @@
                 mn = location.substring(5, location.length());
             } else if (location.startsWith("file:/")) {
                 // named module in exploded image
-                Path path = Paths.get(URI.create(location));
-                Path modulesDir = Paths.get(JAVA_HOME, "modules");
+                Path path = Path.get(URI.create(location));
+                Path modulesDir = Path.get(JAVA_HOME, "modules");
                 if (path.startsWith(modulesDir)) {
                     mn = path.getFileName().toString();
                 }
@@ -267,7 +266,7 @@
         private static URL toFileURL(String location) {
             return AccessController.doPrivileged(new PrivilegedAction<>() {
                 public URL run() {
-                    Path path = Paths.get(location);
+                    Path path = Path.get(location);
                     if (Files.isRegularFile(path)) {
                         try {
                             return path.toUri().toURL();
@@ -285,7 +284,7 @@
         private static Manifest getManifest(String location) {
             return AccessController.doPrivileged(new PrivilegedAction<>() {
                 public Manifest run() {
-                    Path jar = Paths.get(location);
+                    Path jar = Path.get(location);
                     try (InputStream in = Files.newInputStream(jar);
                          JarInputStream jis = new JarInputStream(in, false)) {
                         return jis.getManifest();
--- old/src/java.base/share/classes/jdk/internal/loader/ClassLoaders.java	2018-03-07 17:31:00.000000000 -0800
+++ new/src/java.base/share/classes/jdk/internal/loader/ClassLoaders.java	2018-03-07 17:31:00.000000000 -0800
@@ -28,7 +28,7 @@
 import java.io.IOException;
 import java.net.URL;
 import java.nio.file.InvalidPathException;
-import java.nio.file.Paths;
+import java.nio.file.Path;
 import java.security.CodeSource;
 import java.security.PermissionCollection;
 import java.util.jar.Manifest;
@@ -223,7 +223,7 @@
             // Use an intermediate File object to construct a URI/URL without
             // authority component as URLClassPath can't handle URLs with a UNC
             // server name in the authority component.
-            return Paths.get(s).toRealPath().toFile().toURI().toURL();
+            return Path.get(s).toRealPath().toFile().toURI().toURL();
         } catch (InvalidPathException | IOException ignore) {
             // malformed path string or class path element does not exist
             return null;
--- old/src/java.base/share/classes/jdk/internal/module/ModuleBootstrap.java	2018-03-07 17:31:01.000000000 -0800
+++ new/src/java.base/share/classes/jdk/internal/module/ModuleBootstrap.java	2018-03-07 17:31:01.000000000 -0800
@@ -34,7 +34,6 @@
 import java.lang.module.ResolvedModule;
 import java.net.URI;
 import java.nio.file.Path;
-import java.nio.file.Paths;
 import java.util.ArrayList;
 import java.util.Collections;
 import java.util.HashMap;
@@ -539,7 +538,7 @@
             Path[] paths = new Path[dirs.length];
             int i = 0;
             for (String dir: dirs) {
-                paths[i++] = Paths.get(dir);
+                paths[i++] = Path.get(dir);
             }
             return ModulePath.of(patcher, paths);
         }
--- old/src/java.base/share/classes/jdk/internal/module/ModuleHashesBuilder.java	2018-03-07 17:31:02.000000000 -0800
+++ new/src/java.base/share/classes/jdk/internal/module/ModuleHashesBuilder.java	2018-03-07 17:31:02.000000000 -0800
@@ -30,7 +30,6 @@
 import java.lang.module.ResolvedModule;
 import java.net.URI;
 import java.nio.file.Path;
-import java.nio.file.Paths;
 import java.util.ArrayDeque;
 import java.util.Collections;
 import java.util.Deque;
@@ -129,7 +128,7 @@
             () -> new InternalError("Selected module " + name + " not on module path"));
 
         URI uri = rm.reference().location().get();
-        Path path = Paths.get(uri);
+        Path path = Path.get(uri);
         String fn = path.getFileName().toString();
         if (!fn.endsWith(".jar") && !fn.endsWith(".jmod")) {
             throw new UnsupportedOperationException(path + " is not a modular JAR or jmod file");
--- old/src/java.base/share/classes/jdk/internal/module/ModulePath.java	2018-03-07 17:31:02.000000000 -0800
+++ new/src/java.base/share/classes/jdk/internal/module/ModulePath.java	2018-03-07 17:31:02.000000000 -0800
@@ -43,7 +43,6 @@
 import java.nio.file.Files;
 import java.nio.file.NoSuchFileException;
 import java.nio.file.Path;
-import java.nio.file.Paths;
 import java.nio.file.attribute.BasicFileAttributes;
 import java.util.ArrayList;
 import java.util.Collections;
@@ -360,7 +359,7 @@
         URI uri = mref.location().orElse(null);
         if (uri != null) {
             if (uri.getScheme().equalsIgnoreCase("file")) {
-                Path file = Paths.get(uri);
+                Path file = Path.get(uri);
                 return file.getFileName().toString();
             } else {
                 return uri.toString();
--- old/src/java.base/share/classes/jdk/internal/module/SystemModuleFinders.java	2018-03-07 17:31:03.000000000 -0800
+++ new/src/java.base/share/classes/jdk/internal/module/SystemModuleFinders.java	2018-03-07 17:31:03.000000000 -0800
@@ -38,7 +38,6 @@
 import java.nio.ByteBuffer;
 import java.nio.file.Files;
 import java.nio.file.Path;
-import java.nio.file.Paths;
 import java.security.AccessController;
 import java.security.PrivilegedAction;
 import java.util.ArrayDeque;
@@ -185,7 +184,7 @@
 
         // probe to see if this is an images build
         String home = System.getProperty("java.home");
-        Path modules = Paths.get(home, "lib", "modules");
+        Path modules = Path.get(home, "lib", "modules");
         if (Files.isRegularFile(modules)) {
             if (USE_FAST_PATH) {
                 SystemModules systemModules = allSystemModules();
@@ -205,7 +204,7 @@
         }
 
         // exploded build (do not cache module finder)
-        Path dir = Paths.get(home, "modules");
+        Path dir = Path.get(home, "modules");
         if (!Files.isDirectory(dir))
             throw new InternalError("Unable to detect the run-time image");
         ModuleFinder f = ModulePath.of(ModuleBootstrap.patcher(), dir);
--- old/src/java.base/share/classes/sun/security/provider/PolicyFile.java	2018-03-07 17:31:04.000000000 -0800
+++ new/src/java.base/share/classes/sun/security/provider/PolicyFile.java	2018-03-07 17:31:04.000000000 -0800
@@ -30,7 +30,7 @@
 import java.net.MalformedURLException;
 import java.net.URL;
 import java.net.URI;
-import java.nio.file.Paths;
+import java.nio.file.Path;
 import java.util.*;
 import java.security.*;
 import java.security.cert.Certificate;
@@ -305,7 +305,7 @@
             public URL run() {
                 String sep = File.separator;
                 try {
-                    return Paths.get(System.getProperty("java.home"),
+                    return Path.get(System.getProperty("java.home"),
                                      "lib", "security",
                                      "default.policy").toUri().toURL();
                 } catch (MalformedURLException mue) {
--- old/src/java.base/share/classes/sun/security/tools/keytool/Main.java	2018-03-07 17:31:05.000000000 -0800
+++ new/src/java.base/share/classes/sun/security/tools/keytool/Main.java	2018-03-07 17:31:04.000000000 -0800
@@ -27,7 +27,7 @@
 
 import java.io.*;
 import java.nio.file.Files;
-import java.nio.file.Paths;
+import java.nio.file.Path;
 import java.security.CodeSigner;
 import java.security.CryptoPrimitive;
 import java.security.KeyStore;
@@ -2189,7 +2189,7 @@
                 inplaceBackupName = srcksfname + ".old" + (n == 1 ? "" : n);
                 File bkFile = new File(inplaceBackupName);
                 if (!bkFile.exists()) {
-                    Files.copy(Paths.get(srcksfname), bkFile.toPath());
+                    Files.copy(Path.get(srcksfname), bkFile.toPath());
                     break;
                 }
             }
--- old/src/java.base/solaris/classes/sun/nio/fs/SolarisFileSystemProvider.java	2018-03-07 17:31:06.000000000 -0800
+++ new/src/java.base/solaris/classes/sun/nio/fs/SolarisFileSystemProvider.java	2018-03-07 17:31:05.000000000 -0800
@@ -84,9 +84,9 @@
 
     @Override
     FileTypeDetector getFileTypeDetector() {
-        Path userMimeTypes = Paths.get(
+        Path userMimeTypes = Path.get(
             GetPropertyAction.privilegedGetProperty("user.home"), ".mime.types");
-        Path etcMimeTypes = Paths.get("/etc/mime.types");
+        Path etcMimeTypes = Path.get("/etc/mime.types");
 
         return chain(new MimeTypesFileTypeDetector(userMimeTypes),
                      new MimeTypesFileTypeDetector(etcMimeTypes));
--- old/src/java.base/unix/classes/sun/nio/fs/UnixFileStore.java	2018-03-07 17:31:06.000000000 -0800
+++ new/src/java.base/unix/classes/sun/nio/fs/UnixFileStore.java	2018-03-07 17:31:06.000000000 -0800
@@ -260,7 +260,7 @@
     private static Properties loadProperties() {
         Properties result = new Properties();
         String fstypes = System.getProperty("java.home") + "/lib/fstypes.properties";
-        Path file = Paths.get(fstypes);
+        Path file = Path.get(fstypes);
         try {
             try (ReadableByteChannel rbc = Files.newByteChannel(file)) {
                 result.load(Channels.newReader(rbc, "UTF-8"));