8221262: Cleanups in UnixFileSystem/WinNTFileSystem implementation classes
authorclanger
Tue, 26 Mar 2019 09:16:07 +0100
changeset 54273 f0490ada4712
parent 54272 85657f4753e4
child 54274 a7358438d463
8221262: Cleanups in UnixFileSystem/WinNTFileSystem implementation classes Reviewed-by: alanb, igerasim
src/java.base/unix/classes/java/io/UnixFileSystem.java
src/java.base/unix/native/libjava/UnixFileSystem_md.c
src/java.base/windows/classes/java/io/WinNTFileSystem.java
--- a/src/java.base/unix/classes/java/io/UnixFileSystem.java	Tue Mar 26 04:19:39 2019 +0000
+++ b/src/java.base/unix/classes/java/io/UnixFileSystem.java	Tue Mar 26 09:16:07 2019 +0100
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 1998, 2018, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 1998, 2019, 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
@@ -51,10 +51,12 @@
 
     /* -- Normalization and construction -- */
 
+    @Override
     public char getSeparator() {
         return slash;
     }
 
+    @Override
     public char getPathSeparator() {
         return colon;
     }
@@ -84,6 +86,7 @@
     /* Check that the given pathname is normal.  If not, invoke the real
        normalizer on the part of the pathname that requires normalization.
        This way we iterate through the whole pathname string only once. */
+    @Override
     public String normalize(String pathname) {
         int n = pathname.length();
         char prevChar = 0;
@@ -97,11 +100,13 @@
         return pathname;
     }
 
+    @Override
     public int prefixLength(String pathname) {
         if (pathname.isEmpty()) return 0;
         return (pathname.charAt(0) == '/') ? 1 : 0;
     }
 
+    @Override
     public String resolve(String parent, String child) {
         if (child.isEmpty()) return parent;
         if (child.charAt(0) == '/') {
@@ -112,10 +117,12 @@
         return parent + '/' + child;
     }
 
+    @Override
     public String getDefaultParent() {
         return "/";
     }
 
+    @Override
     public String fromURIPath(String path) {
         String p = path;
         if (p.endsWith("/") && (p.length() > 1)) {
@@ -128,10 +135,12 @@
 
     /* -- Path operations -- */
 
+    @Override
     public boolean isAbsolute(File f) {
         return (f.getPrefixLength() != 0);
     }
 
+    @Override
     public String resolve(File f) {
         if (isAbsolute(f)) return f.getPath();
         SecurityManager sm = System.getSecurityManager();
@@ -153,6 +162,7 @@
     // canonicalization algorithm
     private final ExpiringCache javaHomePrefixCache;
 
+    @Override
     public String canonicalize(String path) throws IOException {
         if (!useCanonCaches) {
             return canonicalize0(path);
@@ -246,6 +256,7 @@
 
     public native int getBooleanAttributes0(File f);
 
+    @Override
     public int getBooleanAttributes(File f) {
         int rv = getBooleanAttributes0(f);
         String name = f.getName();
@@ -253,15 +264,25 @@
         return rv | (hidden ? BA_HIDDEN : 0);
     }
 
+    @Override
     public native boolean checkAccess(File f, int access);
+
+    @Override
     public native long getLastModifiedTime(File f);
+
+    @Override
     public native long getLength(File f);
+
+    @Override
     public native boolean setPermission(File f, int access, boolean enable, boolean owneronly);
 
     /* -- File operations -- */
 
+    @Override
     public native boolean createFileExclusively(String path)
         throws IOException;
+
+    @Override
     public boolean delete(File f) {
         // Keep canonicalization caches in sync after file deletion
         // and renaming operations. Could be more clever than this
@@ -277,8 +298,14 @@
         return delete0(f);
     }
     private native boolean delete0(File f);
+
+    @Override
     public native String[] list(File f);
+
+    @Override
     public native boolean createDirectory(File f);
+
+    @Override
     public boolean rename(File f1, File f2) {
         // Keep canonicalization caches in sync after file deletion
         // and renaming operations. Could be more clever than this
@@ -294,12 +321,16 @@
         return rename0(f1, f2);
     }
     private native boolean rename0(File f1, File f2);
+
+    @Override
     public native boolean setLastModifiedTime(File f, long time);
+
+    @Override
     public native boolean setReadOnly(File f);
 
-
     /* -- Filesystem interface -- */
 
+    @Override
     public File[] listRoots() {
         try {
             SecurityManager security = System.getSecurityManager();
@@ -313,12 +344,15 @@
     }
 
     /* -- Disk usage -- */
+
+    @Override
     public native long getSpace(File f, int t);
 
     /* -- Basic infrastructure -- */
 
     private native long getNameMax0(String path);
 
+    @Override
     public int getNameMax(String path) {
         long nameMax = getNameMax0(path);
         if (nameMax > Integer.MAX_VALUE) {
@@ -327,10 +361,12 @@
         return (int)nameMax;
     }
 
+    @Override
     public int compare(File f1, File f2) {
         return f1.getPath().compareTo(f2.getPath());
     }
 
+    @Override
     public int hashCode(File f) {
         return f.getPath().hashCode() ^ 1234321;
     }
@@ -341,5 +377,4 @@
     static {
         initIDs();
     }
-
 }
--- a/src/java.base/unix/native/libjava/UnixFileSystem_md.c	Tue Mar 26 04:19:39 2019 +0000
+++ b/src/java.base/unix/native/libjava/UnixFileSystem_md.c	Tue Mar 26 09:16:07 2019 +0100
@@ -284,10 +284,10 @@
             fd = handleOpen(path, O_RDWR | O_CREAT | O_EXCL, 0666);
             if (fd < 0) {
                 if (errno != EEXIST)
-                    JNU_ThrowIOExceptionWithLastError(env, path);
+                    JNU_ThrowIOExceptionWithLastError(env, "Could not open file");
             } else {
                 if (close(fd) == -1)
-                    JNU_ThrowIOExceptionWithLastError(env, path);
+                    JNU_ThrowIOExceptionWithLastError(env, "Could not close file");
                 rv = JNI_TRUE;
             }
         }
--- a/src/java.base/windows/classes/java/io/WinNTFileSystem.java	Tue Mar 26 04:19:39 2019 +0000
+++ b/src/java.base/windows/classes/java/io/WinNTFileSystem.java	Tue Mar 26 09:16:07 2019 +0100
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2001, 2018, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2001, 2019, 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
@@ -328,7 +328,6 @@
                 return up + slashify(path.substring(2));
             char drive = path.charAt(0);
             String dir = getDriveDirectory(drive);
-            String np;
             if (dir != null) {
                 /* When resolving a directory-relative path that refers to a
                    drive other than the current drive, insist that the caller
@@ -641,6 +640,7 @@
     // expects the path to be null or a root component ending in a backslash
     private native int getNameMax0(String path);
 
+    @Override
     public int getNameMax(String path) {
         String s = null;
         if (path != null) {