JDK-7119643 : Not possible to read files with a path longer than 2048 characters
  • Type: Enhancement
  • Component: core-libs
  • Sub-Component: java.io
  • Affected Version: 6u29,7u45
  • Priority: P4
  • Status: Resolved
  • Resolution: Fixed
  • OS: linux
  • CPU: x86
  • Submitted: 2011-12-09
  • Updated: 2015-06-15
  • Resolved: 2015-06-04
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
7u91 b01Fixed
Related Reports
Relates :  
Description
FULL PRODUCT VERSION :
Java(TM) SE Runtime Environment (build 1.6.0_29-b11)
Java HotSpot(TM) 64-Bit Server VM (build 20.4-b02, mixed mode)


ADDITIONAL OS VERSION INFORMATION :
Linux 2.6.18-128.el5 #1 SMP Wed Dec 17 11:41:38 EST 2008 x86_64 x86_64 x86_64 GNU/Linux


A DESCRIPTION OF THE PROBLEM :
In previous versions of Java it was possible to read files with a path full path length greater than 2048, 1.6 u 24 for example.
 However in update 1.6 update 29 if you attempt to read a file using a java.io.FileInputStream with a path greater than 2048 characters a java.io.FileNotFoundException is thrown.
  Interestingly a new File().exists() returns true, its just when you attempt to open the file does the error occur. I have also attempted to open the file using a java.io.RandomAccessFile and the FileNotFoundException is still thrown.


REGRESSION.  Last worked in version 6u29

STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
Create a file and directory structure with a length greater than 2048 characters. For example.
/pe_unix_1/itest_templates/DeepDirectoriesAndLongNames/IAmAVeryLongDirectoryNameHeldWithinAVeryDeepPathOfDirectoriesForTesting1/IAmAVeryLongDirectoryNameHeldWithinAVeryDeepPathOfDirectoriesForTesting1/IAmAVeryLongDirectoryNameHeldWithinAVeryDeepPathOfDirectoriesForTesting1/IAmAVeryLongDirectoryNameHeldWithinAVeryDeepPathOfDirectoriesForTesting1/IAmAVeryLongDirectoryNameHeldWithinAVeryDeepPathOfDirectoriesForTesting1/IAmAVeryLongDirectoryNameHeldWithinAVeryDeepPathOfDirectoriesForTesting1/IAmAVeryLongDirectoryNameHeldWithinAVeryDeepPathOfDirectoriesForTesting1/IAmAVeryLongDirectoryNameHeldWithinAVeryDeepPathOfDirectoriesForTesting1/IAmAVeryLongDirectoryNameHeldWithinAVeryDeepPathOfDirectoriesForTesting1/IAmAVeryLongDirectoryNameHeldWithinAVeryDeepPathOfDirectoriesForTesting1/IAmAVeryLongDirectoryNameHeldWithinAVeryDeepPathOfDirectoriesForTesting1/IAmAVeryLongDirectoryNameHeldWithinAVeryDeepPathOfDirectoriesForTesting1/IAmAVeryLongDirectoryNameHeldWithinAVeryDeepPathOfDirectoriesForTesting1/IAmAVeryLongDirectoryNameHeldWithinAVeryDeepPathOfDirectoriesForTesting1/1234567890/1234567890/123456789012345678901234567890123456789012345678901234567890/123456789012345678901234567890123456789012345678901234567890/123456789012345678901234567890123456789012345678901234567890/123456789012345678901234567890123456789012345678901234567890/123456789012345678901234567890123456789012345678901234567890/123456789012345678901234567890123456789012345678901234567890/123456789012345678901234567890123456789012345678901234567890/123456789012345678901234567890123456789012345678901234567890/123456789012345678901234567890123456789012345678901234567890/123456789012345678901234567890123456789012345678901234567890/123456789012345678901234567890123456789012345678901234567890/123456789012345678901234567890123456789012345678901234567890/123456789012345678901234567890123456789012345678901234567890/123456789012345678901234567890123456789012345678901234567890/123456789012345678901234567890123456789012345678901234567890/123456789012345678901234567890123456789012345678901234567890/123456789012345678901234567890123456789012345678901234567890/123456789012345678901234567890123456789012345678901234567890/123456789012345678901234567890123456789012345678901234567890/123456789012345678901234567890123456789012345678901234567890/123456789012345678901234567890123456789012345678901234567890/123456789012345678901234567890123456789012345678901234567890/123456789012345678901234567890123456789012345678901234567890/123456789012345678901234567890123456789012345678901234567890/test.file

Then attempt to open and read the file using a java.io.FileInputStream.




EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
I would expect that the file would be read successfully.
ACTUAL -
A  java.io.FileNotFoundException is thrown and the file is not read.

ERROR MESSAGES/STACK TRACES THAT OCCUR :
java.io.FileNotFoundException: /pe_unix_1/itest_templates/DeepDirectoriesAndLongNames/IAmAVeryLongDirectoryNameHeldWithinAVeryDeepPathOfDirectoriesForTesting1/IAmAVeryLongDirectoryNameHeldWithinAVeryDeepPathOfDirectoriesForTesting1/IAmAVeryLongDirectoryNameHeldWithinAVeryDeepPathOfDirectoriesForTesting1/IAmAVeryLongDirectoryNameHeldWithinAVeryDeepPathOfDirectoriesForTesting1/IAmAVeryLongDirectoryNameHeldWithinAVeryDeepPathOfDirectoriesForTesting1/IAmAVeryLongDirectoryNameHeldWithinAVeryDeepPathOfDirectoriesForTesting1/IAmAVeryLongDirectoryNameHeldWithinAVeryDeepPathOfDirectoriesForTesting1/IAmAVeryLongDirectoryNameHeldWithinAVeryDeepPathOfDirectoriesForTesting1/IAmAVeryLongDirectoryNameHeldWithinAVeryDeepPathOfDirectoriesForTesting1/IAmAVeryLongDirectoryNameHeldWithinAVeryDeepPathOfDirectoriesForTesting1/IAmAVeryLongDirectoryNameHeldWithinAVeryDeepPathOfDirectoriesForTesting1/IAmAVeryLongDirectoryNameHeldWithinAVeryDeepPathOfDirectoriesForTesting1/IAmAVeryLongDirectoryNameHeldWithinAVeryDeepPathOfDirectoriesForTesting1/IAmAVeryLongDirectoryNameHeldWithinAVeryDeepPathOfDirectoriesForTesting1/1234567890/1234567890/123456789012345678901234567890123456789012345678901234567890/123456789012345678901234567890123456789012345678901234567890/123456789012345678901234567890123456789012345678901234567890/123456789012345678901234567890123456789012345678901234567890/123456789012345678901234567890123456789012345678901234567890/123456789012345678901234567890123456789012345678901234567890/123456789012345678901234567890123456789012345678901234567890/123456789012345678901234567890123456789012345678901234567890/123456789012345678901234567890123456789012345678901234567890/123456789012345678901234567890123456789012345678901234567890/123456789012345678901234567890123456789012345678901234567890/123456789012345678901234567890123456789012345678901234567890/123456789012345678901234567890123456789012345678901234567890/123456789012345678901234567890123456789012345678901234567890/123456789012345678901234567890123456789012345678901234567890/123456789012345678901234567890123456789012345678901234567890/123456789012345678901234567890123456789012345678901234567890/123456789012345678901234567890123456789012345678901234567890/123456789012345678901234567890123456789012345678901234567890/123456789012345678901234567890123456789012345678901234567890/123456789012345678901234567890123456789012345678901234567890/123456789012345678901234567890123456789012345678901234567890/123456789012345678901234567890123456789012345678901234567890/123456789012345678901234567890123456789012345678901234567890/test.file (File name too long)
        at java.io.FileInputStream.open(Native Method)
        at java.io.FileInputStream.<init>(FileInputStream.java:120)
        at FilePathLengthTest.main(FilePathLengthTest.java:21)

REPRODUCIBILITY :
This bug can be reproduced always.

---------- BEGIN SOURCE ----------
import java.io.BufferedReader;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStreamReader;



/**
 * Simple class used to test the maximum allowed path length for a file.
 * It seems that between java 1.6 u 24 and java 1.6 u 29 the max path length was lowered to 2048 when opening a FileInputStream.
 *
 */
public class FilePathLengthTest {

	public static void main(String args[]) {
		String path = args[0];
		File file = new File(path);
		if(file.exists()) {
			try {
				BufferedReader fs =new BufferedReader( new InputStreamReader(new FileInputStream(file)));
				String line= "";
				while((line = fs.readLine())!=null) {
					System.out.println("reading line : "+line);
				}
				fs.close();
				
			} catch (FileNotFoundException e) {
				e.printStackTrace();
			} catch (IOException e) {
				e.printStackTrace();
			}
			if(file.isFile()) {
				
			}
		} else  {
			System.out.println(path + " does not exist");
		}
		
	}
	
}
---------- END SOURCE ----------

Comments
Agree that this is a P4 (ILW: HLL). Still, a regression and still present in later versions (need to be verified if that is still the case). Suggest we fix this in latest and backport to JDK6
18-11-2013

EVALUATION os_linux.cpp defines MAX_PATH as 2048 and uses that to limit the buffer used by a number of functions including os::open and os::stat, os::open was introduced by 6348631 and is called in place of hpi::open. hpi::open used the system open call and did not limit the buffer size explicitly.
12-12-2011