[#2454] Correctly return null when DefaultChannelPipeline.firstContext() is called on empty pipeline
Motivation: DefaultChannelPipeline.firstContext() should return null when the ipeline is empty. This is not the case atm. Modification: Fix incorrect check in DefaultChannelPipeline.firstContext() and add unit tests. Result: Correctly return null when DefaultChannelPipeline.firstContext() is called on empty pipeline.
This commit is contained in:
parent
c93c6f01bd
commit
d4f074186d
@ -568,7 +568,7 @@ final class DefaultChannelPipeline implements ChannelPipeline {
|
||||
@Override
|
||||
public ChannelHandlerContext firstContext() {
|
||||
DefaultChannelHandlerContext first = head.next;
|
||||
if (first == head) {
|
||||
if (first == tail) {
|
||||
return null;
|
||||
}
|
||||
return head.next;
|
||||
|
@ -511,6 +511,30 @@ public class DefaultChannelPipelineTest {
|
||||
assertEquals(0, buffer.refCnt());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testFirstContextEmptyPipeline() throws Exception {
|
||||
ChannelPipeline pipeline = new LocalChannel().pipeline();
|
||||
assertNull(pipeline.firstContext());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testLastContextEmptyPipeline() throws Exception {
|
||||
ChannelPipeline pipeline = new LocalChannel().pipeline();
|
||||
assertNull(pipeline.lastContext());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testFirstHandlerEmptyPipeline() throws Exception {
|
||||
ChannelPipeline pipeline = new LocalChannel().pipeline();
|
||||
assertNull(pipeline.first());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testLastHandlerEmptyPipeline() throws Exception {
|
||||
ChannelPipeline pipeline = new LocalChannel().pipeline();
|
||||
assertNull(pipeline.last());
|
||||
}
|
||||
|
||||
private static int next(DefaultChannelHandlerContext ctx) {
|
||||
DefaultChannelHandlerContext next = ctx.next;
|
||||
if (next == null) {
|
||||
|
Loading…
Reference in New Issue
Block a user