United StatesChange Country, Oracle Worldwide Web Sites Communities I am a... I want to...
JDK-6562829 : (se) SelectableChannel.keyFor api uses == to compare the selector

Details
Type:
Bug
Submit Date:
2007-05-29
Status:
Closed
Updated Date:
2011-02-16
Project Name:
JDK
Resolved Date:
2007-09-17
Component:
core-libs
OS:
generic
Sub-Component:
java.nio
CPU:
generic
Priority:
P3
Resolution:
Won't Fix
Affected Versions:
7
Fixed Versions:

Related Reports

Sub Tasks

Description
channel.keyFor(Selector sel) has a code as follows

   private SelectionKey findKey(Selector sel) {
        synchronized (keyLock) {
            if (keys == null)
                return null;
            for (int i = 0; i < keys.length; i++)
                if ((keys[i] != null) && (keys[i].selector() == sel))
                    return keys[i];
            return null;
        }
    }

This uses == to compare the selector. However when glassfish passes a wrapper selector to the api, it will fail.

It causes the following glassfish issue
https://glassfish.dev.java.net/issues/show_bug.cgi?id=3027

                                    

Comments
EVALUATION

The issue here is that the delegating/wrapping Selector used in Glassfish is exposing, to the user, SelectionKeys that are associated with the default provider. As a result, the user has Selectors and SelectionKeys that are associated with different providers and this is why the keyFor method fails. The correct solution is to modify the delegating Selector so that it wraps the SelectionKeys.
                                     
2007-05-29



Hardware and Software, Engineered to Work Together