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

(fs) FileChannel.read(ByteBuffer,long) accepts negative positions

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Fixed
    • Icon: P3 P3
    • 5.0
    • 1.4.0
    • core-libs
    • None
    • tiger
    • sparc
    • solaris_2.6



      Name: apR10229 Date: 05/12/2003



      The API method java.nio.channels.FileChannel.read(ByteBuffer,long)
      does not throw IllegalArgumentException "If the position is negative",
      as Java API documentation says.

      Run the following example to reproduce this bug:

      -------------------- test.java ----------------------
      import java.io.*;
      import java.nio.*;
      import java.nio.channels.*;
      public class test {
          public static void main(String[] args) {
              FileChannel fch = null;
              try {
                  FileOutputStream fos = new FileOutputStream("testFile.tmp");
                  fos.write(new byte[128]);
                  fos.close();
                  fch = (new FileInputStream("testFile.tmp")).getChannel();
              } catch (IOException e) {
                  e.printStackTrace();
              }
              try {
                  fch.read(ByteBuffer.allocate(256),-1L);
              } catch(IllegalArgumentException e) {
                  System.out.println("PASSED");
              } catch(IOException e) {
                  System.out.println("FAILED: Unexpected "+e);
                  System.exit(-1);
              }
              System.out.println("FAILED");
          }
      }
      ------------------- example output ------------------
      <pav@libra(pts/5).290> uname -a
      Linux libra 2.4.18 #10 Fri Jun 28 18:21:54 MSD 2002 i686 unknown
      <pav@libra(pts/5).291> java -version
      java version "1.5.0-beta"
      Java(TM) 2 Runtime Environment, Standard Edition (build 1.5.0-beta-b04)
      Java HotSpot(TM) Client VM (build 1.5.0-beta-b04, mixed mode)
      <pav@libra(pts/5).292> javac -d . test.java
      <pav@libra(pts/5).293> java -cp . test
      FAILED
      <pav@libra(pts/5).294>

      <pav@archer(pts/39).257> uname -a
      SunOS archer 5.8 Generic_108528-20 sun4u sparc SUNW,Ultra-4
      <pav@archer(pts/39).258> java -version
      java version "1.5.0-beta"
      Java(TM) 2 Runtime Environment, Standard Edition (build 1.5.0-beta-b04)
      Java HotSpot(TM) Client VM (build 1.5.0-beta-b04, mixed mode)
      <pav@archer(pts/39).259> javac -d . test.java
      <pav@archer(pts/39).260> java -cp . test
      FAILED
      <pav@archer(pts/39).261>

      -----------------------------------------------------

      ======================================================================

            mmcclosksunw Michael Mccloskey (Inactive)
            pavsunw Pav Pav (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: