United StatesChange Country, Oracle Worldwide Web Sites Communities I am a... I want to...
JDK-4778099 : (se) Selector.selectedKeys() should allow removal but not addition

Details
Type:
Bug
Submit Date:
2002-11-13
Status:
Closed
Updated Date:
2004-09-01
Project Name:
JDK
Resolved Date:
2003-12-19
Component:
core-libs
OS:
solaris_2.6,generic
Sub-Component:
java.nio
CPU:
sparc,generic
Priority:
P3
Resolution:
Fixed
Affected Versions:
1.4.2,5.0
Fixed Versions:
5.0 (b32)

Related Reports
Duplicate:
Relates:

Sub Tasks

Description

Name: auR10023			Date: 11/13/2002



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

Javadoc for Selector.selectedKeys() method states:

...
Keys may be removed from, but not directly added to, the selected-key set. Any attempt to add an object to 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.selectedKeys().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

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

                                    

Comments
EVALUATION

A selector's selected-key set should allow removal but not addition.
The add and addAll methods should throw UnsupportedOperationException.

-- ###@###.### 2002/11/15
                                     
181-10-11 0
CONVERTED DATA

BugTraq+ Release Management Values

COMMIT TO FIX:
tiger
tiger-beta

FIXED IN:
tiger-beta

INTEGRATED IN:
tiger-b32
tiger-beta

VERIFIED IN:
tiger-b63


                                     
2004-09-13



Hardware and Software, Engineered to Work Together