-
Bug
-
Resolution: Fixed
-
P4
-
7, 8, 11, 12
-
b05
-
x86_64
-
windows_10
ADDITIONAL SYSTEM INFORMATION :
OS: Windows 10 Home
Java: OpenJDK 11.0.1+13
File System: NTFS
A DESCRIPTION OF THE PROBLEM :
First, this issue is related/the-same-as two other issues:JDK-8029123 and JDK-8170334. Both were closed as "Not an issue". However, the behavior/contract of Files.isHidden appears inconsistent with other, core software on Windows such as File Explorer, CMD, and PowerShell.
In Windows one can mark a directory as hidden and it won't be displayed by File Explorer (unless configured to display hidden items). The directory won't even appear via CMD with "dir" or via PowerShell with "Get-ChildItem"; not unless explicitly requested by command-line options. Yet this same directory "isn't hidden" according to Files.isHidden.
There's a related question on Stack Overflow: https://stackoverflow.com/questions/53791740/why-does-files-ishiddenpath-return-false-for-directories-on-windows
An answer to that question points to documentation that indicates the hidden attribute relates to a file OR directory, not just a file. (Link to Windows documentation: https://docs.microsoft.com/en-us/windows/desktop/fileio/file-attribute-constants).
If Files.isHidden really is doing the correct thing, maybe it's possible to include documentation explaining why it doesn't behave the same as other Windows software?
STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
Single step: Call Files.isHidden with a Path that points to a hidden directory.
EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
Files.isHidden returns true.
ACTUAL -
Files.isHidden returns false.
---------- BEGIN SOURCE ----------
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.attribute.DosFileAttributes;
public class Main {
public static void main(String[] args) throws Exception {
final var directory = Path.of(args[0]).toAbsolutePath().normalize();
final var store = Files.getFileStore(directory);
final var dosAttrs = Files.readAttributes(directory, DosFileAttributes.class);
System.out.println("Directory : " + directory);
System.out.println("FileStore : " + store.name() + " [" + store.type() + "]");
System.out.println("Hidden (Files): " + Files.isHidden(directory));
System.out.println("Hidden (Dos) : " + dosAttrs.isHidden());
}
}
---------- END SOURCE ----------
CUSTOMER SUBMITTED WORKAROUND :
Query the attribute via java.nio.file.attribute.DosFileAttributes#isHidden directly, rather than use Files.isHidden or the equivalent FileSystemProvider.isHidden.
FREQUENCY : always
OS: Windows 10 Home
Java: OpenJDK 11.0.1+13
File System: NTFS
A DESCRIPTION OF THE PROBLEM :
First, this issue is related/the-same-as two other issues:
In Windows one can mark a directory as hidden and it won't be displayed by File Explorer (unless configured to display hidden items). The directory won't even appear via CMD with "dir" or via PowerShell with "Get-ChildItem"; not unless explicitly requested by command-line options. Yet this same directory "isn't hidden" according to Files.isHidden.
There's a related question on Stack Overflow: https://stackoverflow.com/questions/53791740/why-does-files-ishiddenpath-return-false-for-directories-on-windows
An answer to that question points to documentation that indicates the hidden attribute relates to a file OR directory, not just a file. (Link to Windows documentation: https://docs.microsoft.com/en-us/windows/desktop/fileio/file-attribute-constants).
If Files.isHidden really is doing the correct thing, maybe it's possible to include documentation explaining why it doesn't behave the same as other Windows software?
STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
Single step: Call Files.isHidden with a Path that points to a hidden directory.
EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
Files.isHidden returns true.
ACTUAL -
Files.isHidden returns false.
---------- BEGIN SOURCE ----------
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.attribute.DosFileAttributes;
public class Main {
public static void main(String[] args) throws Exception {
final var directory = Path.of(args[0]).toAbsolutePath().normalize();
final var store = Files.getFileStore(directory);
final var dosAttrs = Files.readAttributes(directory, DosFileAttributes.class);
System.out.println("Directory : " + directory);
System.out.println("FileStore : " + store.name() + " [" + store.type() + "]");
System.out.println("Hidden (Files): " + Files.isHidden(directory));
System.out.println("Hidden (Dos) : " + dosAttrs.isHidden());
}
}
---------- END SOURCE ----------
CUSTOMER SUBMITTED WORKAROUND :
Query the attribute via java.nio.file.attribute.DosFileAttributes#isHidden directly, rather than use Files.isHidden or the equivalent FileSystemProvider.isHidden.
FREQUENCY : always
- csr for
-
JDK-8217168 Files.isHidden should return true for hidden directories on Windows
- Closed
- relates to
-
JDK-8029123 Files.isHidden() Bug
- Closed
-
JDK-8170334 Files.isHidden() fails for folders on Windows
- Closed
- links to