Program: 175704
Project: 175704
Buggy source:
public boolean append(BrokerMessage.MessageContent.Builder message){
  boolean isNeedNewSegmentFile=false;
  int segmentSize=startOffsetSegmentMap.size();
  lock.lock();
  try {
    if (segmentSize == 0) {
      isNeedNewSegmentFile=true;
    }
 else {
      Segment lastSegment=startOffsetSegmentMap.lastEntry().getValue();
      if (!lastSegment.isCanWrite()) {
        isNeedNewSegmentFile=true;
      }
 else {
        int maxSegmentSize=GlobalConf.getInstance().getMaxSegmentSize();
        if (lastSegment.getFileSize() + message.build().getSerializedSize() > maxSegmentSize) {
          isNeedNewSegmentFile=true;
          lastSegment.close();
          lastSegment.setCanWrite(false);
          String newFileName=String.format("String_Node_Str",lastSegment.getStartOffset(),lastSegment.getEndOffset());
          String newFullFileName=segmentDir + File.separator + newFileName;
          File newFile=new File(newFullFileName);
          newFile.createNewFile();
          String oldFullFileName=segmentDir + File.separator + lastSegment.getFileName();
          File oldFile=new File(oldFullFileName);
          oldFile.renameTo(newFile);
          lastSegment.setFileName(newFileName);
          lastSegment.setRandomAccessFile(RaftFileUtils.openFile(segmentDir,newFileName,"String_Node_Str"));
          lastSegment.setChannel(lastSegment.getRandomAccessFile().getChannel());
        }
      }
    }
    Segment newSegment;
    if (isNeedNewSegmentFile) {
      long newStartOffset=getLastEndOffset();
      String newSegmentFileName=String.format("String_Node_Str",newStartOffset);
      String newFullFileName=segmentDir + File.separator + newSegmentFileName;
      File newSegmentFile=new File(newFullFileName);
      if (!newSegmentFile.exists()) {
        newSegmentFile.createNewFile();
      }
      newSegment=new Segment(segmentDir,newSegmentFileName);
      startOffsetSegmentMap.put(newSegment.getStartOffset(),newSegment);
    }
 else {
      newSegment=startOffsetSegmentMap.lastEntry().getValue();
    }
    return newSegment.append(message);
  }
 catch (  IOException ex) {
    throw new RuntimeException("String_Node_Str" + ex.getMessage());
  }
 finally {
    lock.unlock();
  }
}

Fixed version (ground truth):
public boolean append(BrokerMessage.MessageContent.Builder message){
  boolean isNeedNewSegmentFile=false;
  int segmentSize=startOffsetSegmentMap.size();
  lock.lock();
  try {
    if (segmentSize == 0) {
      isNeedNewSegmentFile=true;
    }
 else {
      Segment lastSegment=startOffsetSegmentMap.lastEntry().getValue();
      if (!lastSegment.isCanWrite()) {
        isNeedNewSegmentFile=true;
      }
 else {
        int maxSegmentSize=GlobalConf.getInstance().getMaxSegmentSize();
        if (lastSegment.getFileSize() + message.build().getSerializedSize() > maxSegmentSize) {
          isNeedNewSegmentFile=true;
          lastSegment.close();
          lastSegment.setCanWrite(false);
          String newFileName=String.format("String_Node_Str",lastSegment.getStartOffset(),lastSegment.getEndOffset());
          String newFullFileName=segmentDir + File.separator + newFileName;
          File newFile=new File(newFullFileName);
          String oldFullFileName=segmentDir + File.separator + lastSegment.getFileName();
          File oldFile=new File(oldFullFileName);
          FileUtils.moveFile(oldFile,newFile);
          lastSegment.setFileName(newFileName);
          lastSegment.setRandomAccessFile(RaftFileUtils.openFile(segmentDir,newFileName,"String_Node_Str"));
          lastSegment.setChannel(lastSegment.getRandomAccessFile().getChannel());
        }
      }
    }
    Segment newSegment;
    if (isNeedNewSegmentFile) {
      long newStartOffset=getLastEndOffset();
      String newSegmentFileName=String.format("String_Node_Str",newStartOffset);
      String newFullFileName=segmentDir + File.separator + newSegmentFileName;
      File newSegmentFile=new File(newFullFileName);
      if (!newSegmentFile.exists()) {
        newSegmentFile.createNewFile();
      }
      newSegment=new Segment(segmentDir,newSegmentFileName);
      startOffsetSegmentMap.put(newSegment.getStartOffset(),newSegment);
    }
 else {
      newSegment=startOffsetSegmentMap.lastEntry().getValue();
    }
    return newSegment.append(message);
  }
 catch (  IOException ex) {
    throw new RuntimeException("String_Node_Str" + ex.getMessage());
  }
 finally {
    lock.unlock();
  }
}