Uploaded image for project: 'Undertow'
  1. Undertow
  2. UNDERTOW-2157

UndertowOutputStream.transferFrom appears to have a broken signature

    XMLWordPrintable

Details

    • Bug
    • Resolution: Unresolved
    • Major
    • 2.4.0.Final
    • 2.2.19.Final
    • Core
    • None

    Description

      UndertowOutputStream has a method:

       

      void transferFrom(FileChannel source) throws IOException

      There's not obviously a contract documented for this, but the implementation reads:

       

       

      long position = source.position();
      long size = source.size();
      Channels.transferBlocking(channel, source, position, size);
      updateWritten(size - position);

      I believe that this is incorrect because transferBlocking is specified to transfer size bytes, but here size is the length of the file, rather than the size - position expected. Effectively, this method will only do the right thing if source.position() == 0.

       

      I expect that the signature of the method should be:

       

      void transferFrom(FileChannel source, long position, long size); 

      and the current method should do one of:

       

      1. be made to throw if source.position() != 0.
      2. simply write from position 0 each time. Now the position() of the channel is ignored, but it was useless if nonzero anyway.
      3. call Channels.transferBlocking(channel, source, position, size - position)

      My preference would be for the second one since it'd be unexpected to have a signature that writes the 'rest' of the file, but a 'whole file' signature seems reasonable.

      I don't know what the right solution here is, fwiw, and I'm not 100% sure there's even a bug - I rarely interact with nio primitives directly (I'm an InputStream kind of guy!) - but it seemed dodgy enough to report!

      Attachments

        Activity

          People

            flaviarnn Flavia Rainone
            jbaker200 James Baker (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

              Created:
              Updated: