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;
|
DefaultChannelHandlerContext oldHead = head;
|
||||||
oldHead.next.prev = null;
|
if (oldHead == null) {
|
||||||
head = oldHead.next;
|
throw new NoSuchElementException();
|
||||||
name2ctx.remove(oldHead.getName());
|
}
|
||||||
|
if (oldHead.next == null) {
|
||||||
|
head = tail = null;
|
||||||
|
name2ctx.clear();
|
||||||
|
} else {
|
||||||
|
oldHead.next.prev = null;
|
||||||
|
head = oldHead.next;
|
||||||
|
name2ctx.remove(oldHead.getName());
|
||||||
|
}
|
||||||
return oldHead.getHandler();
|
return oldHead.getHandler();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -183,9 +191,17 @@ public class DefaultChannelPipeline implements ChannelPipeline {
|
|||||||
}
|
}
|
||||||
|
|
||||||
DefaultChannelHandlerContext oldTail = tail;
|
DefaultChannelHandlerContext oldTail = tail;
|
||||||
oldTail.prev.next = null;
|
if (oldTail == null) {
|
||||||
tail = oldTail.prev;
|
throw new NoSuchElementException();
|
||||||
name2ctx.remove(oldTail.getName());
|
}
|
||||||
|
if (oldTail.prev == null) {
|
||||||
|
head = tail = null;
|
||||||
|
name2ctx.clear();
|
||||||
|
} else {
|
||||||
|
oldTail.prev.next = null;
|
||||||
|
tail = oldTail.prev;
|
||||||
|
name2ctx.remove(oldTail.getName());
|
||||||
|
}
|
||||||
return oldTail.getHandler();
|
return oldTail.getHandler();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user