Program: 55912
Project: 55912
Buggy source:
/** 
 * Crosses the values of all pairs that have the same key. The   {@link MatchStub#match(Key,Iterator,Collector)} method is called for each element of the Cartesian product. 
 * @param key The key of all values in the iterator.
 * @param vals An iterator over values that share the same key.
 * @param out The collector to write the results to.
 * @throws Exception 
 */
private final void crossValues(final Iterator<PactRecord> values,final OutputCollector out) throws Exception {
  final PactRecord[] valBuffer=new PactRecord[VALUE_BUFFER_SIZE];
  int bufferValCnt;
  for (bufferValCnt=0; bufferValCnt < VALUE_BUFFER_SIZE; bufferValCnt++) {
    if (values.hasNext()) {
      valBuffer[bufferValCnt]=values.next().createCopy();
    }
 else {
      break;
    }
  }
  for (int i=0; i < bufferValCnt; i++) {
    if (!this.running)     return;
    for (int j=0; j < bufferValCnt; j++) {
      if (!this.running)       return;
      stub.match(valBuffer[i].createCopy(),valBuffer[j].createCopy(),out);
    }
  }
  if (this.running && values.hasNext()) {
    MutableObjectIterator<PactRecord> valReader=new MutableObjectIterator<PactRecord>(){
      @Override public boolean next(      PactRecord target) throws IOException {
        if (!running || !values.hasNext()) {
          return false;
        }
        values.next().copyTo(target);
        for (int i=0; i < VALUE_BUFFER_SIZE; i++) {
          try {
            stub.match(valBuffer[i].createCopy(),target.createCopy(),out);
          }
 catch (          Exception e) {
            e.printStackTrace();
          }
        }
        return true;
      }
    }
;
    SpillingResettableMutableObjectIterator outerValResettableIterator=null;
    SpillingResettableMutableObjectIterator innerValResettableIterator=null;
    try {
      outerValResettableIterator=new SpillingResettableMutableObjectIterator(memoryManager,ioManager,valReader,(long)(availableMemory * (MEMORY_SHARE_RATIO / 2)),this);
      outerValResettableIterator.open();
      BufferIncludingIterator bii=new BufferIncludingIterator(valBuffer,outerValResettableIterator);
      PactRecord outerRecord=new PactRecord();
      PactRecord innerRecord=new PactRecord();
      if (this.running && outerValResettableIterator.next(outerRecord)) {
        innerValResettableIterator=new SpillingResettableMutableObjectIterator(memoryManager,ioManager,bii,(long)(availableMemory * (MEMORY_SHARE_RATIO / 2)),this);
        innerValResettableIterator.open();
        outerValResettableIterator.reset();
        while (this.running && outerValResettableIterator.next(outerRecord)) {
          bufferValCnt=0;
          do {
            outerRecord.copyTo(valBuffer[bufferValCnt++]);
          }
 while (this.running && outerValResettableIterator.next(outerRecord) && bufferValCnt < VALUE_BUFFER_SIZE);
          if (bufferValCnt == 0)           break;
          while (this.running && innerValResettableIterator.next(innerRecord)) {
            for (int i=0; i < bufferValCnt; i++) {
              stub.match(valBuffer[i].createCopy(),innerRecord,out);
              if (i < bufferValCnt - 1)               innerValResettableIterator.repeatLast(innerRecord);
            }
          }
          innerValResettableIterator.reset();
        }
      }
    }
 catch (    Exception e) {
      throw new RuntimeException(e);
    }
 finally {
      if (innerValResettableIterator != null) {
        innerValResettableIterator.close();
      }
      if (outerValResettableIterator != null) {
        outerValResettableIterator.close();
      }
    }
  }
}

Fixed version (ground truth):
/** 
 * Crosses the values of all pairs that have the same key. The   {@link MatchStub#match(Key,Iterator,Collector)} method is called for each element of the Cartesian product. 
 * @param values An iterator over values that share the same key.
 * @param out The collector to write the results to.
 * @throws Exception 
 */
private final void crossValues(final Iterator<PactRecord> values,final OutputCollector out) throws Exception {
  final PactRecord[] valBuffer=new PactRecord[VALUE_BUFFER_SIZE];
  int bufferValCnt;
  for (bufferValCnt=0; bufferValCnt < VALUE_BUFFER_SIZE; bufferValCnt++) {
    if (values.hasNext()) {
      valBuffer[bufferValCnt]=values.next().createCopy();
    }
 else {
      break;
    }
  }
  for (int i=0; i < bufferValCnt; i++) {
    if (!this.running)     return;
    for (int j=0; j < bufferValCnt; j++) {
      if (!this.running)       return;
      stub.match(valBuffer[i].createCopy(),valBuffer[j].createCopy(),out);
    }
  }
  if (this.running && values.hasNext()) {
    MutableObjectIterator<PactRecord> valReader=new MutableObjectIterator<PactRecord>(){
      @Override public boolean next(      PactRecord target) throws IOException {
        if (!running || !values.hasNext()) {
          return false;
        }
        values.next().copyTo(target);
        for (int i=0; i < VALUE_BUFFER_SIZE; i++) {
          try {
            stub.match(valBuffer[i].createCopy(),target.createCopy(),out);
          }
 catch (          Exception e) {
            exceptionInMatchForValReader=e;
            return false;
          }
        }
        return true;
      }
    }
;
    SpillingResettableMutableObjectIterator outerValResettableIterator=null;
    SpillingResettableMutableObjectIterator innerValResettableIterator=null;
    try {
      outerValResettableIterator=new SpillingResettableMutableObjectIterator(memoryManager,ioManager,valReader,(long)(availableMemory * (MEMORY_SHARE_RATIO / 2)),this);
      outerValResettableIterator.open();
      if (exceptionInMatchForValReader != null) {
        throw exceptionInMatchForValReader;
      }
      BufferIncludingIterator bii=new BufferIncludingIterator(valBuffer,outerValResettableIterator);
      PactRecord outerRecord=new PactRecord();
      PactRecord innerRecord=new PactRecord();
      if (this.running) {
        innerValResettableIterator=new SpillingResettableMutableObjectIterator(memoryManager,ioManager,bii,(long)(availableMemory * (MEMORY_SHARE_RATIO / 2)),this);
        innerValResettableIterator.open();
        outerValResettableIterator.reset();
        while (this.running && outerValResettableIterator.next(outerRecord)) {
          bufferValCnt=0;
          do {
            outerRecord.copyTo(valBuffer[bufferValCnt++]);
          }
 while (this.running && bufferValCnt < VALUE_BUFFER_SIZE && outerValResettableIterator.next(outerRecord));
          if (bufferValCnt == 0)           break;
          while (this.running && innerValResettableIterator.next(innerRecord)) {
            for (int i=0; i < bufferValCnt; i++) {
              stub.match(valBuffer[i].createCopy(),innerRecord,out);
              if (i < bufferValCnt - 1)               innerValResettableIterator.repeatLast(innerRecord);
            }
          }
          innerValResettableIterator.reset();
        }
      }
    }
 catch (    Exception e) {
      throw new RuntimeException(e);
    }
 finally {
      if (innerValResettableIterator != null) {
        innerValResettableIterator.close();
      }
      if (outerValResettableIterator != null) {
        outerValResettableIterator.close();
      }
    }
  }
}