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

FileInputStream.open(String) should use FILE_SHARE_DELETE share flag (win)

    Details

    • Type: Enhancement
    • Status: Open
    • Priority: P3
    • Resolution: Unresolved
    • Affects Version/s: 1.2.0, 1.2.2, 1.3.0, 1.3.1, 1.4.2, 7
    • Fix Version/s: None
    • Component/s: core-libs
    • Labels:
      None
    • Subcomponent:
    • Understanding:
      Cause Known
    • CPU:
      generic, x86
    • OS:
      generic, windows_98, windows_nt, windows_2000

      Description

      A customer has pointed out on the java.net forums that opening a file on Windows using a FileInputStream causes other processes to be unable to delete the file. This is intended behavior as the code is currently written, as the sharing flags specified during the opening of the file are FILE_SHARE_READ and FILE_SHARE_WRITE. See io_util_md.c, fileOpen. However, Windows 2000 supplies a new flag, FILE_SHARE_DELETE, which allows another process to delete the file while it is still open. The customer would like to have this functionality available because they are parsing logs generated by another process and when the second process attempts to rotate its logs it can not delete the old log because the JVM has it open. There are really no convenient workarounds for this problem as all approaches ultimately involve using a FileInputStream at least briefly to get the current data from the log and if the target process attempts to delete the file while it is open it will be unable to do so.

      The associated thread is
      http://forums.java.net/jive/thread.jspa?threadID=2150&tstart=0

        Issue Links

          Activity

          Hide
          alanb Alan Bateman added a comment -
          BT2:EVALUATION

          In the new file system API then (by default) the FILE_SHARE_DELETE sharing option is used so that the file can be deleted. We need to think through the compatability implications of adding this to FileInputStream/FileOutputStream/RandomAccessFile as there may be applications depending on current behavior.
          Show
          alanb Alan Bateman added a comment - BT2:EVALUATION In the new file system API then (by default) the FILE_SHARE_DELETE sharing option is used so that the file can be deleted. We need to think through the compatability implications of adding this to FileInputStream/FileOutputStream/RandomAccessFile as there may be applications depending on current behavior.
          Hide
          alanb Alan Bateman added a comment -
          BT2:WORK AROUND

          For jdk7, the workaround is to use new file system API. So instead of new FileInputStream(f) and new FileOutputStream(f), use f.toPath().newInputStream() and f.toPath().newOutputStream().
          Show
          alanb Alan Bateman added a comment - BT2:WORK AROUND For jdk7, the workaround is to use new file system API. So instead of new FileInputStream(f) and new FileOutputStream(f), use f.toPath().newInputStream() and f.toPath().newOutputStream().

            People

            • Assignee:
              alanb Alan Bateman
              Reporter:
              kbr Kenneth Russell (Inactive)
            • Votes:
              0 Vote for this issue
              Watchers:
              2 Start watching this issue

              Dates

              • Created:
                Updated:
                Imported:
                Indexed: