Program: 32418
Project: 32418
Buggy source:
public void SendMessage(ProtocolMessage protocolMsg){
  protocolMsg.setRPCType((byte)0x00);
  SessionType sessionType=protocolMsg.getSessionType();
  byte sessionID=protocolMsg.getSessionID();
  byte[] data=null;
  if (_version > 1 && sessionType != SessionType.NAV && sessionType != SessionType.PCM) {
    if (sessionType.eq(SessionType.CONTROL)) {
      final byte[] secureData=protocolMsg.getData().clone();
      data=new byte[HEADER_SIZE + secureData.length];
      final BinaryFrameHeader binFrameHeader=SdlPacketFactory.createBinaryFrameHeader(protocolMsg.getRPCType(),protocolMsg.getFunctionID(),protocolMsg.getCorrID(),0);
      System.arraycopy(binFrameHeader.assembleHeaderBytes(),0,data,0,HEADER_SIZE);
      System.arraycopy(secureData,0,data,HEADER_SIZE,secureData.length);
    }
 else     if (protocolMsg.getBulkData() != null) {
      data=new byte[12 + protocolMsg.getJsonSize() + protocolMsg.getBulkData().length];
      sessionType=SessionType.BULK_DATA;
    }
 else {
      data=new byte[12 + protocolMsg.getJsonSize()];
    }
    if (!sessionType.eq(SessionType.CONTROL)) {
      BinaryFrameHeader binFrameHeader=new BinaryFrameHeader();
      binFrameHeader=SdlPacketFactory.createBinaryFrameHeader(protocolMsg.getRPCType(),protocolMsg.getFunctionID(),protocolMsg.getCorrID(),protocolMsg.getJsonSize());
      System.arraycopy(binFrameHeader.assembleHeaderBytes(),0,data,0,12);
      System.arraycopy(protocolMsg.getData(),0,data,12,protocolMsg.getJsonSize());
      if (protocolMsg.getBulkData() != null) {
        System.arraycopy(protocolMsg.getBulkData(),0,data,12 + protocolMsg.getJsonSize(),protocolMsg.getBulkData().length);
      }
    }
  }
 else {
    data=protocolMsg.getData();
  }
  if (sdlconn != null && protocolMsg.getPayloadProtected()) {
    if (data != null && data.length > 0) {
      SdlSession session=sdlconn.findSessionById(sessionID);
      if (session == null)       return;
      byte[] dataToRead=new byte[4096];
      SdlSecurityBase sdlSec=session.getSdlSecurity();
      if (sdlSec == null)       return;
      Integer iNumBytes=sdlSec.encryptData(data,dataToRead);
      if ((iNumBytes == null) || (iNumBytes <= 0))       return;
      byte[] encryptedData=new byte[iNumBytes];
      System.arraycopy(dataToRead,0,encryptedData,0,iNumBytes);
      data=encryptedData;
    }
  }
  Object messageLock=_messageLocks.get(sessionID);
  if (messageLock == null) {
    handleProtocolError("String_Node_Str",new SdlException("String_Node_Str",SdlExceptionCause.SDL_UNAVAILABLE));
    return;
  }
synchronized (messageLock) {
    if (data.length > MAX_DATA_SIZE) {
      messageID++;
      int frameCount=data.length / MAX_DATA_SIZE;
      if (data.length % MAX_DATA_SIZE > 0) {
        frameCount++;
      }
      byte[] firstFrameData=new byte[8];
      System.arraycopy(BitConverter.intToByteArray(data.length),0,firstFrameData,0,4);
      System.arraycopy(BitConverter.intToByteArray(frameCount),0,firstFrameData,4,4);
      SdlPacket firstHeader=SdlPacketFactory.createMultiSendDataFirst(sessionType,sessionID,messageID,_version,firstFrameData,protocolMsg.getPayloadProtected());
      firstHeader.setPriorityCoefficient(1 + protocolMsg.priorityCoefficient);
      handlePacketToSend(firstHeader);
      int currentOffset=0;
      byte frameSequenceNumber=0;
      for (int i=0; i < frameCount; i++) {
        if (i < (frameCount - 1)) {
          ++frameSequenceNumber;
          if (frameSequenceNumber == SdlPacket.FRAME_INFO_FINAL_CONNESCUTIVE_FRAME) {
            ++frameSequenceNumber;
          }
        }
 else {
          frameSequenceNumber=SdlPacket.FRAME_INFO_FINAL_CONNESCUTIVE_FRAME;
        }
        int bytesToWrite=data.length - currentOffset;
        if (bytesToWrite > MAX_DATA_SIZE) {
          bytesToWrite=MAX_DATA_SIZE;
        }
        SdlPacket consecHeader=SdlPacketFactory.createMultiSendDataRest(sessionType,sessionID,bytesToWrite,frameSequenceNumber,messageID,_version,data,currentOffset,bytesToWrite,protocolMsg.getPayloadProtected());
        consecHeader.setPriorityCoefficient(i + 2 + protocolMsg.priorityCoefficient);
        handlePacketToSend(consecHeader);
        currentOffset+=bytesToWrite;
      }
    }
 else {
      messageID++;
      SdlPacket header=SdlPacketFactory.createSingleSendData(sessionType,sessionID,data.length,messageID,_version,data,protocolMsg.getPayloadProtected());
      header.setPriorityCoefficient(protocolMsg.priorityCoefficient);
      handlePacketToSend(header);
    }
  }
}

Fixed version (ground truth):
public void SendMessage(ProtocolMessage protocolMsg){
  protocolMsg.setRPCType((byte)0x00);
  SessionType sessionType=protocolMsg.getSessionType();
  byte sessionID=protocolMsg.getSessionID();
  byte[] data=null;
  if (_version > 1 && sessionType != SessionType.NAV && sessionType != SessionType.PCM) {
    if (sessionType.eq(SessionType.CONTROL)) {
      final byte[] secureData=protocolMsg.getData().clone();
      data=new byte[HEADER_SIZE + secureData.length];
      final BinaryFrameHeader binFrameHeader=SdlPacketFactory.createBinaryFrameHeader(protocolMsg.getRPCType(),protocolMsg.getFunctionID(),protocolMsg.getCorrID(),0);
      System.arraycopy(binFrameHeader.assembleHeaderBytes(),0,data,0,HEADER_SIZE);
      System.arraycopy(secureData,0,data,HEADER_SIZE,secureData.length);
    }
 else     if (protocolMsg.getBulkData() != null) {
      data=new byte[12 + protocolMsg.getJsonSize() + protocolMsg.getBulkData().length];
      sessionType=SessionType.BULK_DATA;
    }
 else {
      data=new byte[12 + protocolMsg.getJsonSize()];
    }
    if (!sessionType.eq(SessionType.CONTROL)) {
      BinaryFrameHeader binFrameHeader=SdlPacketFactory.createBinaryFrameHeader(protocolMsg.getRPCType(),protocolMsg.getFunctionID(),protocolMsg.getCorrID(),protocolMsg.getJsonSize());
      System.arraycopy(binFrameHeader.assembleHeaderBytes(),0,data,0,12);
      System.arraycopy(protocolMsg.getData(),0,data,12,protocolMsg.getJsonSize());
      if (protocolMsg.getBulkData() != null) {
        System.arraycopy(protocolMsg.getBulkData(),0,data,12 + protocolMsg.getJsonSize(),protocolMsg.getBulkData().length);
      }
    }
  }
 else {
    data=protocolMsg.getData();
  }
  if (sdlconn != null && protocolMsg.getPayloadProtected()) {
    if (data != null && data.length > 0) {
      SdlSession session=sdlconn.findSessionById(sessionID);
      if (session == null)       return;
      byte[] dataToRead=new byte[4096];
      SdlSecurityBase sdlSec=session.getSdlSecurity();
      if (sdlSec == null)       return;
      Integer iNumBytes=sdlSec.encryptData(data,dataToRead);
      if ((iNumBytes == null) || (iNumBytes <= 0))       return;
      byte[] encryptedData=new byte[iNumBytes];
      System.arraycopy(dataToRead,0,encryptedData,0,iNumBytes);
      data=encryptedData;
    }
  }
  Object messageLock=_messageLocks.get(sessionID);
  if (messageLock == null) {
    handleProtocolError("String_Node_Str",new SdlException("String_Node_Str",SdlExceptionCause.SDL_UNAVAILABLE));
    return;
  }
synchronized (messageLock) {
    if (data.length > MAX_DATA_SIZE) {
      messageID++;
      int frameCount=data.length / MAX_DATA_SIZE;
      if (data.length % MAX_DATA_SIZE > 0) {
        frameCount++;
      }
      byte[] firstFrameData=new byte[8];
      System.arraycopy(BitConverter.intToByteArray(data.length),0,firstFrameData,0,4);
      System.arraycopy(BitConverter.intToByteArray(frameCount),0,firstFrameData,4,4);
      SdlPacket firstHeader=SdlPacketFactory.createMultiSendDataFirst(sessionType,sessionID,messageID,_version,firstFrameData,protocolMsg.getPayloadProtected());
      firstHeader.setPriorityCoefficient(1 + protocolMsg.priorityCoefficient);
      handlePacketToSend(firstHeader);
      int currentOffset=0;
      byte frameSequenceNumber=0;
      for (int i=0; i < frameCount; i++) {
        if (i < (frameCount - 1)) {
          ++frameSequenceNumber;
          if (frameSequenceNumber == SdlPacket.FRAME_INFO_FINAL_CONNESCUTIVE_FRAME) {
            ++frameSequenceNumber;
          }
        }
 else {
          frameSequenceNumber=SdlPacket.FRAME_INFO_FINAL_CONNESCUTIVE_FRAME;
        }
        int bytesToWrite=data.length - currentOffset;
        if (bytesToWrite > MAX_DATA_SIZE) {
          bytesToWrite=MAX_DATA_SIZE;
        }
        SdlPacket consecHeader=SdlPacketFactory.createMultiSendDataRest(sessionType,sessionID,bytesToWrite,frameSequenceNumber,messageID,_version,data,currentOffset,bytesToWrite,protocolMsg.getPayloadProtected());
        consecHeader.setPriorityCoefficient(i + 2 + protocolMsg.priorityCoefficient);
        handlePacketToSend(consecHeader);
        currentOffset+=bytesToWrite;
      }
    }
 else {
      messageID++;
      SdlPacket header=SdlPacketFactory.createSingleSendData(sessionType,sessionID,data.length,messageID,_version,data,protocolMsg.getPayloadProtected());
      header.setPriorityCoefficient(protocolMsg.priorityCoefficient);
      handlePacketToSend(header);
    }
  }
}