Program: 76361
Project: 76361
Buggy source:
/** 
 * Return the keys and values currently in the queue as a pair of arrays, but no more of them than the number given as an argument.  The return value is an array of arrays, where the 0 element is an array of keys and the 1 element is an array of values.  Each array has length equal to the argument or to the size of the queue, whichever is smaller. To get all the entries in the queue, call this method with argument Integer.MAX_VALUE.
 * @param limit The maximum number of keys and values desired.
 * @return The keys and values currently in the queue.
 */
public synchronized final Object[][] toArray(int limit){
  if (limit > _qSize)   limit=_qSize;
  Object[][] result=new Object[2][limit];
  int index=0;
  int currentBucket=_minBucket;
  long virtualBucket=_minVirtualBucket;
  long minimumNextVirtualBucket=Long.MAX_VALUE;
  int indexOfMinimum=currentBucket;
  int nextStartBucket=_minBucket;
  Object minKeySoFar=null;
  CQCell[] bucketHead=new CQCell[_bucket.length];
  for (int i=0; i < _bucket.length; i++) {
    bucketHead[i]=_bucket[i].head;
  }
  while (true) {
    if (bucketHead[currentBucket] != null) {
      Object nextKeyInBucket=bucketHead[currentBucket].contents.key;
      while (_getBinIndex(nextKeyInBucket) == virtualBucket) {
        result[0][index]=nextKeyInBucket;
        result[1][index]=bucketHead[currentBucket].contents.value;
        index++;
        if (index == limit)         return result;
        bucketHead[currentBucket]=bucketHead[currentBucket].next;
        if (bucketHead[currentBucket] == null)         break;
        nextKeyInBucket=bucketHead[currentBucket].contents.key;
      }
      long nextVirtualBucket=_getBinIndex(nextKeyInBucket);
      if (nextVirtualBucket < minimumNextVirtualBucket) {
        minimumNextVirtualBucket=nextVirtualBucket;
        nextStartBucket=currentBucket;
      }
    }
    ++currentBucket;
    ++virtualBucket;
    if (currentBucket == _nBuckets)     currentBucket=0;
    if (currentBucket == nextStartBucket) {
      if (minimumNextVirtualBucket == Long.MAX_VALUE) {
        throw new InternalErrorException("String_Node_Str");
      }
      virtualBucket=minimumNextVirtualBucket;
      minimumNextVirtualBucket=Long.MAX_VALUE;
    }
  }
}

Fixed version (ground truth):
/** 
 * Return the keys and values currently in the queue as a pair of arrays, but no more of them than the number given as an argument.  The return value is an array of arrays, where the 0 element is an array of keys and the 1 element is an array of values.  Each array has length equal to the argument or to the size of the queue, whichever is smaller. To get all the entries in the queue, call this method with argument Integer.MAX_VALUE.
 * @param limit The maximum number of keys and values desired.
 * @return The keys and values currently in the queue.
 */
public synchronized final Object[][] toArray(int limit){
  if (limit > _qSize)   limit=_qSize;
  Object[][] result=new Object[2][limit];
  if (_qSize == 0)   return result;
  int index=0;
  int currentBucket=_minBucket;
  long virtualBucket=_minVirtualBucket;
  long minimumNextVirtualBucket=Long.MAX_VALUE;
  int indexOfMinimum=currentBucket;
  int nextStartBucket=_minBucket;
  Object minKeySoFar=null;
  CQCell[] bucketHead=new CQCell[_bucket.length];
  for (int i=0; i < _bucket.length; i++) {
    bucketHead[i]=_bucket[i].head;
  }
  while (true) {
    if (bucketHead[currentBucket] != null) {
      Object nextKeyInBucket=bucketHead[currentBucket].contents.key;
      while (_getBinIndex(nextKeyInBucket) == virtualBucket) {
        result[0][index]=nextKeyInBucket;
        result[1][index]=bucketHead[currentBucket].contents.value;
        index++;
        if (index == limit)         return result;
        bucketHead[currentBucket]=bucketHead[currentBucket].next;
        if (bucketHead[currentBucket] == null)         break;
        nextKeyInBucket=bucketHead[currentBucket].contents.key;
      }
      long nextVirtualBucket=_getBinIndex(nextKeyInBucket);
      if (nextVirtualBucket < minimumNextVirtualBucket) {
        minimumNextVirtualBucket=nextVirtualBucket;
        nextStartBucket=currentBucket;
      }
    }
    ++currentBucket;
    ++virtualBucket;
    if (currentBucket == _nBuckets)     currentBucket=0;
    if (currentBucket == nextStartBucket) {
      if (minimumNextVirtualBucket == Long.MAX_VALUE) {
        throw new InternalErrorException("String_Node_Str" + _qSize);
      }
      virtualBucket=minimumNextVirtualBucket;
      minimumNextVirtualBucket=Long.MAX_VALUE;
    }
  }
}