Program: 172929
Project: 172929
Buggy source:
private boolean serializeKeyedData(Object content,Object key,SerializeState state,MPIBuffer targetBuffer,MessageType contentType,MessageType keyType){
  ByteBuffer byteBuffer=targetBuffer.getByteBuffer();
  if (state.getPart() == SerializeState.Part.INIT) {
    int keyLength=KeySerializer.serializeKey(key,keyType,state,serializer);
    int dataLength=DataSerializer.serializeData(content,contentType,state,serializer);
    LOG.info(String.format("String_Node_Str",executor,dataLength,byteBuffer.position()));
    if (!buildSubMessageHeader(targetBuffer,dataLength + keyLength)) {
      LOG.warning("String_Node_Str");
      return false;
    }
    state.setTotalBytes(state.getTotalBytes() + NORMAL_SUB_MESSAGE_HEADER_SIZE);
    LOG.info(String.format("String_Node_Str",executor,byteBuffer.position()));
    LOG.info(String.format("String_Node_Str",executor,state.getTotalBytes()));
  }
  if (state.getPart() == SerializeState.Part.INIT || state.getPart() == SerializeState.Part.HEADER) {
    boolean complete=KeySerializer.copyKeyToBuffer(key,keyType,targetBuffer.getByteBuffer(),state,serializer);
    LOG.info(String.format("String_Node_Str",executor,byteBuffer.position()));
    LOG.info(String.format("String_Node_Str",executor,state.getTotalBytes()));
    if (complete) {
      state.setPart(SerializeState.Part.BODY);
    }
 else {
      state.setPart(SerializeState.Part.HEADER);
    }
  }
  if (state.getPart() != SerializeState.Part.BODY) {
    return false;
  }
  boolean completed=DataSerializer.copyDataToBuffer(content,contentType,byteBuffer,state,serializer);
  LOG.info(String.format("String_Node_Str",executor,byteBuffer.position()));
  targetBuffer.setSize(byteBuffer.position());
  if (completed) {
    LOG.info(String.format("String_Node_Str",executor,state.getTotalBytes()));
    state.setBytesCopied(0);
    state.setBufferNo(0);
    state.setData(null);
    state.setPart(SerializeState.Part.INIT);
    state.setKeySize(0);
    return true;
  }
 else {
    return false;
  }
}

Fixed version (ground truth):
private boolean serializeKeyedData(Object content,Object key,SerializeState state,MPIBuffer targetBuffer,MessageType contentType,MessageType keyType){
  ByteBuffer byteBuffer=targetBuffer.getByteBuffer();
  if (state.getPart() == SerializeState.Part.INIT) {
    int keyLength=KeySerializer.serializeKey(key,keyType,state,serializer);
    int dataLength=DataSerializer.serializeData(content,contentType,state,serializer);
    if (!buildSubMessageHeader(targetBuffer,dataLength + keyLength)) {
      LOG.warning("String_Node_Str");
      return false;
    }
    state.setTotalBytes(state.getTotalBytes() + NORMAL_SUB_MESSAGE_HEADER_SIZE);
  }
  if (state.getPart() == SerializeState.Part.INIT || state.getPart() == SerializeState.Part.HEADER) {
    boolean complete=KeySerializer.copyKeyToBuffer(key,keyType,targetBuffer.getByteBuffer(),state,serializer);
    if (complete) {
      state.setPart(SerializeState.Part.BODY);
    }
 else {
      state.setPart(SerializeState.Part.HEADER);
    }
  }
  if (state.getPart() != SerializeState.Part.BODY) {
    return false;
  }
  boolean completed=DataSerializer.copyDataToBuffer(content,contentType,byteBuffer,state,serializer);
  targetBuffer.setSize(byteBuffer.position());
  if (completed) {
    state.setBytesCopied(0);
    state.setBufferNo(0);
    state.setData(null);
    state.setPart(SerializeState.Part.INIT);
    state.setKeySize(0);
    return true;
  }
 else {
    return false;
  }
}