Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-7119643

Not possible to read files with a path longer than 2048 characters

XMLWordPrintable

    • b01
    • x86
    • linux

      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 ----------

            coffeys Sean Coffey
            webbuggrp Webbug Group
            Votes:
            0 Vote for this issue
            Watchers:
            7 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: