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

(fs) Files.createDirectory fails if the resoved path is exactly 248 characters long

    XMLWordPrintable

Details

    • Bug
    • Resolution: Fixed
    • P3
    • 8
    • 7, 7u17
    • core-libs
    • None
    • b91
    • Verified

    Backports

      Description

        FULL PRODUCT VERSION :
        java version " 1.7.0_17 "
        Java(TM) SE Runtime Environment (build 1.7.0_17-b02)
        Java HotSpot(TM) 64-Bit Server VM (build 23.7-b01, mixed mode)

        ADDITIONAL OS VERSION INFORMATION :
        Microsoft Windows [Version 6.2.9200]

        A DESCRIPTION OF THE PROBLEM :
        The Files.createDirectory(Path) method which forms part of NIO2 fails if the path passed to it is exactly 248 characters long. Shorter paths and longer paths both work fine.

        STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
        Run the attached test case


        ERROR MESSAGES/STACK TRACES THAT OCCUR :
        java.nio.file.FileSystemException: [...]: The filename or extension is too long.


        REPRODUCIBILITY :
        This bug can be reproduced always.

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

        import org.junit.Before;
        import org.junit.Test;

        public class TestProblem {
            String path;

            @Before
            public void setupPath() throws Exception {
                StringBuilder builder = new StringBuilder(new File(System.getProperty( " java.io.tmpdir " )).getAbsolutePath());
                builder.append(File.separator);
                while (builder.length() < 248) {
                    builder.append('0');
                }

                path = builder.toString();
                File dir = new File(path);
                if (dir.exists()) { // could use Files.deleteIfExists but assuming it probably has a similar bug
                    Files.delete(path.toPath());
                }
            }

            @Test
            public void testSpecificDirectory() throws Exception {
                Path dir = new File(path).toPath();
                Files.createDirectories(dir); // <-- FAILS HERE
            }
        }

        ---------- END SOURCE ----------

        CUSTOMER SUBMITTED WORKAROUND :
        Avoiding using the API entirely seems to be the only safe workaround.

        SUPPORT :
        YES

        Attachments

          Issue Links

            Activity

              People

                alanb Alan Bateman
                webbuggrp Webbug Group
                Votes:
                0 Vote for this issue
                Watchers:
                3 Start watching this issue

                Dates

                  Created:
                  Updated:
                  Resolved: