United StatesChange Country, Oracle Worldwide Web Sites Communities I am a... I want to...
Bug ID: JDK-8011128 (fs) Files.createDirectory fails if the resoved path is exactly 248 characters long
JDK-8011128 : (fs) Files.createDirectory fails if the resoved path is exactly 248 characters long

Details
Type:
Bug
Submit Date:
2013-03-27
Status:
Closed
Updated Date:
2013-12-17
Project Name:
JDK
Resolved Date:
2013-05-11
Component:
core-libs
OS:
Sub-Component:
java.nio
CPU:
Priority:
P3
Resolution:
Fixed
Affected Versions:
7,7u17
Fixed Versions:

Related Reports
Backport:
Backport:
Backport:

Sub Tasks

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
                                    

Comments
URL:   http://hg.openjdk.java.net/jdk8/tl/jdk/rev/09a3b08c986f
User:  alanb
Date:  2013-05-10 13:56:35 +0000

                                     
2013-05-11
URL:   http://hg.openjdk.java.net/jdk8/jdk8/jdk/rev/09a3b08c986f
User:  lana
Date:  2013-05-21 18:20:30 +0000

                                     
2013-05-21
verified in b94
                                     
2013-06-17



Hardware and Software, Engineered to Work Together