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

Files.createDirectories throws FileAlreadyExistsException for a symbolic link whose target is an existing directory

XMLWordPrintable

    • generic
    • generic

        A DESCRIPTION OF THE PROBLEM :
        It appears that the issue reported in JDK-8294193 is not fixed in JDK17. Can this be fixed in JDK17?

        STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
        1. Create a symlink. For example:
        ln -s <some-path> /opt/test

        2. Create a simple code as below and run it using the latest JDK17 and JDK20. JDK17 should give FileAlreadyExistsException.

        import java.io.File;
        import java.nio.file.Files;

        public class Main {

            public static void main(String[] args) {

                File test = new File("/opt/test");
                try {
                    Files.createDirectories(test.toPath());
                } catch(Exception e) {
                    System.out.println(e);
                }
            }
        }

        EXPECTED VERSUS ACTUAL BEHAVIOR :
        EXPECTED -
        There shouldn't be FileAlreadyExistsException.
        ACTUAL -
        JDK17 gives FileAlreadyExistsException.

        ---------- BEGIN SOURCE ----------
        import java.io.File;
        import java.nio.file.Files;

        public class Main {

            public static void main(String[] args) {

                File test = new File("/opt/test");
                try {
                    Files.createDirectories(test.toPath());
                } catch(Exception e) {
                    System.out.println(e);
                }
            }
        }
        ---------- END SOURCE ----------

        FREQUENCY : always


              wxiao Weibing Xiao
              webbuggrp Webbug Group
              Votes:
              0 Vote for this issue
              Watchers:
              5 Start watching this issue

                Created:
                Updated:
                Resolved: