JDK-8011128 : (fs) Files.createDirectory fails if the resoved path is exactly 248 characters long
  • Type: Bug
  • Component: core-libs
  • Sub-Component: java.nio
  • Affected Version: 7,7u17
  • Priority: P3
  • Status: Closed
  • Resolution: Fixed
  • Submitted: 2013-03-27
  • Updated: 2013-12-17
  • Resolved: 2013-05-11
The Version table provides details related to the release that this issue/RFE will be addressed.

Unresolved : Release in which this issue/RFE will be addressed.
Resolved: Release in which this issue/RFE has been resolved.
Fixed : Release in which this issue/RFE has been fixed. The release containing this fix may be available for download as an Early Access Release or a General Availability Release.

To download the current JDK release, click here.
JDK 7 JDK 8
7u40Fixed 8 b91Fixed
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
verified in b94
17-06-2013