changeset 53388:8c08552a1fbd

8215467: Files.isHidden should return true for hidden directories on Windows Reviewed-by: alanb, bchristi, darcy
author bpb
date Fri, 18 Jan 2019 09:33:13 -0800
parents c9622e15ba29
children 529fc7620460
files src/java.base/share/classes/java/nio/file/Files.java src/java.base/windows/classes/sun/nio/fs/WindowsFileSystemProvider.java test/jdk/java/nio/file/Files/Misc.java
diffstat 3 files changed, 23 insertions(+), 13 deletions(-) [+]
line wrap: on
line diff
--- a/src/java.base/share/classes/java/nio/file/Files.java	Fri Jan 18 17:06:29 2019 +0000
+++ b/src/java.base/share/classes/java/nio/file/Files.java	Fri Jan 18 09:33:13 2019 -0800
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2007, 2018, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2007, 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
@@ -1608,12 +1608,13 @@
     }
 
     /**
-     * Tells whether or not a file is considered <em>hidden</em>. The exact
-     * definition of hidden is platform or provider dependent. On UNIX for
-     * example a file is considered to be hidden if its name begins with a
-     * period character ('.'). On Windows a file is considered hidden if it
-     * isn't a directory and the DOS {@link DosFileAttributes#isHidden hidden}
-     * attribute is set.
+     * Tells whether or not a file is considered <em>hidden</em>.
+     *
+     * @apiNote
+     * The exact definition of hidden is platform or provider dependent. On UNIX
+     * for example a file is considered to be hidden if its name begins with a
+     * period character ('.'). On Windows a file is considered hidden if the DOS
+     * {@link DosFileAttributes#isHidden hidden} attribute is set.
      *
      * <p> Depending on the implementation this method may require to access
      * the file system to determine if the file is considered hidden.
--- a/src/java.base/windows/classes/sun/nio/fs/WindowsFileSystemProvider.java	Fri Jan 18 17:06:29 2019 +0000
+++ b/src/java.base/windows/classes/sun/nio/fs/WindowsFileSystemProvider.java	Fri Jan 18 09:33:13 2019 -0800
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2008, 2018, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2008, 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
@@ -470,9 +470,6 @@
         } catch (WindowsException x) {
             x.rethrowAsIOException(file);
         }
-        // DOS hidden attribute not meaningful when set on directories
-        if (attrs.isDirectory())
-            return false;
         return attrs.isHidden();
     }
 
--- a/test/jdk/java/nio/file/Files/Misc.java	Fri Jan 18 17:06:29 2019 +0000
+++ b/test/jdk/java/nio/file/Files/Misc.java	Fri Jan 18 09:33:13 2019 -0800
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2008, 2013, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2008, 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
@@ -22,7 +22,7 @@
  */
 
 /* @test
- * @bug 4313887 6838333 8005566 8032220
+ * @bug 4313887 6838333 8005566 8032220 8215467
  * @summary Unit test for miscellenous methods in java.nio.file.Files
  * @library ..
  */
@@ -102,6 +102,18 @@
             } finally {
                 delete(file);
             }
+            Path dir = tmpdir.resolve("hidden");
+            createDirectory(dir);
+            try {
+                setAttribute(dir, "dos:hidden", true);
+                try {
+                    assertTrue(isHidden(dir));
+                } finally {
+                    setAttribute(dir, "dos:hidden", false);
+                }
+            } finally {
+                delete(dir);
+            }
         } else {
             assertTrue(isHidden(file));
         }