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

(fc) FileChannel.transferFrom(channel, position, Long.MAX_VALUE) throws IAE

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Fixed
    • Icon: P4 P4
    • 6
    • 1.4.2
    • core-libs
    • b33
    • x86
    • linux, solaris_2.5.1, windows_2000



      Name: js151677 Date: 09/22/2004


      FULL PRODUCT VERSION :
      java version "1.4.2_03"
      Java(TM) 2 Runtime Environment, Standard Edition (build 1.4.2_03-b02)
      Java HotSpot(TM) Client VM (build 1.4.2_03-b02, mixed mode)


      ADDITIONAL OS VERSION INFORMATION :
      Linux hive 2.6.6 #8 Tue Aug 10 13:08:57 BST 2004 i686 athlon i386 GNU/Linux

      A DESCRIPTION OF THE PROBLEM :
      Reduce the length to Integer.MAX_VALUE and it works fine, increase it to Integer.MAX_VALUE + 1, and you get an IllegalArgumentException with a much shorter stack trace:

      Exception in thread "main" java.lang.IllegalArgumentException
              at sun.nio.ch.FileChannelImpl.transferFrom(FileChannelImpl.java:569)
              at test.main(test.java:19)

      This exception is NOT documented; the documentation gives no reason to suggest that any positive length would be illegal. I'd mention what the source says, except I can't find sun.nio.

      After discovering this bug, I found that due to other bug(s) recorded in the database, FileChannels transferFrom and transferTo on linux are useless for non blocking IO, so this is a moot point for me anyway.


      STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
      Step 1: Enter the attached test case into a file called test.java
      Step 2: Compile test.java with "javac test.java"
      Step 3: Run the test case with "java test"

      EXPECTED VERSUS ACTUAL BEHAVIOR :
      EXPECTED -
      [program waits indefinitely]
      ACTUAL -
      Exception in thread "main" java.lang.IllegalArgumentException
              at java.nio.Buffer.limit(Buffer.java:249)
              at sun.nio.ch.FileChannelImpl.transferFromArbitraryChannel(FileChannelImpl.java:535)
              at sun.nio.ch.FileChannelImpl.transferFrom(FileChannelImpl.java:576)
              at test.main(test.java:18)

      ERROR MESSAGES/STACK TRACES THAT OCCUR :
      Exception in thread "main" java.lang.IllegalArgumentException
              at java.nio.Buffer.limit(Buffer.java:249)
              at sun.nio.ch.FileChannelImpl.transferFromArbitraryChannel(FileChannelImpl.java:535)
              at sun.nio.ch.FileChannelImpl.transferFrom(FileChannelImpl.java:576)
              at test.main(test.java:18)


      REPRODUCIBILITY :
      This bug can be reproduced always.

      ---------- BEGIN SOURCE ----------
      import java.io.*;
      import java.net.*;
      import java.nio.channels.*;

      public class test {
              public static void main(String[] args) throws IOException
              {
                      // open a client socket channel
                      SocketChannel socket = SocketChannel.open();
                      socket.socket().connect(new InetSocketAddress("www.google.com", 80));

                      // open a file channel
                      FileOutputStream out = new FileOutputStream("out.tmp");
                      FileChannel file = out.getChannel();

                      // copy directly from socket channel into file channel
                      file.transferFrom(socket, 0, Long.MAX_VALUE);
              }
      }
      ---------- END SOURCE ----------

      CUSTOMER SUBMITTED WORKAROUND :
      Don't be stupid enough to try and transfer more than 2Gb of data at once :).
      (Incident Review ID: 311376)
      ======================================================================

            sjiang Shanliang Jiang (Inactive)
            jssunw Jitender S (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: