JDK-6562829 : (se) SelectableChannel.keyFor api uses == to compare the selector
  • Type: Bug
  • Component: core-libs
  • Sub-Component: java.nio
  • Affected Version: 7
  • Priority: P3
  • Status: Closed
  • Resolution: Won't Fix
  • OS: generic
  • CPU: generic
  • Submitted: 2007-05-29
  • Updated: 2011-02-16
  • Resolved: 2007-09-17
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