Program: 172864
Project: 172864
Buggy source:
@Override public Object build(Object message,Object partialBuildObject){
  int noOfMessages=1;
  if (message instanceof List) {
    noOfMessages=((List)message).size();
  }
  OutMessage sendMessage=(OutMessage)partialBuildObject;
  ChannelMessage channelMessage=sendMessage.getMPIMessage();
  if (channelMessage.isComplete()) {
    sendMessage.setSendState(OutMessage.SendState.SERIALIZED);
    return sendMessage;
  }
  if (sendMessage.getSerializationState() == null) {
    sendMessage.setSerializationState(new SerializeState());
  }
  while (sendBuffers.size() > 0 && sendMessage.serializedState() != OutMessage.SendState.SERIALIZED) {
    DataBuffer buffer=sendBuffers.poll();
    if (sendMessage.serializedState() == OutMessage.SendState.INIT || sendMessage.serializedState() == OutMessage.SendState.SENT_INTERNALLY) {
      buildHeader(buffer,sendMessage);
      sendMessage.setSendState(OutMessage.SendState.HEADER_BUILT);
    }
    if (sendMessage.serializedState() == OutMessage.SendState.HEADER_BUILT || sendMessage.serializedState() == OutMessage.SendState.BODY_BUILT || sendMessage.serializedState() == OutMessage.SendState.PARTIALLY_SERIALIZED) {
      if ((sendMessage.getFlags() & MessageFlags.EMPTY) == MessageFlags.EMPTY) {
        sendMessage.setSendState(OutMessage.SendState.SERIALIZED);
        sendMessage.getSerializationState().setTotalBytes(0);
      }
 else {
        if (sendMessage.serializedState() == OutMessage.SendState.PARTIALLY_SERIALIZED && sendMessage.getSerializationState().getData() == null) {
          buildHeader(buffer,sendMessage);
        }
        serializeBody(message,sendMessage,buffer);
      }
    }
    channelMessage.addBuffer(buffer);
    if (sendMessage.serializedState() == OutMessage.SendState.SERIALIZED) {
      SerializeState state=sendMessage.getSerializationState();
      if (!channelMessage.isHeaderSent()) {
        int totalBytes=state.getTotalBytes();
        channelMessage.getBuffers().get(0).getByteBuffer().putInt(HEADER_SIZE - Integer.BYTES,totalBytes);
        MessageHeader.Builder builder=MessageHeader.newBuilder(sendMessage.getSource(),sendMessage.getEdge(),totalBytes);
        builder.destination(sendMessage.getDestintationIdentifier());
        sendMessage.getMPIMessage().setHeader(builder.build());
        channelMessage.setHeaderSent(true);
      }
      state.setTotalBytes(0);
      channelMessage.setComplete(true);
    }
 else     if (sendMessage.serializedState() == OutMessage.SendState.PARTIALLY_SERIALIZED) {
      SerializeState state=sendMessage.getSerializationState();
      if (!channelMessage.isHeaderSent()) {
        int totalBytes=state.getTotalBytes();
        int missing=state.getData().length - state.getBytesCopied();
        totalBytes=totalBytes + missing;
        channelMessage.getBuffers().get(0).getByteBuffer().putInt(HEADER_SIZE - Integer.BYTES,totalBytes);
        MessageHeader.Builder builder=MessageHeader.newBuilder(sendMessage.getSource(),sendMessage.getEdge(),totalBytes);
        builder.destination(sendMessage.getDestintationIdentifier());
        sendMessage.getMPIMessage().setHeader(builder.build());
        channelMessage.setHeaderSent(true);
      }
      state.setTotalBytes(0);
    }
  }
  return sendMessage;
}

Fixed version (ground truth):
@Override public Object build(Object message,Object partialBuildObject){
  int noOfMessages=1;
  if (message instanceof List) {
    noOfMessages=((List)message).size();
  }
  OutMessage sendMessage=(OutMessage)partialBuildObject;
  ChannelMessage channelMessage=sendMessage.getMPIMessage();
  if (channelMessage.isComplete()) {
    sendMessage.setSendState(OutMessage.SendState.SERIALIZED);
    return sendMessage;
  }
  if (sendMessage.getSerializationState() == null) {
    sendMessage.setSerializationState(new SerializeState());
  }
  while (sendBuffers.size() > 0 && sendMessage.serializedState() != OutMessage.SendState.SERIALIZED) {
    DataBuffer buffer=sendBuffers.poll();
    if (sendMessage.serializedState() == OutMessage.SendState.INIT || sendMessage.serializedState() == OutMessage.SendState.SENT_INTERNALLY) {
      buildHeader(buffer,sendMessage);
      sendMessage.setSendState(OutMessage.SendState.HEADER_BUILT);
    }
    if (sendMessage.serializedState() == OutMessage.SendState.HEADER_BUILT || sendMessage.serializedState() == OutMessage.SendState.BODY_BUILT || sendMessage.serializedState() == OutMessage.SendState.PARTIALLY_SERIALIZED) {
      if ((sendMessage.getFlags() & MessageFlags.EMPTY) == MessageFlags.EMPTY) {
        sendMessage.setSendState(OutMessage.SendState.SERIALIZED);
        sendMessage.getSerializationState().setTotalBytes(0);
      }
 else {
        if (sendMessage.serializedState() == OutMessage.SendState.PARTIALLY_SERIALIZED && sendMessage.getSerializationState().getData() == null) {
          buildHeader(buffer,sendMessage);
        }
        serializeBody(message,sendMessage,buffer);
      }
    }
    channelMessage.addBuffer(buffer);
    if (sendMessage.serializedState() == OutMessage.SendState.SERIALIZED) {
      SerializeState state=sendMessage.getSerializationState();
      int totalBytes=state.getTotalBytes();
      channelMessage.getBuffers().get(0).getByteBuffer().putInt(HEADER_SIZE - Integer.BYTES,totalBytes);
      MessageHeader.Builder builder=MessageHeader.newBuilder(sendMessage.getSource(),sendMessage.getEdge(),totalBytes);
      builder.destination(sendMessage.getDestintationIdentifier());
      sendMessage.getMPIMessage().setHeader(builder.build());
      state.setTotalBytes(0);
      channelMessage.setComplete(true);
    }
 else     if (sendMessage.serializedState() == OutMessage.SendState.PARTIALLY_SERIALIZED) {
      SerializeState state=sendMessage.getSerializationState();
      int totalBytes=state.getTotalBytes();
      channelMessage.getBuffers().get(0).getByteBuffer().putInt(HEADER_SIZE - Integer.BYTES,totalBytes);
      MessageHeader.Builder builder=MessageHeader.newBuilder(sendMessage.getSource(),sendMessage.getEdge(),totalBytes);
      builder.destination(sendMessage.getDestintationIdentifier());
      sendMessage.getMPIMessage().setHeader(builder.build());
      state.setTotalBytes(0);
    }
  }
  return sendMessage;
}