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

(se) Selector.keys() should be immutable

    XMLWordPrintable

    Details

    • Subcomponent:
    • Resolved In Build:
      b32
    • CPU:
      generic, sparc
    • OS:
      generic, solaris_2.6
    • Verification:
      Verified

      Description



      Name: auR10023 Date: 11/13/2002



      java.nio.channels.Selector.keys().add() doesn't throw
      UnsupportedOperationException.

      Javadoc for Selector.keys() method states:

      ...
      The key set is not directly modifiable. A key is removed only after it has been cancelled and its channel has been deregistered. Any attempt to modify the key set will cause an UnsupportedOperationException to be thrown.
      ...

      Here is the example:

      -------test.java---------

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

      public class test {
              
          public static void main(String args[]) {
              
              DatagramChannel channel = null;
              Selector sel = null;
              SelectionKey key = null;
              try {
                  channel = DatagramChannel.open();
                  channel.configureBlocking(false);
                  sel = Selector.open();

                  key = channel.register(
                  sel, SelectionKey.OP_WRITE);
              } catch (IOException e) {
                  System.out.println("Unexpected IOException");
                  return;
              }

              try {
                  sel.keys().add(key);
                  System.out.println("UnsupportedOperationException should be " +
                                     "thrown");
                  return;
              } catch (UnsupportedOperationException e) {
              }
              System.out.println("OKAY");
          }
      }

      Here is the result
      #java -version
      java version "1.4.2-beta"
      Java(TM) 2 Runtime Environment, Standard Edition (build 1.4.2-beta-b06)
      Java HotSpot(TM) Client VM (build 1.4.2-beta-b06, mixed mode)

      #java test
      UnsupportedOperationException should be thrown

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

        Attachments

          Issue Links

            Activity

              People

              Assignee:
              mr Mark Reinhold
              Reporter:
              avusunw Avu Avu (Inactive)
              Votes:
              0 Vote for this issue
              Watchers:
              0 Start watching this issue

                Dates

                Created:
                Updated:
                Resolved:
                Imported:
                Indexed: