Java Solaris Communities Sun Store Join SDN My Profile Why Join?
 
Bug Database
Bug Detail
Quick Lists
Top 25 Bugs
Top 25 RFE's
Recently Closed Bugs
Printable Page Printable Page


Bug Database
Bug ID: 5025260
Votes 0
Synopsis (se) Register methods should throw ClosedChannelException instead of NPE
Category java:classes_nio
Reported Against 1.4.2
Release Fixed 7(b39)
State 10-Fix Delivered, bug
Priority: 4-Low
Related Bugs 6510916
Submit Date 01-APR-2004
Description


A DESCRIPTION OF THE REQUEST :
When you try to call register method of a selectable channel with a closed selector argument , it throws NPE. I think AbstractSelectableChannel.register should check for
this condition and throw another kind of exception since it is very difficult to figure out the problem looking at NPE.

Exception in thread "main" java.lang.NullPointerException
        at sun.nio.ch.DevPollSelectorImpl.putEventOps(DevPollSelectorImpl.java:170)
        at sun.nio.ch.ServerSocketChannelImpl.translateAndSetInterestOps(ServerSocketChannelImpl.java:239)
        at sun.nio.ch.SelectionKeyImpl.interestOps(SelectionKeyImpl.java:70)
        at sun.nio.ch.SelectorImpl.register(SelectorImpl.java:107)
        at java.nio.channels.spi.AbstractSelectableChannel.register(AbstractSelectableChannel.java:181)
        at java.nio.channels.SelectableChannel.register(SelectableChannel.java:254)
        at Test2.main(Test2.java:14)


JUSTIFICATION :
It is difficult to realize the problem when you only get a null pointer exception.


---------- BEGIN SOURCE ----------
import java.nio.*;
import java.nio.channels.*;
import java.net.*;

public class Test2
{
	public static void main(String[] args) throws Exception
	{
		Selector s = Selector.open();
		s.close();
		ServerSocketChannel c = ServerSocketChannel.open();
		c.socket().bind(new InetSocketAddress(40000));
		c.configureBlocking(false);
		c.register(s,SelectionKey.OP_ACCEPT);
	}
}
---------- END SOURCE ----------
(Incident Review ID: 243508) 
======================================================================
Posted Date : 2006-12-12 23:44:28.0
Work Around
N/A
Evaluation
The specifications of the register methods in the SelectableChannel and
AbstractSelectableChannel classes should be revised to say that a
ClosedSelectorException will be thrown if these methods are invoked upon or
with a closed selector, and the code should be revised accordingly.

This is a small change in behavior but the compatibility risk is acceptable
since it's highly unlikely that existing code depends upon the NPE that's
currently being thrown in this situation.

The NIO API should be scanned for other instances of this problem.

--   xxxxx@xxxxx   2004/5/17
Comments
  
  Include a link with my name & email   


PLEASE NOTE: JDK6 is formerly known as Project Mustang