Potential fix for NPE during SocketChannel.register(..)

This commit is contained in:
Trustin Lee 2008-11-06 10:55:56 +00:00
parent b15fe51e95
commit 486218ab28

View File

@ -89,11 +89,14 @@ class NioWorker implements Runnable {
boolean firstChannel = started.compareAndSet(false, true); boolean firstChannel = started.compareAndSet(false, true);
Selector selector; Selector selector;
if (firstChannel) { if (firstChannel) {
selectorGuard.writeLock().lock();
try { try {
this.selector = selector = Selector.open(); this.selector = selector = Selector.open();
} catch (IOException e) { } catch (IOException e) {
throw new ChannelException( throw new ChannelException(
"Failed to create a selector.", e); "Failed to create a selector.", e);
} finally {
selectorGuard.writeLock().unlock();
} }
} else { } else {
selector = this.selector; selector = this.selector;