Details
Description
We're getting this intermittent NullPointerExceptions in our unit tests when doing the org.mortbay.jetty.Server.stop():
[junit] java.lang.NullPointerException [junit] at org.mortbay.io.nio.SelectorManager.doStop(SelectorManager.java:211) [junit] at org.mortbay.component.AbstractLifeCycle.stop(AbstractLifeCycle.java:65) [junit] at org.mortbay.jetty.nio.SelectChannelConnector.doStop(SelectChannelConnector.java:320) [junit] at org.mortbay.component.AbstractLifeCycle.stop(AbstractLifeCycle.java:65) [junit] at org.mortbay.jetty.Server.doStop(Server.java:267) [junit] at org.mortbay.component.AbstractLifeCycle.stop(AbstractLifeCycle.java:65)
Could it be a chance of having a race in the doStop() when one thread has nullified the _selectSet and the other is accessing it?
protected void doStop() throws Exception
{
for (int i=0;i<_selectSet.length;i++)
_selectSet[i].stop(); // <------ line #211 of SelectorManager.java
super.doStop();
_selectSet=null;
}
We had done some work after 6.1.3 to avoid dual calls to stop, but as there is no harm in some defensive programming, I have also restructured stop to avoid the NPE.