Commons IO
  1. Commons IO
  2. IO-201

CountingInputStream/CountingOutputStream only partially synchronized

    Details

    • Type: Bug Bug
    • Status: Closed
    • Priority: Major Major
    • Resolution: Fixed
    • Affects Version/s: 1.4
    • Fix Version/s: 2.0
    • Component/s: Filters
    • Labels:
      None

      Description

      CountingInputStream is only partially synchronized.

      The count is not synchronized when it is updated in read operations, so is not guaranteed to be published correctly

      The synchronization could be removed without loss of functionality.

      Not sure it makes sense to share a stream between threads anyway, as the underlying stream is unlikely to be thread-safe.

      If only one thread reads the stream, then the count field could be made volatile.
      This would allow other threads to read the count safely.

        Issue Links

          Activity

          Show
          Niall Pemberton added a comment - Fixed http://svn.apache.org/viewvc?view=revision&revision=1004079
          Hide
          Niall Pemberton added a comment -

          The resetCount method was added with the synchronized keyword:

          The getCount() methods were synchronzied later for the changes IO-84 - but theres no mention of why

          I agree the syncronization is incomplete and could probably be removed. Seems like a minor thing though so. I'm assigning this to 2.x.

          Show
          Niall Pemberton added a comment - The resetCount method was added with the synchronized keyword: https://svn.apache.org/viewvc?view=revision&revision=140583 The getCount() methods were synchronzied later for the changes IO-84 - but theres no mention of why https://svn.apache.org/viewvc?view=revision&revision=462818 I agree the syncronization is incomplete and could probably be removed. Seems like a minor thing though so. I'm assigning this to 2.x.
          Hide
          Sebb added a comment -

          Same applies to CountingOutputStream

          Show
          Sebb added a comment - Same applies to CountingOutputStream

            People

            • Assignee:
              Niall Pemberton
              Reporter:
              Sebb
            • Votes:
              0 Vote for this issue
              Watchers:
              0 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved:

                Development