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

Clarify specification of java.io.RandomAccessFile.setLength

XMLWordPrintable

    • Icon: Enhancement Enhancement
    • Resolution: Fixed
    • Icon: P4 P4
    • 23
    • 22
    • core-libs
    • b09
    • generic
    • generic

      The method java.io.RandomAccessFile.setLength is incomplete about how it affects the file offset as returned by getFilePointer(). For example, there is no mention of the case where the desired length of the file is greater than the present length and the file offset is greater than both of those lengths, i.e.,

      length() < newLength < getFilePointer()

      What actually happens in this case is that the file is extended to size newLength and the file position is clamped to newLength. After the method returns, getFilePointer() will return newLength.

      Neither is there mention of what happens when the present and desired lengths are equal. In this case, the file itself and its length are unaffected, but if the file offset is greater than newLength, then it will be clamped to newLength, so that after the call getFilePointer() will return newLength.

            bpb Brian Burkhalter
            bpb Brian Burkhalter
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

              Created:
              Updated:
              Resolved: