Program: 99498
Project: 99498
Buggy source:
/** 
 * SysEx Code Index Number : 0x4, 0x5, 0x6, 0x7
 * @param cable 0-15
 * @param systemExclusive : start with 'F0', and end with 'F7'
 */
public void sendMidiSystemExclusive(int cable,final byte[] systemExclusive){
  for (int sysexStartPosition=0; sysexStartPosition < systemExclusive.length; sysexStartPosition+=PARAM_BUFFER_SIZE_FOR_RAW_SYSEX) {
    int sysexTransferLength=0;
    if (sysexStartPosition + PARAM_BUFFER_SIZE_FOR_RAW_SYSEX > systemExclusive.length) {
      sysexTransferLength=systemExclusive.length - sysexStartPosition;
    }
 else {
      sysexTransferLength=PARAM_BUFFER_SIZE_FOR_RAW_SYSEX;
    }
    byte[] buffer=new byte[PARAM_BUFFER_SIZE];
    int bufferIndex=0;
    for (int sysexIndex=sysexStartPosition; sysexIndex < sysexStartPosition + sysexTransferLength; sysexIndex+=3, bufferIndex+=4) {
      if ((sysexIndex + 3 < systemExclusive.length) && (sysexIndex + 3 <= sysexStartPosition + sysexTransferLength)) {
        buffer[bufferIndex + 0]=(byte)(((cable & 0xf) << 4) | (0x4 & 0xf));
        buffer[bufferIndex + 1]=systemExclusive[sysexIndex + 0];
        buffer[bufferIndex + 2]=systemExclusive[sysexIndex + 1];
        buffer[bufferIndex + 3]=systemExclusive[sysexIndex + 2];
      }
 else {
switch (sysexStartPosition + sysexTransferLength - sysexIndex) {
case 1:
          buffer[bufferIndex + 0]=(byte)(((cable & 0xf) << 4) | (0x5 & 0xf));
        buffer[bufferIndex + 1]=systemExclusive[sysexIndex + 0];
      buffer[bufferIndex + 2]=0;
    buffer[bufferIndex + 3]=0;
  break;
case 2:
buffer[bufferIndex + 0]=(byte)(((cable & 0xf) << 4) | (0x6 & 0xf));
buffer[bufferIndex + 1]=systemExclusive[sysexIndex + 0];
buffer[bufferIndex + 2]=systemExclusive[sysexIndex + 1];
buffer[bufferIndex + 3]=0;
break;
case 3:
buffer[bufferIndex + 0]=(byte)(((cable & 0xf) << 4) | (0x7 & 0xf));
buffer[bufferIndex + 1]=systemExclusive[sysexIndex + 0];
buffer[bufferIndex + 2]=systemExclusive[sysexIndex + 1];
buffer[bufferIndex + 3]=systemExclusive[sysexIndex + 2];
break;
default :
break;
}
}
}
deviceConnection.bulkTransfer(outputEndpoint,buffer,buffer.length,0);
}
}

Fixed version (ground truth):
/** 
 * SysEx Code Index Number : 0x4, 0x5, 0x6, 0x7
 * @param cable 0-15
 * @param systemExclusive : start with 'F0', and end with 'F7'
 */
public void sendMidiSystemExclusive(int cable,final byte[] systemExclusive){
  ByteArrayOutputStream transferDataStream=new ByteArrayOutputStream();
  for (int sysexIndex=0; sysexIndex < systemExclusive.length; sysexIndex+=3) {
    if ((sysexIndex + 3 < systemExclusive.length)) {
      transferDataStream.write((((cable & 0xf) << 4) | 0x4));
      transferDataStream.write(systemExclusive[sysexIndex + 0] & 0xff);
      transferDataStream.write(systemExclusive[sysexIndex + 1] & 0xff);
      transferDataStream.write(systemExclusive[sysexIndex + 2] & 0xff);
    }
 else {
switch (systemExclusive.length % 3) {
case 1:
        transferDataStream.write((((cable & 0xf) << 4) | 0x5));
      transferDataStream.write(systemExclusive[sysexIndex + 0] & 0xff);
    transferDataStream.write(0);
  transferDataStream.write(0);
break;
case 2:
transferDataStream.write((((cable & 0xf) << 4) | 0x6));
transferDataStream.write(systemExclusive[sysexIndex + 0] & 0xff);
transferDataStream.write(systemExclusive[sysexIndex + 1] & 0xff);
transferDataStream.write(0);
break;
case 0:
transferDataStream.write((((cable & 0xf) << 4) | 0x7));
transferDataStream.write(systemExclusive[sysexIndex + 0] & 0xff);
transferDataStream.write(systemExclusive[sysexIndex + 1] & 0xff);
transferDataStream.write(systemExclusive[sysexIndex + 2] & 0xff);
break;
}
}
}
byte[] buffer=transferDataStream.toByteArray();
int transferedBytes=deviceConnection.bulkTransfer(outputEndpoint,buffer,buffer.length,0);
Log.d(Constants.TAG,"String_Node_Str" + transferedBytes + "String_Node_Str"+ buffer.length+ "String_Node_Str");
}