JDK-6524172 : (se) Selector.wakeup on Selector interrupted by close can throw NullPointerException
  • Type: Bug
  • Component: core-libs
  • Sub-Component: java.nio
  • Affected Version: 6
  • Priority: P3
  • Status: Resolved
  • Resolution: Fixed
  • OS: linux
  • CPU: x86
  • Submitted: 2007-02-12
  • Updated: 2011-12-16
  • Resolved: 2007-03-10
The Version table provides details related to the release that this issue/RFE will be addressed.

Unresolved : Release in which this issue/RFE will be addressed.
Resolved: Release in which this issue/RFE has been resolved.
Fixed : Release in which this issue/RFE has been fixed. The release containing this fix may be available for download as an Early Access Release or a General Availability Release.

To download the current JDK release, click here.
JDK 6 JDK 7
6u18Fixed 7 b10Fixed
Description
Redhat FC6 Linux 2.6.19-1.2895.fc6 #1 SMP
Java HotSpot(TM) Client VM (build 1.6.0-b105, mixed mode, sharing) 

Person reporting the bug is a Sun employee, but without
bugster access (###@###.###)

The following code produces the following exception:

java.lang.NullPointerException
       at sun.nio.ch.EPollSelectorImpl.wakeup(EPollSelectorImpl.java:170)
       at net.jxta.impl.endpoint.tcp.TcpTransport.stopApp(TcpTransport.java:841)

According to the API, a call to Selector.wakeup() is not required after calling Selector.close(), and arguably the call is not required, however EPollSelectorImpl should not throw an NPE.

       Thread temp = messengerSelectorThread;
       if (null != temp) {
           temp.interrupt();
           try {
               messengerSelector.close();
           } catch (IOException failed) {
               if (LOG.isLoggable(Level.SEVERE)) {
                   LOG.log(Level.SEVERE, "IO error occured while closing server socket", failed);
               }
           }
       }

       // in case interrupt did not wakeup the Selector
Line:841>>>        messengerSelector.wakeup();

Comments
EVALUATION Yes, there's a bug here. It also duplicates on Solaris with the /dev/poll Selector and on Linux with the poll Selector. The close causes the Selector to wakeup and reset its interrupt status. The close then releases the Selector's resources including the poll object. A subsequent wakeup on the closed Selector throws NPE as the poll object is null.
13-02-2007