Program: 142359
Project: 142359
Buggy source:
@Override protected LogSubmitOutcomes doInBackground(Void... params){
  try {
    SqlIndexedStorageUtility<DeviceReportRecord> storage=CommCareApplication._().getStorage(DeviceReportRecord.STORAGE_KEY,DeviceReportRecord.class);
    if (serializeCurrentLogs) {
      SharedPreferences settings=PreferenceManager.getDefaultSharedPreferences(CommCareApplication._());
      settings.edit().putLong(CommCarePreferences.LOG_LAST_DAILY_SUBMIT,new Date().getTime()).commit();
      DeviceReportRecord record=DeviceReportRecord.GenerateNewRecordStub();
      try {
        DeviceReportWriter reporter;
        try {
          reporter=new DeviceReportWriter(record);
        }
 catch (        IOException e) {
          e.printStackTrace();
          return LogSubmitOutcomes.Error;
        }
        AndroidLogSerializer serializer=new AndroidLogSerializer(CommCareApplication._().getStorage(AndroidLogEntry.STORAGE_KEY,AndroidLogEntry.class));
        reporter.addReportElement(serializer);
        reporter.write();
        storage.write(record);
        serializer.purge();
      }
 catch (      Exception e) {
        e.printStackTrace();
        return LogSubmitOutcomes.Error;
      }
    }
    int numberOfLogsToSubmit=storage.getNumRecords();
    this.beginSubmissionProcess(numberOfLogsToSubmit);
    int index=0;
    ArrayList<Integer> submittedSuccesfullyIds=new ArrayList<Integer>();
    ArrayList<DeviceReportRecord> submittedSuccesfully=new ArrayList<DeviceReportRecord>();
    for (    DeviceReportRecord slr : storage) {
      try {
        if (submit(slr,index)) {
          submittedSuccesfullyIds.add(slr.getID());
          submittedSuccesfully.add(slr);
        }
        index++;
      }
 catch (      Exception e) {
      }
    }
    try {
      storage.remove(submittedSuccesfullyIds);
    }
 catch (    Exception e) {
      e.printStackTrace();
      Logger.log(AndroidLogger.TYPE_MAINTENANCE,"String_Node_Str" + e.getMessage());
      return LogSubmitOutcomes.Serialized;
    }
    for (    DeviceReportRecord record : submittedSuccesfully) {
      try {
        File f=new File(record.getFilePath());
        f.delete();
      }
 catch (      Exception e) {
      }
    }
    if (submittedSuccesfully.size() > 0) {
      Logger.log(AndroidLogger.TYPE_MAINTENANCE,"String_Node_Str" + submittedSuccesfully.size() + "String_Node_Str");
    }
    if (submittedSuccesfully.size() == numberOfLogsToSubmit) {
      return LogSubmitOutcomes.Submitted;
    }
 else {
      Logger.log(AndroidLogger.TYPE_MAINTENANCE,numberOfLogsToSubmit - submittedSuccesfully.size() + "String_Node_Str");
      return LogSubmitOutcomes.Serialized;
    }
  }
 catch (  SessionUnavailableException sue) {
    return LogSubmitOutcomes.Error;
  }
}

Fixed version (ground truth):
@Override protected LogSubmitOutcomes doInBackground(Void... params){
  try {
    SqlIndexedStorageUtility<DeviceReportRecord> storage=CommCareApplication._().getStorage(DeviceReportRecord.STORAGE_KEY,DeviceReportRecord.class);
    if (serializeCurrentLogs) {
      SharedPreferences settings=PreferenceManager.getDefaultSharedPreferences(CommCareApplication._());
      settings.edit().putLong(CommCarePreferences.LOG_LAST_DAILY_SUBMIT,new Date().getTime()).commit();
      DeviceReportRecord record=DeviceReportRecord.GenerateNewRecordStub();
      try {
        DeviceReportWriter reporter;
        try {
          reporter=new DeviceReportWriter(record);
        }
 catch (        IOException e) {
          e.printStackTrace();
          return LogSubmitOutcomes.Error;
        }
        AndroidLogSerializer serializer=new AndroidLogSerializer(CommCareApplication._().getStorage(AndroidLogEntry.STORAGE_KEY,AndroidLogEntry.class));
        reporter.addReportElement(serializer);
        reporter.write();
        storage.write(record);
        serializer.purge();
      }
 catch (      Exception e) {
        e.printStackTrace();
        return LogSubmitOutcomes.Error;
      }
    }
    int numberOfLogsToSubmit=storage.getNumRecords();
    if (numberOfLogsToSubmit == 0) {
      return LogSubmitOutcomes.Submitted;
    }
    this.beginSubmissionProcess(numberOfLogsToSubmit);
    int index=0;
    ArrayList<Integer> submittedSuccesfullyIds=new ArrayList<Integer>();
    ArrayList<DeviceReportRecord> submittedSuccesfully=new ArrayList<DeviceReportRecord>();
    for (    DeviceReportRecord slr : storage) {
      try {
        if (submit(slr,index)) {
          submittedSuccesfullyIds.add(slr.getID());
          submittedSuccesfully.add(slr);
        }
        index++;
      }
 catch (      Exception e) {
      }
    }
    try {
      storage.remove(submittedSuccesfullyIds);
    }
 catch (    Exception e) {
      e.printStackTrace();
      Logger.log(AndroidLogger.TYPE_MAINTENANCE,"String_Node_Str" + e.getMessage());
      return LogSubmitOutcomes.Serialized;
    }
    for (    DeviceReportRecord record : submittedSuccesfully) {
      try {
        File f=new File(record.getFilePath());
        f.delete();
      }
 catch (      Exception e) {
      }
    }
    if (submittedSuccesfully.size() > 0) {
      Logger.log(AndroidLogger.TYPE_MAINTENANCE,"String_Node_Str" + submittedSuccesfully.size() + "String_Node_Str");
    }
    if (submittedSuccesfully.size() == numberOfLogsToSubmit) {
      return LogSubmitOutcomes.Submitted;
    }
 else {
      Logger.log(AndroidLogger.TYPE_MAINTENANCE,numberOfLogsToSubmit - submittedSuccesfully.size() + "String_Node_Str");
      return LogSubmitOutcomes.Serialized;
    }
  }
 catch (  SessionUnavailableException sue) {
    return LogSubmitOutcomes.Error;
  }
}