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

Data race in FilterOutputStream.close

    XMLWordPrintable

    Details

    • Subcomponent:
    • Resolved In Build:
      b18
    • Verification:
      Not verified

      Description

      There have been several attempts to fix FilterOutputStream.close, but a casual look reveals that close() has an obvious data race when close is called by separate threads.

          public void close() throws IOException {
              if (closed) {
                  return;
              }
              closed = true;

      This is a problem because FilterOutputStream makes no effort to be thread-safe but its subclasses like BufferedOutputStream do, without overriding close. Maybe it's just too hard to have a thread-unsafe superclass with thread-safe subclasses? One is tempted to rewrite classes like BufferedOutputStream without using any of the FilterOutputStream helper methods!

      This race is likely to be mostly benign in practice. I investigated this because we see TSAN warnings in jdk8. There's no closed field in jdk8, but the fundamental problem of implementing close so that it works with thread-safe and thread-unsafe subclasses remains.

        Attachments

          Issue Links

            Activity

              People

              Assignee:
              bpb Brian Burkhalter
              Reporter:
              martin Martin Buchholz
              Votes:
              0 Vote for this issue
              Watchers:
              9 Start watching this issue

                Dates

                Created:
                Updated:
                Resolved: