(se) SelectableChannel.register() should throw IAE for ops other than READ/WRITE/CONNECT/ACCEPT

XMLWordPrintable

    • Type: Bug
    • Resolution: Not an Issue
    • Priority: P3
    • None
    • Affects Version/s: 6
    • Component/s: core-libs
    • generic
    • generic

      SelectableChannel.register() allows to register with Selector for Operations which do not have any meaning.
      For Example ServerSocketChannel can be registered with Selector for the operation 0,
      allowing selector.select() to wait forever.
      Similarly , SocketChannel can be registered for the operation 0,5,9,12,13 with selector,
      DatagramChannel for 0, 5, and Pipe.SinkChannel/SourceChannel can be register with selector
      for operation 0.

      Clearly registering Channels for operations other than SelectionKey.OP_READ/OP_WRITE/OP_CONNECT/OP_ACCEPT
      is not useful. it is should throw IllegalArgumentException.

      Please see the following code and Result,
      OS : Windows2000Prof.
      <jdk-version>
      client24 /home/rg157576 $ java -version
      java version "1.6.0-rc"
      Java(TM) SE Runtime Environment (build 1.6.0-rc-b89)
      Java HotSpot(TM) Client VM (build 1.6.0-rc-b89, mixed mode)
      </jdk-version>

      <code>
      import java.nio.*;
      import java.nio.channels.*;

      public class UnknownOps {
        public static void main(String... args ) throws Exception {
      SelectableChannel ch[] = {SocketChannel.open(),ServerSocketChannel.open(),DatagramChannel.open()};
      Selector selector = Selector.open();
      for (SelectableChannel channel : ch) {
      channel.configureBlocking(false);
      for (int j=0;j<15;j++) {
      try {
      channel.register(selector,j);
      if (!(j== 1 || j==4 || j==8 || j==16)) {
      System.out.println("Channel "+channel.getClass().getName()+" Register for Unvalid Ops "+j);
      }
      }catch(Exception e) {
      //System.out.println("j"+j);
      //e.printStackTrace();
      }
      }
      }
        }
      }
      </code>
      <Result>

      Channel sun.nio.ch.SocketChannelImpl Register for Unvalid Ops 0
      Channel sun.nio.ch.SocketChannelImpl Register for Unvalid Ops 5
      Channel sun.nio.ch.SocketChannelImpl Register for Unvalid Ops 9
      Channel sun.nio.ch.SocketChannelImpl Register for Unvalid Ops 12
      Channel sun.nio.ch.SocketChannelImpl Register for Unvalid Ops 13
      Channel sun.nio.ch.ServerSocketChannelImpl Register for Unvalid Ops 0
      Channel sun.nio.ch.DatagramChannelImpl Register for Unvalid Ops 0
      Channel sun.nio.ch.DatagramChannelImpl Register for Unvalid Ops 5

      </Result>

            Assignee:
            Xueming Shen
            Reporter:
            Rajendra Gutupalli (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: