Program: 87743
Project: 87743
Buggy source:
private void writeTransferEnvelope(final TransferEnvelope transferEnvelope) throws IOException, InterruptedException {
  final Buffer buffer=transferEnvelope.getBuffer();
  if (buffer != null) {
    if (buffer.isBackedByMemory()) {
      final Buffer fileBuffer=BufferFactory.createFromFile(buffer.size(),this.task.getVertexID(),this.fileBufferManager,this.distributed);
      buffer.copyToBuffer(fileBuffer);
      transferEnvelope.setBuffer(fileBuffer);
      buffer.recycleBuffer();
    }
  }
  if (this.numberOfSerializedTransferEnvelopes % ENVELOPES_PER_META_DATA_FILE == 0) {
    if (this.fileSystem == null) {
      this.fileSystem=this.checkpointPath.getFileSystem();
    }
    if (this.metaDataFileChannel != null) {
      this.metaDataFileChannel.close();
      this.metaDataFileChannel=null;
      renameCheckpointPart();
      ++this.metaDataSuffix;
    }
  }
  if (this.metaDataFileChannel == null) {
    this.metaDataFileChannel=getMetaDataFileChannel("String_Node_Str");
  }
  this.transferEnvelopeSerializer.setTransferEnvelope(transferEnvelope);
  while (this.transferEnvelopeSerializer.write(this.metaDataFileChannel)) {
  }
  final EventList eventList=transferEnvelope.getEventList();
  if (eventList != null) {
    final Iterator<AbstractEvent> it=eventList.iterator();
    while (it.hasNext()) {
      if (it.next() instanceof ByteBufferedChannelCloseEvent) {
        ++this.numberOfClosedChannels;
      }
    }
  }
  ++this.numberOfSerializedTransferEnvelopes;
  if (this.numberOfClosedChannels == this.numberOfConnectedChannels) {
    if (this.metaDataFileChannel != null) {
      this.metaDataFileChannel.close();
      renameCheckpointPart();
    }
    getMetaDataFileChannel(CheckpointUtils.COMPLETED_CHECKPOINT_SUFFIX).close();
    LOG.info("String_Node_Str" + this.task.getVertexID());
    this.task.checkpointStateChanged(CheckpointState.COMPLETE);
  }
}

Fixed version (ground truth):
private void writeTransferEnvelope(final TransferEnvelope transferEnvelope) throws IOException, InterruptedException {
  Buffer buffer=transferEnvelope.getBuffer();
  if (buffer != null) {
    if (buffer.isBackedByMemory()) {
      final Buffer fileBuffer=BufferFactory.createFromFile(buffer.size(),this.task.getVertexID(),this.fileBufferManager,this.distributed);
      buffer.copyToBuffer(fileBuffer);
      transferEnvelope.setBuffer(fileBuffer);
      buffer.recycleBuffer();
    }
  }
  if (this.numberOfSerializedTransferEnvelopes % ENVELOPES_PER_META_DATA_FILE == 0) {
    if (this.fileSystem == null) {
      this.fileSystem=this.checkpointPath.getFileSystem();
    }
    if (this.metaDataFileChannel != null) {
      this.metaDataFileChannel.close();
      this.metaDataFileChannel=null;
      renameCheckpointPart();
      ++this.metaDataSuffix;
    }
  }
  if (this.metaDataFileChannel == null) {
    this.metaDataFileChannel=getMetaDataFileChannel("String_Node_Str");
  }
  this.transferEnvelopeSerializer.setTransferEnvelope(transferEnvelope);
  while (this.transferEnvelopeSerializer.write(this.metaDataFileChannel)) {
  }
  buffer=transferEnvelope.getBuffer();
  if (buffer != null) {
    if (this.firstSerializedFileBuffer == null) {
      this.firstSerializedFileBuffer=buffer;
    }
 else {
      buffer.recycleBuffer();
    }
  }
  final EventList eventList=transferEnvelope.getEventList();
  if (eventList != null) {
    final Iterator<AbstractEvent> it=eventList.iterator();
    while (it.hasNext()) {
      if (it.next() instanceof ByteBufferedChannelCloseEvent) {
        ++this.numberOfClosedChannels;
      }
    }
  }
  ++this.numberOfSerializedTransferEnvelopes;
  if (this.numberOfClosedChannels == this.numberOfConnectedChannels) {
    if (this.firstSerializedFileBuffer != null) {
      this.firstSerializedFileBuffer.recycleBuffer();
    }
    if (this.metaDataFileChannel != null) {
      this.metaDataFileChannel.close();
      renameCheckpointPart();
    }
    getMetaDataFileChannel(CheckpointUtils.COMPLETED_CHECKPOINT_SUFFIX).close();
    LOG.info("String_Node_Str" + this.task.getVertexID());
    this.task.checkpointStateChanged(CheckpointState.COMPLETE);
  }
}