[#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:
Norman Maurer 2014-05-04 21:09:58 +02:00
parent c93c6f01bd
commit d4f074186d
2 changed files with 25 additions and 1 deletions

View File

@ -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;

View File

@ -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) {