8215467: Files.isHidden should return true for hidden directories on Windows
authorbpb
Fri, 18 Jan 2019 09:33:13 -0800
changeset 53388 8c08552a1fbd
parent 53387 c9622e15ba29
child 53389 529fc7620460
8215467: Files.isHidden should return true for hidden directories on Windows Reviewed-by: alanb, bchristi, darcy
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
--- 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));
         }