ADDITIONAL SYSTEM INFORMATION :
Linux: Ubuntu 24.04 LTS
macOS: macOS Monterey 12.7.6
openjdk version "23.0.1" 2024-10-15
OpenJDK Runtime Environment Corretto-23.0.1.8.1 (build 23.0.1+8-FR)
OpenJDK 64-Bit Server VM Corretto-23.0.1.8.1 (build 23.0.1+8-FR, mixed mode, sharing)
A DESCRIPTION OF THE PROBLEM :
The behavior of the Files.createLink method varies across operating systems when creating a link to a symbolic link.
For the following code:
```
var target = Files.createFile(Path.of("target"));
var symlink = Files.createSymbolicLink(Path.of("symlink"), target);
var hardlink = Files.createLink(Path.of("hardlink"), symlink);
System.out.println(Files.isSymbolicLink(hardlink));
```
On Linux, createLink() does not dereference the symbolic link, and the resulting hard link points to the symlink itself (output: true).
On macOS, createLink() follows the symbolic link, and the created hard link is a link to the target file (output: false).
It would be beneficial if the behavior were consistent across all platforms, or if the documentation explicitly stated that the behavior when creating a link to a symbolic link is platform-dependent.
Linux: Ubuntu 24.04 LTS
macOS: macOS Monterey 12.7.6
openjdk version "23.0.1" 2024-10-15
OpenJDK Runtime Environment Corretto-23.0.1.8.1 (build 23.0.1+8-FR)
OpenJDK 64-Bit Server VM Corretto-23.0.1.8.1 (build 23.0.1+8-FR, mixed mode, sharing)
A DESCRIPTION OF THE PROBLEM :
The behavior of the Files.createLink method varies across operating systems when creating a link to a symbolic link.
For the following code:
```
var target = Files.createFile(Path.of("target"));
var symlink = Files.createSymbolicLink(Path.of("symlink"), target);
var hardlink = Files.createLink(Path.of("hardlink"), symlink);
System.out.println(Files.isSymbolicLink(hardlink));
```
On Linux, createLink() does not dereference the symbolic link, and the resulting hard link points to the symlink itself (output: true).
On macOS, createLink() follows the symbolic link, and the created hard link is a link to the target file (output: false).
It would be beneficial if the behavior were consistent across all platforms, or if the documentation explicitly stated that the behavior when creating a link to a symbolic link is platform-dependent.
- csr for
-
JDK-8344633 (fs) Files.createLink: inconsistent behavior when creating link to symbolic link
- Closed
- links to
-
Review(master) openjdk/jdk/22257