Fixed issue: NETTY-10 (DefaultChannelPipeline.removeFirst() and removeLast() throws NullPointerException)
* Made sure NoSuchElementException is thrown when the pipeline is empty * Made sure NullPointerException is not thrown when the pipeline contains only one handler
This commit is contained in:
parent
8e9b51a412
commit
866a74305c
@ -171,9 +171,17 @@ public class DefaultChannelPipeline implements ChannelPipeline {
|
||||
}
|
||||
|
||||
DefaultChannelHandlerContext oldHead = head;
|
||||
if (oldHead == null) {
|
||||
throw new NoSuchElementException();
|
||||
}
|
||||
if (oldHead.next == null) {
|
||||
head = tail = null;
|
||||
name2ctx.clear();
|
||||
} else {
|
||||
oldHead.next.prev = null;
|
||||
head = oldHead.next;
|
||||
name2ctx.remove(oldHead.getName());
|
||||
}
|
||||
return oldHead.getHandler();
|
||||
}
|
||||
|
||||
@ -183,9 +191,17 @@ public class DefaultChannelPipeline implements ChannelPipeline {
|
||||
}
|
||||
|
||||
DefaultChannelHandlerContext oldTail = tail;
|
||||
if (oldTail == null) {
|
||||
throw new NoSuchElementException();
|
||||
}
|
||||
if (oldTail.prev == null) {
|
||||
head = tail = null;
|
||||
name2ctx.clear();
|
||||
} else {
|
||||
oldTail.prev.next = null;
|
||||
tail = oldTail.prev;
|
||||
name2ctx.remove(oldTail.getName());
|
||||
}
|
||||
return oldTail.getHandler();
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user