Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-8343823

(fs) Files.createLink: inconsistent behavior when creating link to symbolic link

XMLWordPrintable

    • Icon: Enhancement Enhancement
    • Resolution: Unresolved
    • Icon: P4 P4
    • None
    • None
    • core-libs
    • In Review
    • generic
    • generic

      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.



            bpb Brian Burkhalter
            webbuggrp Webbug Group
            Votes:
            0 Vote for this issue
            Watchers:
            6 Start watching this issue

              Created:
              Updated: