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

Channels.newChannel methods do not count bytes properly

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Fixed
    • Icon: P3 P3
    • 1.4.0
    • 1.4.0
    • core-libs
    • None
    • beta2
    • generic
    • generic

      Date: Wed, 18 Jul 2001 20:47:25 -0400 (EDT)
      From: ###@###.###>
      To: ###@###.###, ###@###.###
      Subject: Channels.newChannel bugs

      FYI, there seem to be a couple of bugs in the Channels.newChannel
      method implementations:

      In newChannel(InputStream),

                              int bytesToRead = Math.min(len, TRANSFER_SIZE);

      should be

                              int bytesToRead = Math.min((len - totalRead),
      TRANSFER_SIZE);

      and in newChannel(OutputStream),

                              int bytesToRead = Math.min(len, TRANSFER_SIZE);

      should be

                              int bytesToRead = Math.min((len - totalWritten),
      TRANSFER_SIZE);

      In both cases as is, the number of bytes already transferred in
      previous iterations of the while loop is not considered, so it is
      possible for the buffer put/get operations to cause a
      BufferOverflowException or BufferUnderflowException (respectively). I
      experienced the former in practive, and the above change fixed the
      problem.

            mmcclosksunw Michael Mccloskey (Inactive)
            mr Mark Reinhold
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: