Program: 99466
Project: 99466
Buggy source:
@Override public void run(){
  byte[] dequedDataBuffer;
  int queueSize=0;
  final int maxPacketSize=outputEndpoint.getMaxPacketSize();
  byte[] endpointBuffer=new byte[maxPacketSize];
  int endpointBufferLength=0;
  int bufferPosition;
  int dequedDataBufferLength;
  while (stopFlag == false) {
    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) {
        if (usbRequest == null) {
          usbRequest=new UsbRequest();
          usbRequest.initialize(usbDeviceConnection,outputEndpoint);
        }
        for (bufferPosition=0; bufferPosition < dequedDataBufferLength; bufferPosition+=maxPacketSize) {
          if (bufferPosition + maxPacketSize > dequedDataBufferLength) {
            endpointBufferLength=dequedDataBufferLength % maxPacketSize;
          }
 else {
            endpointBufferLength=maxPacketSize;
          }
          System.arraycopy(dequedDataBuffer,bufferPosition,endpointBuffer,0,endpointBufferLength);
          while (usbRequest.queue(ByteBuffer.wrap(endpointBuffer),endpointBufferLength) == false) {
          }
          while (usbRequest.equals(usbDeviceConnection.requestWait()) == false) {
          }
        }
      }
    }
    if (queueSize == 0 && !interrupted()) {
      try {
        sleep(500);
      }
 catch (      InterruptedException e) {
      }
    }
  }
  if (usbRequest != null) {
    usbRequest.close();
  }
}

Fixed version (ground truth):
@Override public void run(){
  byte[] dequedDataBuffer;
  int queueSize=0;
  final int maxPacketSize=outputEndpoint.getMaxPacketSize();
  byte[] endpointBuffer=new byte[maxPacketSize];
  int endpointBufferLength=0;
  int bufferPosition;
  int dequedDataBufferLength;
  int usbRequestFailCount;
  while (stopFlag == false) {
    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) {
        if (usbRequest == null) {
          usbRequest=new UsbRequest();
          usbRequest.initialize(usbDeviceConnection,outputEndpoint);
        }
        for (bufferPosition=0; bufferPosition < dequedDataBufferLength; bufferPosition+=maxPacketSize) {
          if (bufferPosition + maxPacketSize > dequedDataBufferLength) {
            endpointBufferLength=dequedDataBufferLength % maxPacketSize;
          }
 else {
            endpointBufferLength=maxPacketSize;
          }
          System.arraycopy(dequedDataBuffer,bufferPosition,endpointBuffer,0,endpointBufferLength);
          usbRequestFailCount=0;
          while (usbRequest.queue(ByteBuffer.wrap(endpointBuffer),endpointBufferLength) == false) {
            usbRequestFailCount++;
            if (usbRequestFailCount > 10) {
              stopFlag=true;
              break;
            }
          }
          if (stopFlag) {
            break;
          }
          usbRequestFailCount=0;
          while (usbRequest.equals(usbDeviceConnection.requestWait()) == false) {
            usbRequestFailCount++;
            if (usbRequestFailCount > 10) {
              stopFlag=true;
              break;
            }
          }
        }
      }
    }
    if (queueSize == 0 && !interrupted()) {
      try {
        sleep(500);
      }
 catch (      InterruptedException e) {
      }
    }
  }
  if (usbRequest != null) {
    usbRequest.close();
  }
}