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

(fs) File.length() does not match FileChannel.size()

    Details

    • Type: Bug
    • Status: Closed
    • Priority: P4
    • Resolution: Not an Issue
    • Affects Version/s: 1.4.0
    • Fix Version/s: None
    • Component/s: core-libs
    • Subcomponent:
    • CPU:
      x86
    • OS:
      windows_2000

      Description

      File is updated with two consecutive transferFrom() operations.
      First operation writes 'n' bytes and second operation writes 'm' bytes to underlying file.

      FileChannel.size() returns correct size of underlying file.
      However, File.length() returns 'n' (rather than actual file size).

      This fails on Windows 2000 professional.

      Works fine on Solaris, Windows NT, Linyx, Windows 98.

      --------- part of test code transferFrom.java: xferTest04() ----------
      // FileChannel fcS1, fcS2, fcD ;

      //get read file channel for the file
      fcS1 = Helper.openReadFileChannel(new File(src1FileName));

      //get read file channel for the file
      fcS2 = Helper.openReadFileChannel(new File(src2FileName));


      File file = new File (dstFileName) ;

      // get filechannel for the dst file.
      fcD = Helper.openRWFileChannel(dstFileName) ;

      bytesToWrite = srcData.length ;
      startPosition = 0 ;

      bytesWritten = fcD.transferFrom(fcS1, startPosition, bytesToWrite);

      // verify that first transfer operation is fine.
      System.out.println("bytesWritten=" + bytesWritten);
      System.out.println("fcD.size()=" + fcD.size());

      //fsize = (int) file.length() ;
      //System.out.println("file.length()=" + fsize);

      bytesToWrite = srcData.length / 2 ;
      startPosition = (srcData.length / 2) + (srcData.length / 4) ;

      bytesWritten = fcD.transferFrom(fcS2, startPosition, bytesToWrite);
                  // verify that first transfer operation is fine.
      System.out.println("bytesWritten=" + bytesWritten);
      System.out.println("fcD.size()=" + fcD.size());

      fsize = (int) file.length() ;
      System.out.println("file.length()=" + fsize);

      FileInputStream fis = new FileInputStream (file) ;
      favail = fis.available() ;
      System.out.println("fis.available()=" + favail);

      ------------ results on windows 2000 ------------
      bytesWritten=7868
      fcD.size()=7868
      file.length()=7868
      bytesWritten=3934
      fcD.size()=9835
      file.length()=7868 <<<< should be 9835
      fis.available()=9835

      ----------- result on other platforms -----------
      bytesWritten=7868
      fcD.size()=7868
      file.length()=7868
      bytesWritten=3934
      fcD.size()=9835
      file.length()=9835
      fis.available()=9835
      ----------------------------------

      Merlin Build B-65.

        Attachments

          Activity

            People

            • Assignee:
              mmcclosksunw Michael Mccloskey (Inactive)
              Reporter:
              hvilekar Harshad Vilekar
            • Votes:
              0 Vote for this issue
              Watchers:
              0 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved:
                Imported:
                Indexed: