Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Files.isHidden C:\\ changed between JDK12 and JDK13 on windows

Tags:

java

java-13

Files.isHidden(Path.of("c:\\")) returns true on Windows 10, JDK 13

but returns false on JDK 12 same machine.

Anyone know why this is?

like image 487
J Shattu Avatar asked Sep 30 '19 13:09

J Shattu


People also ask

Which JDK to download for Windows?

Java 18 is the latest JDK development kit for Windows, Linux, and macOS platforms. If you are a beginner and looking for regular updates for a prolonged period, we recommend going with Java SE 11.

How do I download JDK EXE?

Downloading the JDK InstallerAccess Java SE Downloads page and click Accept License Agreement. Under the Download menu, click the Download link that corresponds to the .exe for your version of Windows. Download the file jdk-12. interim.

How to install Oracle JDK 13 on Windows?

For Windows, choose to download Windows x64 Installer. Then you will download the jdk-13.0.2_windows-x64_bin.exe file (~160 MB), and verify SHA256 checksum for the downloaded file using this command: Run the Oracle JDK 13 installer program and you will see the following screen: The setup for Oracle JDK 13 is simple, quick and easy.

What is OpenJDK 13?

Download and Install OpenJDK 13 OpenJDK 13 is a reference implementation of Java SE 13 which was officially release on September, 17 th 2019. OpenJDK is free for personal, development and commercial use under GNU General Public License (GPLv2) without technical support.

What is the Java JDK?

The JDK is a development environment for building applications using the Java programming language. The JDK includes tools useful for developing and testing programs written in the Java programming language and running on the Java TM platform.

How to verify integrity of openjdk-13+33_windows-x64_bin file?

For Windows, you will download the file openjdk-13+33_windows-x64_bin.zip. (~186 MB). You should verify integrity of the downloaded file by comparing SHA256 checksum of the zip file with the one published on the website. On Windows, run this command:


Video Answer


2 Answers

It was a bug that was fixed with JDK 13.

On Microsoft Windows, the java.nio.file.Files.isHidden method has historically ignored the DOS "hidden" attribute on directories. This has been fixed in this release so that isHidden now returns true when invoked to test a directory that has this attribute set.

From the release notes

like image 101
Turamarth Avatar answered Oct 17 '22 00:10

Turamarth


As already mentioned, the difference in behavior is due to a bug being fixed: JDK-8215467. The description of the bug explains that, before the fix, the result of Files#isHidden(Path) was inconsistent with other core software on Windows (e.g. File Explorer, PowerShell, CMD, etc.). The inconsistency was that directories in Windows certainly can be hidden but Java (or at least NIO2) thought otherwise.

In the comments to the issue it was pointed out the result was also inconsistent with java.io.File#isHidden(). In fact, if you use:

File file = new File("C:\\");
System.out.println(file.isHidden());

You'll see true printed out, even in Java 12 and older (at least I do on my Windows 10 Home machine).

The fact C:\ is being reported as hidden appears to be correct for me. If I check the attributes of C:\ in PowerShell it shows the directory as hidden.

PS C:\> $root = Get-Item "C:\"
PS C:\> $root.Attributes
Hidden, System, Directory
like image 6
Slaw Avatar answered Oct 16 '22 23:10

Slaw