Program: 91450
Project: 91450
Buggy source:
/** 
 * Removes at most the given number of available elements from this queue and adds them to the given collection.  A failure encountered while attempting to add elements to collection <tt>c</tt> may result in elements being in neither, either or both collections when the associated exception is thrown.  Attempts to drain a queue to itself result in <tt>IllegalArgumentException</tt>. Further, the behavior of this operation is undefined if the specified collection is modified while the operation is in progress.
 * @param target      the array to transfer elements into
 * @param maxElements the maximum number of elements to transfer
 * @return the number of elements transferred
 * @throws UnsupportedOperationException if addition of elementsis not supported by the specified collection
 * @throws ClassCastException            if the class of an element of this queueprevents it from being added to the specified collection
 * @throws NullPointerException          if the specified collection is null
 * @throws IllegalArgumentException      if the specified collection is thisqueue, or some property of an element of this queue prevents it from being added to the specified collection
 */
int drainTo(E[] target,int maxElements){
  int readLocation=this.consumerReadLocation;
  int i=0;
  int writeLocation=this.locator.getWriteLocation();
  do {
    if (writeLocation == readLocation) {
      writeLocation=this.locator.getWriteLocation();
      if (writeLocation == readLocation) {
        setReadLocation(readLocation);
        return i;
      }
    }
    readLocation=(readLocation + 1 == dataLocator.getCapacity()) ? 0 : readLocation + 1;
    target[i]=dataLocator.getData(readLocation);
  }
 while (i <= maxElements);
  setReadLocation(readLocation);
  return maxElements;
}

Fixed version (ground truth):
/** 
 * Removes at most the given number of available elements from this queue and adds them to the given collection.  A failure encountered while attempting to add elements to collection <tt>c</tt> may result in elements being in neither, either or both collections when the associated exception is thrown.  Attempts to drain a queue to itself result in <tt>IllegalArgumentException</tt>. Further, the behavior of this operation is undefined if the specified collection is modified while the operation is in progress.
 * @param target      the array to transfer elements into
 * @param maxElements the maximum number of elements to transfer
 * @return the number of elements transferred
 * @throws UnsupportedOperationException if addition of elementsis not supported by the specified collection
 * @throws ClassCastException            if the class of an element of this queueprevents it from being added to the specified collection
 * @throws NullPointerException          if the specified collection is null
 * @throws IllegalArgumentException      if the specified collection is thisqueue, or some property of an element of this queue prevents it from being added to the specified collection
 */
int drainTo(E[] target,int maxElements){
  int readLocation=this.consumerReadLocation;
  int i=0;
  int writeLocation=this.locator.getWriterLocation();
  do {
    if (writeLocation == readLocation) {
      writeLocation=this.locator.getWriterLocation();
      if (writeLocation == readLocation) {
        setReadLocation(readLocation);
        return i;
      }
    }
    readLocation=(readLocation + 1 == dataLocator.getCapacity()) ? 0 : readLocation + 1;
    target[i]=dataLocator.getData(readLocation);
  }
 while (i <= maxElements);
  setReadLocation(readLocation);
  return maxElements;
}