Please find attached a small test program which
reproduces the following crash under Kaffe 1.1.2:
/usr/local/kaffe/bin/java -classpath build telnet.TelnetServer
waiting for connections on 1234
java.lang.NullPointerException
at gnu.java.nio.SelectorImpl.deregisterCancelledKeys (SelectorImpl.java:234)
at gnu.java.nio.SelectorImpl.select (SelectorImpl.java:146)
at gnu.java.nio.SelectorImpl.select (SelectorImpl.java:92)
at telnet.TelnetServer.serve (TelnetServer.java:93)
at telnet.TelnetServer.main (TelnetServer.java:22)
I have looked quickly on the problem, and it seems
SelectorImpl.deregisterCancelledKeys() calls cancelledKeys(),
which is inherited as "returning null" from AbstractSelector:
class SelectorImpl extends AbstractSelector:
private final void deregisterCancelledKeys()
{
Iterator it = cancelledKeys().iterator();
...
class AbstractSelector:
protected final Set cancelledKeys()
{
return null;
}
So is someone writing SelectorImpl.cancelledKeys()...? ;)
Regards,
Everton
package telnet;
import java.io.IOException;
import java.net.Socket;
import java.net.InetAddress;
import java.net.InetSocketAddress;
import java.net.SocketException;
import java.net.UnknownHostException;
import java.util.Set;
import java.util.Iterator;
import java.nio.channels.Selector;
import java.nio.channels.SocketChannel;
import java.nio.channels.ServerSocketChannel;
import java.nio.channels.SelectionKey;
import java.nio.channels.ClosedChannelException;
import java.nio.channels.spi.SelectorProvider;
public class TelnetServer {
public static void main(String args[]) {
serve();
}
private static void serve() {
Selector selector;
try {
selector = SelectorProvider.provider().openSelector();
}
catch (IOException e) {
System.err.println("could not create channel selector: " + e);
return;
}
ServerSocketChannel channel;
try {
channel = ServerSocketChannel.open();
}
catch (IOException e) {
System.err.println("could not create channel: " + e);
return;
}
try {
channel.configureBlocking(false);
}
catch (IOException e) {
System.err.println("could not set channel non-blocking mode: " + e);
return;
}
final String ANY_ADDR = "0.0.0.0";
InetAddress anyAddr;
try {
anyAddr = InetAddress.getByName(ANY_ADDR);
}
catch (UnknownHostException e) {
System.err.println("could not solve wildcard address: " + ANY_ADDR + ": " + e);
return;
}
final int listenPort = 1234;
InetSocketAddress sockAddr = new InetSocketAddress(anyAddr, listenPort);
if (sockAddr == null) {
System.err.println("could not create socket for wildcard address on port " + listenPort);
return;
}
try {
channel.socket().bind(sockAddr);
}
catch (IOException e) {
System.err.println("could not bind to local address: " + anyAddr.getHostAddress() + ":" + listenPort + ": " + e);
return;
}
SelectionKey acceptKey;
try {
acceptKey = channel.register(selector, SelectionKey.OP_ACCEPT);
}
catch (ClosedChannelException e) {
System.err.println("could not register accept interest: " + e);
return;
}
System.out.println("waiting for connections on " + listenPort);
for (;;) {
int addedKeys;
try {
addedKeys = selector.select();
}
catch (IOException e) {
System.err.println("channel selection failed: " + e);
continue;
}
if (addedKeys <= 0) {
System.err.println("no key selected");
break;
}
System.out.println("selected keys: " + addedKeys);
Set readyKeys = selector.selectedKeys();
for (Iterator i = readyKeys.iterator(); i.hasNext(); ) {
SelectionKey sk = (SelectionKey) i.next();
i.remove();
if (sk.isAcceptable()) {
ServerSocketChannel nextReady = (ServerSocketChannel) sk.channel();
SocketChannel ch;
try {
ch = nextReady.accept();
}
catch (IOException e) {
System.err.println("could not accept client: " + e);
continue;
}
try {
ch.configureBlocking(false);
}
catch (IOException io) {
System.err.println("could not set socket as non-blocking: " + io);
try { ch.close(); } catch (IOException e) {}
continue;
}
Socket s = ch.socket();
System.out.println("registering client socket for listening");
try {
acceptKey = ch.register(selector, SelectionKey.OP_READ);
}
catch (ClosedChannelException e) {
System.err.println("could not register socket for reading: " + e);
continue;
}
continue;
}
if (sk.isReadable()) {
SocketChannel nextReady = (SocketChannel) sk.channel();
Socket s = nextReady.socket();
System.out.println("disconnecting client socket");
try {
nextReady.close(); // calls sk.cancel(), de-registers key
}
catch (IOException e) {
System.err.println("failure closing socket: " + e);
}
continue;
}
System.err.println("select LOOP");
}
}
}
}
_______________________________________________
Classpath mailing list
[EMAIL PROTECTED]
http://mail.gnu.org/mailman/listinfo/classpath