Program: 34263
Project: 34263
Buggy source:
/** 
 * Runs periodic background processing. <br><br> This method will first check whether there are any QueueRecord objects saved in the database. If there are, it will attempt to complete the task recorded by each of those QueueRecords in turn. After that, it will run the 'check for messages' task. If no QueueRecords are found in the database, it will run the 'check for messages' task. 
 */
private void processTasks(){
  Log.i(TAG,"String_Node_Str");
  TaskController taskController=new TaskController();
  QueueRecordProvider queueProv=QueueRecordProvider.get(getApplicationContext());
  QueueRecordProcessor queueProc=new QueueRecordProcessor();
  ArrayList<QueueRecord> queueRecords=queueProv.getAllQueueRecords();
  Log.i(TAG,"String_Node_Str" + queueRecords.size());
  long currentTime=System.currentTimeMillis() / 1000;
  Iterator<QueueRecord> iterator=queueRecords.iterator();
  while (iterator.hasNext()) {
    QueueRecord q=iterator.next();
    if (q.getTriggerTime() > currentTime) {
      Log.i(TAG,"String_Node_Str" + q.getTask() + "String_Node_Str"+ "String_Node_Str"+ (q.getTriggerTime() - currentTime)+ "String_Node_Str");
      iterator.remove();
      ;
    }
  }
  if (queueRecords.size() > 0) {
    Collections.sort(queueRecords);
    for (    QueueRecord q : queueRecords) {
      Log.i(TAG,"String_Node_Str" + q.getTask() + "String_Node_Str"+ q.getAttempts());
      int attempts=q.getAttempts();
      String task=q.getTask();
      if (attempts > MAXIMUM_ATTEMPTS) {
        if (task.equals(TASK_SEND_MESSAGE)) {
          MessageProvider msgProv=MessageProvider.get(getApplicationContext());
          Message messageToSend=msgProv.searchForSingleRecord(q.getObject0Id());
          messageToSend.setStatus(Message.STATUS_SENDING_FAILED);
          msgProv.updateMessage(messageToSend);
        }
        queueProc.deleteQueueRecord(q);
        continue;
      }
      if (task.equals(TASK_SEND_MESSAGE)) {
        if (NetworkHelper.checkInternetAvailability() == true) {
          try {
            MessageProvider msgProv=MessageProvider.get(getApplicationContext());
            Message messageToSend=msgProv.searchForSingleRecord(q.getObject0Id());
            ArrayList<QueueRecord> matchingRecords=queueProv.searchQueueRecords(QueueRecordsTable.COLUMN_OBJECT_0_ID,String.valueOf(q.getObject0Id()));
            for (            QueueRecord match : matchingRecords) {
              if (match.getTask().equals(TASK_SEND_MESSAGE) || match.getTask().equals(TASK_PROCESS_OUTGOING_MESSAGE)) {
                if (match.getTriggerTime() < q.getTriggerTime()) {
                  if (match.getRecordCount() == 0) {
                    q.setTriggerTime(q.getTriggerTime() + FIRST_ATTEMPT_TTL);
                  }
 else {
                    q.setTriggerTime(q.getTriggerTime() + SUBSEQUENT_ATTEMPTS_TTL);
                  }
                  queueProv.updateQueueRecord(q);
                  continue;
                }
              }
            }
            if (q.getRecordCount() == 0) {
              taskController.sendMessage(q,messageToSend,DO_POW,FIRST_ATTEMPT_TTL,FIRST_ATTEMPT_TTL);
            }
 else {
              queueProc.createAndSaveQueueRecord(TASK_SEND_MESSAGE,(System.currentTimeMillis() / 1000) + SUBSEQUENT_ATTEMPTS_TTL,q.getRecordCount() + 1,messageToSend,null);
              taskController.sendMessage(q,messageToSend,DO_POW,SUBSEQUENT_ATTEMPTS_TTL,SUBSEQUENT_ATTEMPTS_TTL);
            }
          }
 catch (          RuntimeException e) {
            Log.i(TAG,"String_Node_Str" + TASK_SEND_MESSAGE + "String_Node_Str"+ "String_Node_Str");
            queueProv.deleteQueueRecord(q);
            continue;
          }
        }
      }
 else       if (task.equals(TASK_PROCESS_OUTGOING_MESSAGE)) {
        Message messageToSend=null;
        try {
          MessageProvider msgProv=MessageProvider.get(getApplicationContext());
          messageToSend=msgProv.searchForSingleRecord(q.getObject0Id());
        }
 catch (        RuntimeException e) {
          Log.i(TAG,"String_Node_Str" + TASK_PROCESS_OUTGOING_MESSAGE + "String_Node_Str"+ "String_Node_Str");
          queueProv.deleteQueueRecord(q);
          continue;
        }
        PubkeyProvider pubProv=PubkeyProvider.get(App.getContext());
        Pubkey toPubkey=pubProv.searchForSingleRecord(q.getObject1Id());
        if (q.getRecordCount() == 0) {
          taskController.processOutgoingMessage(q,messageToSend,toPubkey,DO_POW,FIRST_ATTEMPT_TTL);
        }
 else {
          taskController.processOutgoingMessage(q,messageToSend,toPubkey,DO_POW,SUBSEQUENT_ATTEMPTS_TTL);
        }
      }
 else       if (task.equals(TASK_DISSEMINATE_MESSAGE)) {
        if (NetworkHelper.checkInternetAvailability() == true) {
          PayloadProvider payProv=PayloadProvider.get(getApplicationContext());
          Payload payloadToSend=payProv.searchForSingleRecord(q.getObject0Id());
          PubkeyProvider pubProv=PubkeyProvider.get(App.getContext());
          Pubkey toPubkey=pubProv.searchForSingleRecord(q.getObject1Id());
          taskController.disseminateMessage(q,payloadToSend,toPubkey,DO_POW);
        }
      }
 else       if (task.equals(TASK_CREATE_IDENTITY)) {
        taskController.createIdentity(q,DO_POW);
      }
 else       if (task.equals(TASK_DISSEMINATE_PUBKEY)) {
        if (NetworkHelper.checkInternetAvailability() == true) {
          PayloadProvider payProv=PayloadProvider.get(getApplicationContext());
          Payload payloadToSend=payProv.searchForSingleRecord(q.getObject0Id());
          taskController.disseminatePubkey(q,payloadToSend,DO_POW);
        }
      }
 else {
        Log.e(TAG,"String_Node_Str" + "String_Node_Str" + task);
      }
    }
    runPeriodicTasks();
  }
 else {
    runPeriodicTasks();
    if (checkIfDatabaseCleaningIsRequired()) {
      Intent intent=new Intent(getBaseContext(),DatabaseCleaningService.class);
      intent.putExtra(DatabaseCleaningService.EXTRA_RUN_DATABASE_CLEANING_ROUTINE,true);
      startService(intent);
    }
  }
}

Fixed version (ground truth):
/** 
 * Runs periodic background processing. <br><br> This method will first check whether there are any QueueRecord objects saved in the database. If there are, it will attempt to complete the task recorded by each of those QueueRecords in turn. After that, it will run the 'check for messages' task. If no QueueRecords are found in the database, it will run the 'check for messages' task. 
 */
private void processTasks(){
  Log.i(TAG,"String_Node_Str");
  TaskController taskController=new TaskController();
  QueueRecordProvider queueProv=QueueRecordProvider.get(getApplicationContext());
  QueueRecordProcessor queueProc=new QueueRecordProcessor();
  ArrayList<QueueRecord> queueRecords=queueProv.getAllQueueRecords();
  Log.i(TAG,"String_Node_Str" + queueRecords.size());
  long currentTime=System.currentTimeMillis() / 1000;
  Iterator<QueueRecord> iterator=queueRecords.iterator();
  while (iterator.hasNext()) {
    QueueRecord q=iterator.next();
    if (q.getTriggerTime() > currentTime) {
      Log.i(TAG,"String_Node_Str" + q.getTask() + "String_Node_Str"+ "String_Node_Str"+ (q.getTriggerTime() - currentTime)+ "String_Node_Str");
      iterator.remove();
      ;
    }
  }
  if (queueRecords.size() > 0) {
    Collections.sort(queueRecords);
    for (    QueueRecord q : queueRecords) {
      Log.i(TAG,"String_Node_Str" + q.getTask() + "String_Node_Str"+ q.getAttempts());
      int attempts=q.getAttempts();
      String task=q.getTask();
      if (attempts > MAXIMUM_ATTEMPTS) {
        if (task.equals(TASK_SEND_MESSAGE)) {
          MessageProvider msgProv=MessageProvider.get(getApplicationContext());
          Message messageToSend=msgProv.searchForSingleRecord(q.getObject0Id());
          messageToSend.setStatus(Message.STATUS_SENDING_FAILED);
          msgProv.updateMessage(messageToSend);
        }
        queueProc.deleteQueueRecord(q);
        continue;
      }
      if (task.equals(TASK_SEND_MESSAGE)) {
        if (NetworkHelper.checkInternetAvailability() == true) {
          try {
            MessageProvider msgProv=MessageProvider.get(getApplicationContext());
            Message messageToSend=msgProv.searchForSingleRecord(q.getObject0Id());
            ArrayList<QueueRecord> matchingRecords=queueProv.searchQueueRecords(QueueRecordsTable.COLUMN_OBJECT_0_ID,String.valueOf(q.getObject0Id()));
            for (            QueueRecord match : matchingRecords) {
              if (match.getTask().equals(TASK_SEND_MESSAGE) || match.getTask().equals(TASK_PROCESS_OUTGOING_MESSAGE)) {
                if (match.getTriggerTime() < q.getTriggerTime()) {
                  currentTime=System.currentTimeMillis() / 1000;
                  if (match.getRecordCount() == 0) {
                    q.setTriggerTime(currentTime + FIRST_ATTEMPT_TTL);
                  }
 else {
                    q.setTriggerTime(currentTime + SUBSEQUENT_ATTEMPTS_TTL);
                  }
                  queueProv.updateQueueRecord(q);
                  continue;
                }
              }
            }
            if (q.getRecordCount() == 0) {
              taskController.sendMessage(q,messageToSend,DO_POW,FIRST_ATTEMPT_TTL,FIRST_ATTEMPT_TTL);
            }
 else {
              currentTime=System.currentTimeMillis() / 1000;
              queueProc.createAndSaveQueueRecord(TASK_SEND_MESSAGE,currentTime + SUBSEQUENT_ATTEMPTS_TTL,q.getRecordCount() + 1,messageToSend,null);
              taskController.sendMessage(q,messageToSend,DO_POW,SUBSEQUENT_ATTEMPTS_TTL,SUBSEQUENT_ATTEMPTS_TTL);
            }
          }
 catch (          RuntimeException e) {
            Log.i(TAG,"String_Node_Str" + TASK_SEND_MESSAGE + "String_Node_Str"+ "String_Node_Str");
            queueProv.deleteQueueRecord(q);
            continue;
          }
        }
      }
 else       if (task.equals(TASK_PROCESS_OUTGOING_MESSAGE)) {
        Message messageToSend=null;
        try {
          MessageProvider msgProv=MessageProvider.get(getApplicationContext());
          messageToSend=msgProv.searchForSingleRecord(q.getObject0Id());
        }
 catch (        RuntimeException e) {
          Log.i(TAG,"String_Node_Str" + TASK_PROCESS_OUTGOING_MESSAGE + "String_Node_Str"+ "String_Node_Str");
          queueProv.deleteQueueRecord(q);
          continue;
        }
        PubkeyProvider pubProv=PubkeyProvider.get(App.getContext());
        Pubkey toPubkey=pubProv.searchForSingleRecord(q.getObject1Id());
        if (q.getRecordCount() == 0) {
          taskController.processOutgoingMessage(q,messageToSend,toPubkey,DO_POW,FIRST_ATTEMPT_TTL);
        }
 else {
          taskController.processOutgoingMessage(q,messageToSend,toPubkey,DO_POW,SUBSEQUENT_ATTEMPTS_TTL);
        }
      }
 else       if (task.equals(TASK_DISSEMINATE_MESSAGE)) {
        if (NetworkHelper.checkInternetAvailability() == true) {
          PayloadProvider payProv=PayloadProvider.get(getApplicationContext());
          Payload payloadToSend=payProv.searchForSingleRecord(q.getObject0Id());
          PubkeyProvider pubProv=PubkeyProvider.get(App.getContext());
          Pubkey toPubkey=pubProv.searchForSingleRecord(q.getObject1Id());
          taskController.disseminateMessage(q,payloadToSend,toPubkey,DO_POW);
        }
      }
 else       if (task.equals(TASK_CREATE_IDENTITY)) {
        taskController.createIdentity(q,DO_POW);
      }
 else       if (task.equals(TASK_DISSEMINATE_PUBKEY)) {
        if (NetworkHelper.checkInternetAvailability() == true) {
          PayloadProvider payProv=PayloadProvider.get(getApplicationContext());
          Payload payloadToSend=payProv.searchForSingleRecord(q.getObject0Id());
          taskController.disseminatePubkey(q,payloadToSend,DO_POW);
        }
      }
 else {
        Log.e(TAG,"String_Node_Str" + "String_Node_Str" + task);
      }
    }
    runPeriodicTasks();
  }
 else {
    runPeriodicTasks();
    if (checkIfDatabaseCleaningIsRequired()) {
      Intent intent=new Intent(getBaseContext(),DatabaseCleaningService.class);
      intent.putExtra(DatabaseCleaningService.EXTRA_RUN_DATABASE_CLEANING_ROUTINE,true);
      startService(intent);
    }
  }
}