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

(fs) FileChannel.transferTo throws wrong exception when target is read-only

XMLWordPrintable

    • mantis
    • sparc
    • solaris_2.6
    • Verified



      Name: auR10023 Date: 08/16/2002



      java.nio.FileChannel.transferTo(long, long, WritableByteChannel) throws
      unexpected IOException instead of NonWritableChannelException

      Here is the example:

      -------test.java---------
      import java.io.*;
      import java.nio.channels.*;


      public class test {

          public static void main(String args[]) {
                  FileChannel channel = null;
                  try {
                       channel = (new FileInputStream(
                          new File("test.java").getPath())).getChannel();
                  } catch (IOException e) {
                      System.out.println("Cannot create channel");
                      return;
                  }

                  try {
                      channel.transferTo((long)0, (long)2,
                                         channel);
                      System.out.println( "NonWritableChannelException expected");
                      return;
                  } catch(NonWritableChannelException e) {
                  } catch(IllegalStateException e) {
                      return;
                  } catch(IllegalArgumentException e) {
                      return;
                  } catch(IOException e) {
                      System.out.println("Unexpected IOException");
                      return;
                  }
                  System.out.println( "OK");
              return;
          }
      }

      Here is the result of execution on Solaris 2.8 and Linux RH 7.3

      Solaris:

      #java -version

      java version "1.4.0"
      Java(TM) 2 Runtime Environment, Standard Edition (build 1.4.0-b92)
      Java HotSpot(TM) Client VM (build 1.4.0-b92, mixed mode)

      #java test

      OK

      Linux:

      #java -version

      java version "1.4.0"
      Java(TM) 2 Runtime Environment, Standard Edition (build 1.4.0-b92)
      Java HotSpot(TM) Client VM (build 1.4.0-b92, mixed mode)

      #java test

      Unexpected IOException

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

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

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: