United StatesChange Country, Oracle Worldwide Web Sites Communities I am a... I want to...
Bug ID: JDK-6524172 (se) Selector.wakeup on Selector interrupted by close can throw NullPointerException
JDK-6524172 : (se) Selector.wakeup on Selector interrupted by close can throw NullPointerException

Details
Type:
Bug
Submit Date:
2007-02-12
Status:
Resolved
Updated Date:
2011-12-16
Project Name:
JDK
Resolved Date:
2007-03-10
Component:
core-libs
OS:
linux
Sub-Component:
java.nio
CPU:
x86
Priority:
P3
Resolution:
Fixed
Affected Versions:
6
Fixed Versions:

Related Reports
Backport:

Sub Tasks

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.
                                     
2007-02-13



Hardware and Software, Engineered to Work Together