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

java.nio.file.Files.copy does not handle long file path

    Details

    • Subcomponent:
    • CPU:
      x86_64
    • OS:
      windows_10

      Description

      ADDITIONAL SYSTEM INFORMATION :
      OS: Microsoft Windows 10 Enterprise
      Java: 1.8.0_232

      A DESCRIPTION OF THE PROBLEM :
      Calling java.nio.file.Files.copy(Path, Path, CopyOption...) using long filenames (more than 256 characters?) results in JVM exits.
      The problem is related to windows device path, ones starting with "\\?\"

      STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
      Call java.nio.file.Files.copy(Path, Path, CopyOption...) with a long filename in "target" parameter

      EXPECTED VERSUS ACTUAL BEHAVIOR :
      EXPECTED -
      File copied to destination.
      In the attached example, it is expected to print: "prepare to copy" and "copy OK" but the latter is not.

      ACTUAL -
      JVM exits

      ---------- BEGIN SOURCE ----------
      public class CopyFiles
      {

          public static void main(String[] args) throws IOException
          {
              File source = new File(
                      "C:/Projects/dev/GIT/xdm-customer-project/web/dist/target/war/work/com.energeya.xdm2/xdm2.rap.war/WEB-INF/plugins/xdm2.commons.client.core/it/openmindonline/xdm/client/common/databinding/FromListToReferenceCodeUpdateStrategy$FromListToReferenceCodeConverter.class");
              File target = new File(
                      "C:/Projects/dev/GIT/xdm-customer-project/web/dist/target/template.web.client.dist-20.2.0-SNAPSHOT/WEB-INF/plugins/xdm2.commons.client.core/it/openmindonline/xdm/client/common/databinding/FromListToReferenceCodeUpdateStrategy$FromListToReferenceCodeConverter.class");

              if (!source.exists())
              {
                  throw new IllegalArgumentException("source does not exists");
              }

              System.out.println("prepare to copy");
              Files.copy(source.toPath(),
                         target.toPath(),
                         StandardCopyOption.REPLACE_EXISTING,
                         StandardCopyOption.COPY_ATTRIBUTES);

              System.out.println("copy OK");
          }

      }
      ---------- END SOURCE ----------

      FREQUENCY : always


        Attachments

        1. CopyFiles.java
          1 kB
        2. CopyFiles.java
          3 kB
        3. Eclipse.jpg
          Eclipse.jpg
          390 kB
        4. folders.jpg
          folders.jpg
          170 kB

          Activity

            People

            • Assignee:
              Unassigned
              Reporter:
              webbuggrp Webbug Group
            • Votes:
              0 Vote for this issue
              Watchers:
              7 Start watching this issue

              Dates

              • Created:
                Updated: