Program: 2918
Project: 2918
Buggy source:
@Override public void messageReceived(ChannelHandlerContext ctx,MessageEvent e) throws Exception {
  Object msg=e.getMessage();
  if (msg instanceof IcapMessage) {
    IcapMessage currentMessage=(IcapMessage)msg;
    message=currentMessage;
    if (message.getBody() == null || message.getBody().equals(IcapMessageElementEnum.NULLBODY)) {
      Channels.fireMessageReceived(ctx,message,e.getRemoteAddress());
      message=null;
      return;
    }
  }
 else   if (msg instanceof IcapChunkTrailer) {
    if (message == null) {
      ctx.sendUpstream(e);
    }
 else {
      IcapChunkTrailer trailer=(IcapChunkTrailer)msg;
      if (message.getBody().equals(IcapMessageElementEnum.REQBODY)) {
        for (        String name : trailer.getHeaderNames()) {
          message.getHttpRequest().addHeader(name,trailer.getHeader(name));
        }
      }
 else       if (message.getBody().equals(IcapMessageElementEnum.RESBODY)) {
        for (        String name : trailer.getHeaderNames()) {
          message.getHttpResponse().addHeader(name,trailer.getHeader(name));
        }
      }
      Channels.fireMessageReceived(ctx,message,e.getRemoteAddress());
    }
  }
 else   if (msg instanceof IcapChunk) {
    IcapChunk chunk=(IcapChunk)msg;
    if (message == null) {
      ctx.sendUpstream(e);
    }
 else     if (chunk.isLast()) {
      Channels.fireMessageReceived(ctx,message,e.getRemoteAddress());
      message=null;
    }
 else {
      ChannelBuffer chunkBuffer=chunk.getContent();
      if (message.getBody().equals(IcapMessageElementEnum.REQBODY)) {
        if (message.getHttpRequest() != null) {
          if (message.getHttpRequest().getContent().readableBytes() <= 0) {
            message.getHttpRequest().setContent(ChannelBuffers.dynamicBuffer());
          }
          message.getHttpRequest().getContent().writeBytes(chunkBuffer);
        }
 else {
        }
      }
 else       if (message.getBody().equals(IcapMessageElementEnum.RESBODY)) {
        if (message.getHttpResponse() != null) {
          if (message.getHttpResponse().getContent().readableBytes() <= 0) {
            message.getHttpResponse().setContent(ChannelBuffers.dynamicBuffer());
          }
          message.getHttpResponse().getContent().writeBytes(chunkBuffer);
        }
 else {
        }
      }
 else {
      }
    }
  }
 else {
    ctx.sendUpstream(e);
  }
}

Fixed version (ground truth):
@Override public void messageReceived(ChannelHandlerContext ctx,MessageEvent e) throws Exception {
  Object msg=e.getMessage();
  if (msg instanceof IcapMessage) {
    IcapMessage currentMessage=(IcapMessage)msg;
    message=currentMessage;
    if (message.getBody() == null || message.getBody().equals(IcapMessageElementEnum.NULLBODY)) {
      Channels.fireMessageReceived(ctx,message,e.getRemoteAddress());
      message=null;
      return;
    }
  }
 else   if (msg instanceof IcapChunkTrailer) {
    if (message == null) {
      ctx.sendUpstream(e);
    }
 else {
      IcapChunkTrailer trailer=(IcapChunkTrailer)msg;
      if (trailer.getHeaderNames().size() > 0) {
        for (        String name : trailer.getHeaderNames()) {
          if (message.getBody().equals(IcapMessageElementEnum.REQBODY)) {
            message.getHttpRequest().addHeader(name,trailer.getHeader(name));
          }
 else           if (message.getBody().equals(IcapMessageElementEnum.RESBODY)) {
            message.getHttpResponse().addHeader(name,trailer.getHeader(name));
          }
        }
      }
      Channels.fireMessageReceived(ctx,message,e.getRemoteAddress());
    }
  }
 else   if (msg instanceof IcapChunk) {
    IcapChunk chunk=(IcapChunk)msg;
    if (message == null) {
      ctx.sendUpstream(e);
    }
 else     if (chunk.isLast()) {
      Channels.fireMessageReceived(ctx,message,e.getRemoteAddress());
      message=null;
    }
 else {
      ChannelBuffer chunkBuffer=chunk.getContent();
      if (message.getBody().equals(IcapMessageElementEnum.REQBODY)) {
        if (message.getHttpRequest() != null) {
          if (message.getHttpRequest().getContent().readableBytes() <= 0) {
            message.getHttpRequest().setContent(ChannelBuffers.dynamicBuffer());
          }
          message.getHttpRequest().getContent().writeBytes(chunkBuffer);
        }
 else {
        }
      }
 else       if (message.getBody().equals(IcapMessageElementEnum.RESBODY)) {
        if (message.getHttpResponse() != null) {
          if (message.getHttpResponse().getContent().readableBytes() <= 0) {
            message.getHttpResponse().setContent(ChannelBuffers.dynamicBuffer());
          }
          message.getHttpResponse().getContent().writeBytes(chunkBuffer);
        }
 else {
        }
      }
 else {
      }
    }
  }
 else {
    ctx.sendUpstream(e);
  }
}