Program: 16136
Project: 16136
Buggy source:
private void removeOld() throws SQLException {
  int i=0;
  ObjectArray<CacheObject> changed=ObjectArray.newInstance();
  int si=sizeIn, sm=sizeMain, rc=recordCount;
  CacheObject inNext=headIn.next, mainNext=headMain.next;
  while (((si * 4 > maxIn * 3) || (sm * 4 > maxMain * 3)) && rc > Constants.CACHE_MIN_RECORDS) {
    i++;
    if (i == rc) {
      writer.flushLog();
    }
    if (i >= rc * 2) {
      writer.getTrace().info("String_Node_Str");
      break;
    }
    if (si > maxIn) {
      CacheObject r=inNext;
      inNext=r.next;
      if (!r.canRemove()) {
        removeFromList(r);
        addToFront(headIn,r);
        continue;
      }
      rc--;
      si-=r.getMemorySize();
      if (r.isChanged()) {
        changed.add(r);
      }
 else {
        remove(r);
      }
    }
 else     if (sm > 0) {
      CacheObject r=mainNext;
      mainNext=r.next;
      if (!r.canRemove() && !(r instanceof CacheHead)) {
        removeFromList(r);
        addToFront(headMain,r);
        continue;
      }
      rc--;
      sm-=r.getMemorySize();
      if (r.isChanged()) {
        changed.add(r);
      }
 else {
        remove(r);
      }
    }
  }
  if (changed.size() > 0) {
    int mm=maxMain;
    int mi=maxIn;
    try {
      maxMain=Integer.MAX_VALUE;
      maxIn=Integer.MAX_VALUE;
      CacheObject.sort(changed);
      for (i=0; i < changed.size(); i++) {
        CacheObject rec=changed.get(i);
        writer.writeBack(rec);
      }
    }
  finally {
      maxMain=mm;
      maxIn=mi;
    }
    for (i=0; i < changed.size(); i++) {
      CacheObject rec=changed.get(i);
      remove(rec);
    }
  }
}

Fixed version (ground truth):
private void removeOld() throws SQLException {
  int i=0;
  ObjectArray<CacheObject> changed=ObjectArray.newInstance();
  int si=sizeIn, sm=sizeMain, rc=recordCount;
  CacheObject inNext=headIn.next, mainNext=headMain.next;
  while (((si * 4 > maxIn * 3) || (sm * 4 > maxMain * 3)) && rc > Constants.CACHE_MIN_RECORDS) {
    i++;
    if (i == rc) {
      writer.flushLog();
    }
    if (i >= rc * 2) {
      writer.getTrace().info("String_Node_Str");
      break;
    }
    if (si > maxIn) {
      CacheObject r=inNext;
      inNext=r.next;
      if (!r.canRemove()) {
        if (r != headIn) {
          removeFromList(r);
          addToFront(headIn,r);
        }
        continue;
      }
      rc--;
      si-=r.getMemorySize();
      if (r.isChanged()) {
        changed.add(r);
      }
 else {
        remove(r);
      }
    }
 else     if (sm > 0) {
      CacheObject r=mainNext;
      mainNext=r.next;
      if (!r.canRemove() && !(r instanceof CacheHead)) {
        removeFromList(r);
        addToFront(headMain,r);
        continue;
      }
      rc--;
      sm-=r.getMemorySize();
      if (r.isChanged()) {
        changed.add(r);
      }
 else {
        remove(r);
      }
    }
  }
  if (changed.size() > 0) {
    int mm=maxMain;
    int mi=maxIn;
    try {
      maxMain=Integer.MAX_VALUE;
      maxIn=Integer.MAX_VALUE;
      CacheObject.sort(changed);
      for (i=0; i < changed.size(); i++) {
        CacheObject rec=changed.get(i);
        writer.writeBack(rec);
      }
    }
  finally {
      maxMain=mm;
      maxIn=mi;
    }
    for (i=0; i < changed.size(); i++) {
      CacheObject rec=changed.get(i);
      remove(rec);
    }
  }
}