Program: 173264
Project: 173264
Buggy source:
/** 
 * Serializes a java object using kryo serialization
 * @param object
 * @param sendMessage
 * @param buffer
 */
private void serializeObject(Object object,MPISendMessage sendMessage,MPIBuffer buffer){
  byte[] data;
  int dataPosition;
  ByteBuffer byteBuffer=buffer.getByteBuffer();
  if (sendMessage.serializedState() == MPISendMessage.SerializedState.HEADER_BUILT) {
    data=serializer.serialize(object);
    byteBuffer.putInt(12,data.length);
    MessageHeader.Builder builder=MessageHeader.newBuilder(sendMessage.getSource(),sendMessage.getEdge(),data.length);
    builder.subEdge(sendMessage.getSubEdge());
    sendMessage.getMPIMessage().setHeader(builder.build());
    dataPosition=0;
    sendMessage.setSendBytes(data);
    LOG.log(Level.INFO,String.format("String_Node_Str",sendMessage.getSource(),sendMessage.getEdge(),sendMessage.getPath(),data.length));
  }
 else {
    data=sendMessage.getSendBytes();
    dataPosition=sendMessage.getByteCopied();
  }
  LOG.log(Level.INFO,"String_Node_Str");
  if (grouped && MPISendMessage.SerializedState.BODY == sendMessage.serializedState()) {
    byteBuffer.putInt(sendMessage.getPath());
  }
  int remainingToCopy=data.length - dataPosition;
  int bufferSpace=byteBuffer.capacity() - byteBuffer.position();
  int copyBytes=remainingToCopy > bufferSpace ? bufferSpace : remainingToCopy;
  byteBuffer.put(data,dataPosition,copyBytes);
  sendMessage.setByteCopied(dataPosition + copyBytes);
  buffer.setSize(byteBuffer.position());
  if (copyBytes == remainingToCopy) {
    sendMessage.setSerializedState(MPISendMessage.SerializedState.FINISHED);
  }
}

Fixed version (ground truth):
/** 
 * Serializes a java object using kryo serialization
 * @param object
 * @param sendMessage
 * @param buffer
 */
private void serializeObject(Object object,MPISendMessage sendMessage,MPIBuffer buffer){
  byte[] data;
  int dataPosition;
  ByteBuffer byteBuffer=buffer.getByteBuffer();
  if (sendMessage.serializedState() == MPISendMessage.SerializedState.HEADER_BUILT) {
    data=serializer.serialize(object);
    byteBuffer.putInt(12,data.length);
    MessageHeader.Builder builder=MessageHeader.newBuilder(sendMessage.getSource(),sendMessage.getEdge(),data.length);
    builder.subEdge(sendMessage.getSubEdge());
    sendMessage.getMPIMessage().setHeader(builder.build());
    dataPosition=0;
    sendMessage.setSendBytes(data);
    LOG.log(Level.INFO,String.format("String_Node_Str",sendMessage.getSource(),sendMessage.getEdge(),sendMessage.getPath(),data.length));
  }
 else {
    data=sendMessage.getSendBytes();
    dataPosition=sendMessage.getByteCopied();
  }
  if (grouped && MPISendMessage.SerializedState.BODY == sendMessage.serializedState()) {
    byteBuffer.putInt(sendMessage.getPath());
  }
  int remainingToCopy=data.length - dataPosition;
  int bufferSpace=byteBuffer.capacity() - byteBuffer.position();
  int copyBytes=remainingToCopy > bufferSpace ? bufferSpace : remainingToCopy;
  byteBuffer.put(data,dataPosition,copyBytes);
  sendMessage.setByteCopied(dataPosition + copyBytes);
  LOG.log(Level.INFO,String.format("String_Node_Str" + "String_Node_Str",byteBuffer.position(),copyBytes,remainingToCopy));
  buffer.setSize(byteBuffer.position());
  if (copyBytes == remainingToCopy) {
    sendMessage.setSerializedState(MPISendMessage.SerializedState.FINISHED);
  }
 else {
    sendMessage.setSerializedState(MPISendMessage.SerializedState.BODY);
  }
}