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

RandomAccessFile.length() is not thread-safe

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Fixed
    • Icon: P4 P4
    • 9
    • 1.4.1, 5.0
    • core-libs
    • b101
    • x86, sparc
    • solaris_7, windows_xp

      Name: nt126004 Date: 02/24/2003


      FULL PRODUCT VERSION :
      java version "1.4.1_01"
      Java(TM) 2 Runtime Environment, Standard Edition (build 1.4.1_01-b01)
      Java HotSpot(TM) Client VM (build 1.4.1_01-b01, mixed mode)


      FULL OPERATING SYSTEM VERSION :
      SunOS pantar 5.7 Generic_106541-17 sun4u sparc SUNW,Ultra-4

      EXTRA RELEVANT SYSTEM CONFIGURATION :
      System has 4 CPUs.

      A DESCRIPTION OF THE PROBLEM :
      The length() method of java.io.RandomAccessFile temporarily
      changes the file pointer. If it is called in one thread,
      another thread that does a read() or write() can do so at
      the wrong offset. Conversely, a seek() in another thread
      can be lost due to a simultaneous call to length().

      This should either be clearly documented in the API
      specification (requiring users to synchronize calls to
      length() with those to other file methods) or fixed using
      some kind of internal lock.


      REPRODUCIBILITY :
      This bug can be reproduced occasionally.

      CUSTOMER WORKAROUND :
      synchronize all calls to relevant methods on some object,
      e.g. the RandomAccessFile instance itself.
      (Review ID: 181612)
      ======================================================================

            vtewari Vyom Tewari
            nthompsosunw Nathanael Thompson (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: