Program: 99422
Project: 99422
Buggy source:
@Override public void run(){
  byte[] dequedDataBuffer;
  int dequedDataBufferLength;
  int queueSize;
  final int maxPacketSize=outputEndpoint.getMaxPacketSize();
  byte[] endpointBuffer=new byte[maxPacketSize];
  int endpointBufferLength;
  int bufferPosition;
  int usbRequestFailCount;
  int bytesWritten;
  while (!stopFlag) {
    dequedDataBuffer=null;
synchronized (queue) {
      queueSize=queue.size();
      if (queueSize > 0) {
        dequedDataBuffer=queue.poll();
      }
    }
    if (suspendFlag) {
      try {
        sleep(500);
      }
 catch (      InterruptedException e) {
      }
      continue;
    }
    if (dequedDataBuffer != null) {
      dequedDataBufferLength=dequedDataBuffer.length;
synchronized (usbDeviceConnection) {
        for (bufferPosition=0; bufferPosition < dequedDataBufferLength; bufferPosition+=maxPacketSize) {
          endpointBufferLength=dequedDataBufferLength - bufferPosition;
          if (endpointBufferLength > maxPacketSize) {
            endpointBufferLength=maxPacketSize;
          }
          usbRequestFailCount=0;
          while (true) {
            if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR2) {
              bytesWritten=usbDeviceConnection.bulkTransfer(outputEndpoint,dequedDataBuffer,bufferPosition,endpointBufferLength,10);
            }
 else {
              if (bufferPosition > 0) {
                System.arraycopy(dequedDataBuffer,bufferPosition,endpointBuffer,0,endpointBufferLength);
                bytesWritten=usbDeviceConnection.bulkTransfer(outputEndpoint,endpointBuffer,endpointBufferLength,10);
              }
 else {
                bytesWritten=usbDeviceConnection.bulkTransfer(outputEndpoint,dequedDataBuffer,endpointBufferLength,10);
              }
            }
            if (bytesWritten < 0) {
              usbRequestFailCount++;
            }
 else {
              break;
            }
            if (usbRequestFailCount > 10) {
              stopFlag=true;
              break;
            }
          }
          if (stopFlag) {
            break;
          }
        }
      }
    }
    if (queueSize == 0 && !interrupted()) {
      try {
        sleep(500);
      }
 catch (      InterruptedException e) {
      }
    }
  }
}

Fixed version (ground truth):
@Override public void run(){
  byte[] dequedDataBuffer;
  int dequedDataBufferLength;
  int queueSize;
  final int maxPacketSize=outputEndpoint.getMaxPacketSize();
  byte[] endpointBuffer=new byte[maxPacketSize];
  int endpointBufferLength;
  int bufferPosition;
  int usbRequestFailCount;
  int bytesWritten;
  while (!stopFlag) {
    dequedDataBuffer=null;
synchronized (queue) {
      queueSize=queue.size();
      if (queueSize > 0) {
        dequedDataBuffer=queue.poll();
      }
    }
    if (suspendFlag) {
      try {
        sleep(500);
      }
 catch (      InterruptedException e) {
      }
      continue;
    }
    if (dequedDataBuffer != null) {
      dequedDataBufferLength=dequedDataBuffer.length;
synchronized (usbDeviceConnection) {
        for (bufferPosition=0; bufferPosition < dequedDataBufferLength; bufferPosition+=maxPacketSize) {
          endpointBufferLength=dequedDataBufferLength - bufferPosition;
          if (endpointBufferLength > maxPacketSize) {
            endpointBufferLength=maxPacketSize;
          }
          usbRequestFailCount=0;
          while (true) {
            if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR2) {
              bytesWritten=usbDeviceConnection.bulkTransfer(outputEndpoint,dequedDataBuffer,bufferPosition,endpointBufferLength,10);
            }
 else {
              if (bufferPosition > 0) {
                System.arraycopy(dequedDataBuffer,bufferPosition,endpointBuffer,0,endpointBufferLength);
                bytesWritten=usbDeviceConnection.bulkTransfer(outputEndpoint,endpointBuffer,endpointBufferLength,10);
              }
 else {
                bytesWritten=usbDeviceConnection.bulkTransfer(outputEndpoint,dequedDataBuffer,endpointBufferLength,10);
              }
            }
            if (bytesWritten < 0) {
              usbRequestFailCount++;
            }
 else {
              break;
            }
            if (usbRequestFailCount > 10) {
              stopFlag=true;
              break;
            }
          }
          if (stopFlag) {
            break;
          }
        }
      }
      if (dequedDataBuffer.length == 4) {
synchronized (queue) {
          bufferPool.addLast(dequedDataBuffer);
        }
      }
    }
    if (queueSize == 0 && !interrupted()) {
      try {
        sleep(500);
      }
 catch (      InterruptedException e) {
      }
    }
  }
}