Index: src/test/java/tests/api/java/io/FileTest.java =================================================================== --- src/test/java/tests/api/java/io/FileTest.java (revision 472394) +++ src/test/java/tests/api/java/io/FileTest.java (working copy) @@ -1769,9 +1769,10 @@ } /** + * @throws IOException * @tests java.io.File#mkdir() */ - public void test_mkdir() { + public void test_mkdir() throws IOException { // Test for method boolean java.io.File.mkdir() String base = System.getProperty("user.dir"); @@ -1789,16 +1790,31 @@ dirExists = false; } } - try { - assertTrue("mkdir failed", dir.mkdir() && dir.exists()); - } finally { - dir.delete(); - } + + assertTrue("mkdir failed", dir.mkdir() && dir.exists()); + dir.deleteOnExit(); + + // Test make a long path + String longDirName = "abcdefghijklmnopqrstuvwx";// 24 chars + StringBuilder sb = new StringBuilder(dir + File.separator); + while (dir.getCanonicalPath().length() < 256 - longDirName.length()) { + sb.append(longDirName + File.separator); + dir = new File(sb.toString()); + assertTrue("mkdir failed", dir.mkdir() && dir.exists()); + dir.deleteOnExit(); + } + while (dir.getCanonicalPath().length() < 256) { + sb.append(0); + dir = new File(sb.toString()); + assertTrue("mkdir " + dir.getCanonicalPath().length() + " failed", + dir.mkdir() && dir.exists()); + dir.deleteOnExit(); + } } /** - * @tests java.io.File#mkdirs() - */ + * @tests java.io.File#mkdirs() + */ public void test_mkdirs() { // Test for method boolean java.io.File.mkdirs() Index: src/main/java/java/io/File.java =================================================================== --- src/main/java/java/io/File.java (revision 473328) +++ src/main/java/java/io/File.java (working copy) @@ -50,7 +50,7 @@ private String path; - byte[] properPath; + private byte[] properPath; /** * System dependent file separator character. @@ -74,6 +74,8 @@ */ public static final String pathSeparator; + private static final int MAX_PATH_LENGTH = 248; + /* Temp file counter needs java.util.Random from mJava */ private static int counter; @@ -1038,20 +1040,35 @@ if (security != null) { security.checkWrite(path); } - return mkdirImpl(properPath(true)); - } + byte[] properPath = properPath(true); + if (properPath.length < MAX_PATH_LENGTH) { + return mkdirImpl(properPath); + } else { + return mkLongPath(); + } + } + private boolean mkLongPath() { + String longStr = null; + try { + longStr = getCanonicalPath(); + } catch (IOException e) { + //should not happen. + } + return mkdirImpl(Util.getBytes(longStr)); + } + private native boolean mkdirImpl(byte[] filePath); /** - * Create all the directories needed for this File. If the terminal - * directory already exists, answer false. If the directories were created - * successfully, answer true. - * - * @return true if the necessary directories were created, - * false otherwise. - * - */ + * Create all the directories needed for this File. If the terminal + * directory already exists, answer false. If the directories were created + * successfully, answer true. + * + * @return true if the necessary directories were created, + * false otherwise. + * + */ public boolean mkdirs() { /* If the terminal directory already exists, answer false */ if (exists()) {