Java Solaris Communities Sun Store Join SDN My Profile Why Join?
 
Bug Database
Bug Detail
Quick Lists
Top 25 Bugs
Top 25 RFE's
Recently Closed Bugs
Printable Page Printable Page


Bug Database
Bug ID: 4403166
Votes 14
Synopsis File does not support long paths on WIndows NT
Category java:classes_io
Reported Against 1.3 , 1.1.6 , mantis , kestrel , 1.4.0_01 , 1.4.1_02 , 1.4.2_01
Release Fixed mustang(b19)
State 10-Fix Delivered, bug
Priority: 3-Medium
Related Bugs 4165006 , 4306208 , 4699450 , 4700220 , 4751669 , 4759207 , 6481955 , 4741049 , 6193661 , 6194847 , 6222304
Submit Date 09-JAN-2001
Description



------------
java version "1.3.0"
Java(TM) 2 Runtime Environment, Standard Edition (build 1.3.0-C)
Java HotSpot(TM) Client VM (build 1.3.0-C, mixed mode)

Windows NT with an NTFS file system does not restrict the
total length of a path (unlike Windows 9x). You can create
a directory structure where the total path exceeds 255
characters. Unfortunately Java is unable to use any such file or
directory. The attached application illustrates this --- it attempts
to recurse through the structure. On encountering a file or directory
with path greater than 255 characters it will report that the  customer 
is neither a file nor a directory. Any attempt to open such a file will also
fail.

  To avoid this problem the native code should prepend \\?\ before any paths
which are longer than 255 characters when passing file names to the Windows
API. Actually you could always do this when the OS is NT.
7
  To create a deep directory structure try this:
mkdir deep
cd deep
mkdir a
mkdir a\averylongnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnn
mkdir b
move a b\evenlongernnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnn
ren b a
mkdir b
move a b\evenlongernnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnn
ren b a
mkdir b
move a b\evenlongernnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnn
ren b a

repeat the last three lines as required

-------------------------------------
import java.io.File;
import java.io.IOException;

class RecurseFile
{
	public static void main(String[] args)
	{
		for (int i=0; i<args.length; i++)
		{
			File f = new File(args[i]);
			System.out.println("Scanning tree: "+f);
			long size = sizeOf(f);
			System.out.println("size="+size);
		}
	}
	
	private static long sizeOf(File dir)
	{
		String[] names = dir.list();
		if (names == null)
			return 0;
		long size=0;
		for (int i=0; i<names.length; i++)
		{
			File f = new File(dir, names[i]);
			if (f.getPath().length() > 255)
			{
				System.out.println("Long path: "+f);
			}
			if (f.isDirectory())
			{
				size += sizeOf(f);
			}
			else if (f.isFile())
			{
				size += f.length();
			}
			else
				System.out.println("Neither file nor
directory: "+f);
		}
		return size;
	}
}
(Review ID: 114827)
  xxxxx@xxxxx   10/15/04 20:43 GMT
Work Around


Avoid deep directory structures.
======================================================================
Evaluation
We now use the CreateFile API to allow longer path lengths. Each component of the path is still limited to 260 characters. When the path is longer than 260 characters it must be fully qualified.
  xxxxx@xxxxx   2002-11-11

Adding long path support to the entire file API is too risky for Mantis. We can fix this in Tiger. It is not clear whether the support would be in java.io.File or the new filesystem API.
  xxxxx@xxxxx   2003-04-17
--
This issue was fixed in mustang at b19, and has been fixed for 5.0u6 as 6182812.
Posted Date : 2005-09-22 08:05:41.0

The solution we put into 6.0 and 5.0u6 has problem (regression) when dealing with
a "un-canonicalized" absolute path, as suggested in SDC comment. See #6481955 for
more details.
Posted Date : 2006-10-13 19:26:51.0
Comments
  
  Include a link with my name & email   

Submitted On 18-JAN-2001
mthornton
IMHO the best way to implement this fix is to test if a 
path is longer than 255 characters (if not leave as it is). 
Then check that the path is absolute, make it so if not and 
then prepend \\?\.


Submitted On 10-JAN-2005
KristenD
Can you clarify in which release it was fixed? 1.5? or a service release? It


Submitted On 07-OCT-2005
hi


Submitted On 07-OCT-2005
hi


Submitted On 27-JAN-2006
Hi,

Is this fixed in 1.5 by anychance.
Thanks.


Submitted On 06-MAR-2006
sergiohm
I just got the JDK 1.6 Beta and it has not been fixed. Neither it has been fixed under JDK 1.5.0_06-b-5 which I believe as of today (3/6/2006) is the most recent.
Why is the status closed if it has not been fixed ?


Submitted On 06-MAR-2006
sergiohm
My tests tell  me that each component of the path must be less than 256 characters and not 260.


Submitted On 18-SEP-2006
ravishakya
How to prepend \\?\ to the path if it's greater > 255 chars?


Submitted On 13-OCT-2006
Also, between 1.5.0_05 and 1.5.0_06 a length limit on 248 characters
was introduced on relative paths which can cause severe grievances
for people upgrading. Before the "fix" files of length 260 could be used.

import java.io.*;

public class TestPathLength {
	private static String longFilename = "C:\\tmp\\.\\";
	private static String padding = "1234567890123456789012345678901234567890012345678900123456789001234567890012345678900123456789001234567890012345678900123456789001234567890012345678900123456789001234567890012345678900123456789001234567890012345678900123456789001234567890012345678900123456789001234567890012345678900123456789001234567890012345678900123456789001234567890";
	
	public static void main(String[] args) {
		for (int i = 230; i < 260; i++) {
			String tmpName = longFilename + padding.substring(0, i) + ".txt";
			try {
				FileWriter fw = new FileWriter(tmpName);
				fw.close();
			} catch (Exception e) {
				System.out.println("Failed at length: " + tmpName.length());
				break;
			}
		}
	}
}



PLEASE NOTE: JDK6 is formerly known as Project Mustang