Program: 145218
Project: 145218
Buggy source:
/** 
 * Clean out the RMS when it's getting too full. Only deletes saved forms that have not been successfully sent.
 * @param triggerThreshold how full the RMS must be to commence purging (.8 == 80% full)
 * @param clearThreshold how full it should be before we stop purging (0. == purge every available record)
 * @param ageThreshold how old a record must be before it may be purged (in days)
 * @return whether the RMS fullness is less than the trigger threshold when done purging. if it's notwe're in serious trouble
 */
public boolean purge(double triggerThreshold,double clearThreshold,double ageThreshold){
  this.open();
  boolean ok;
  System.out.println("String_Node_Str" + (100. * getUsageFactor()) + "String_Node_Str");
  if (getUsageFactor() >= triggerThreshold) {
    System.out.println("String_Node_Str");
    Vector deletables=new Vector();
    Date now=new Date();
    IRecordStoreEnumeration instances=metaDataRMS.enumerateMetaData();
    while (instances.hasNextElement()) {
      DataModelTreeMetaData meta=null;
      try {
        meta=getMetaDataFromId(instances.nextRecordId());
      }
 catch (      RecordStorageException e) {
        e.printStackTrace();
      }
      if ((now.getTime() - meta.getDateSaved().getTime()) > ageThreshold * 86400000l)       deletables.addElement(new Integer(meta.getRecordId()));
    }
    ITransportManager tm=JavaRosaServiceProvider.instance().getTransportManager();
    Vector sendStatuses=tm.getModelDeliveryStatuses(deletables,true);
    for (int i=0, j=0; i < deletables.size(); i++, j++) {
      if (((Integer)sendStatuses.elementAt(j)).intValue() != TransportMessage.STATUS_DELIVERED) {
        deletables.removeElementAt(i);
        i--;
      }
    }
    System.out.println("String_Node_Str" + deletables.size() + "String_Node_Str");
    boolean emptyEnough=false;
    Vector purged=new Vector();
    for (int i=0; i < deletables.size() && !emptyEnough; i++) {
      int modelID=((Integer)deletables.elementAt(i)).intValue();
      deleteRecord(modelID);
      purged.addElement(new Integer(modelID));
      if (getUsageFactor() <= clearThreshold)       emptyEnough=true;
    }
    tm.wipeAssociatedMessages(purged);
    System.out.println("String_Node_Str" + purged.size() + "String_Node_Str"+ (100. * getUsageFactor())+ "String_Node_Str");
    ok=getUsageFactor() < triggerThreshold;
  }
 else {
    ok=true;
  }
  return ok;
}

Fixed version (ground truth):
/** 
 * Clean out the RMS when it's getting too full. Only deletes saved forms that have not been successfully sent.
 * @param triggerThreshold how full the RMS must be to commence purging (.8 == 80% full)
 * @param clearThreshold how full it should be before we stop purging (0. == purge every available record)
 * @param ageThreshold how old a record must be before it may be purged (in days)
 * @return whether the RMS fullness is less than the trigger threshold when done purging. if it's notwe're in serious trouble
 */
public boolean purge(double triggerThreshold,double clearThreshold,double ageThreshold){
  this.open();
  boolean ok;
  System.out.println("String_Node_Str" + (100. * getUsageFactor()) + "String_Node_Str");
  if (getUsageFactor() >= triggerThreshold) {
    System.out.println("String_Node_Str");
    Vector deletables=new Vector();
    Date now=new Date();
    IRecordStoreEnumeration instances=metaDataRMS.enumerateMetaData();
    while (instances.hasNextElement()) {
      DataModelTreeMetaData meta=null;
      try {
        meta=getMetaDataFromId(instances.nextRecordId());
        if ((now.getTime() - meta.getDateSaved().getTime()) > ageThreshold * 86400000l)         deletables.addElement(new Integer(meta.getRecordId()));
      }
 catch (      Exception e) {
        e.printStackTrace();
      }
    }
    ITransportManager tm=JavaRosaServiceProvider.instance().getTransportManager();
    Vector sendStatuses=tm.getModelDeliveryStatuses(deletables,true);
    for (int i=0, j=0; i < deletables.size(); i++, j++) {
      if (((Integer)sendStatuses.elementAt(j)).intValue() != TransportMessage.STATUS_DELIVERED) {
        deletables.removeElementAt(i);
        i--;
      }
    }
    System.out.println("String_Node_Str" + deletables.size() + "String_Node_Str");
    boolean emptyEnough=false;
    Vector purged=new Vector();
    for (int i=0; i < deletables.size() && !emptyEnough; i++) {
      int modelID=((Integer)deletables.elementAt(i)).intValue();
      deleteRecord(modelID);
      purged.addElement(new Integer(modelID));
      if (getUsageFactor() <= clearThreshold)       emptyEnough=true;
    }
    tm.wipeAssociatedMessages(purged);
    System.out.println("String_Node_Str" + purged.size() + "String_Node_Str"+ (100. * getUsageFactor())+ "String_Node_Str");
    ok=getUsageFactor() < triggerThreshold;
  }
 else {
    ok=true;
  }
  return ok;
}