Program: 28449
Project: 28449
Buggy source:
@Override public void complete(ActionReport report,Payload.Outbound outbound){
  if (commandProgress != null && report != null && report.getActionExitCode() == ExitCode.SUCCESS) {
    commandProgress.complete();
  }
  super.actionReport=report;
  this.payload=outbound;
  this.completionDate=System.currentTimeMillis();
  if (isManagedJob) {
    if (getState().equals(State.RUNNING_RETRYABLE) && failToRetryable) {
      JobManagerService jobManager=Globals.getDefaultHabitat().getService(JobManagerService.class);
      jobManager.getRetryableJobsInfo().put(id,new CompletedJob(id,completionDate,jobsFile));
      jobManager.purgeJob(id);
      setState(State.FAILED_RETRYABLE);
    }
 else {
      JobPersistence jobPersistenceService;
      if (scope != null) {
        jobPersistenceService=Globals.getDefaultHabitat().getService(JobPersistence.class,scope + "String_Node_Str");
      }
 else {
        jobPersistenceService=Globals.getDefaultHabitat().getService(JobPersistenceService.class);
      }
      State finalState=State.COMPLETED;
      if (getState().equals(State.REVERTING)) {
        finalState=State.REVERTED;
      }
      jobPersistenceService.persist(new JobInfo(id,commandName,executionDate,report.getActionExitCode().name(),subjectUsernames.get(0),report.getMessage(),getJobsFile(),finalState.name(),completionDate));
      if (getState().equals(State.RUNNING_RETRYABLE) || getState().equals(State.REVERTING)) {
        JobManagerService jobManager=Globals.getDefaultHabitat().getService(JobManagerService.class);
        jobManager.deleteCheckpoint(this);
      }
      setState(finalState);
    }
  }
 else {
    setState(State.COMPLETED);
  }
}

Fixed version (ground truth):
@Override public void complete(ActionReport report,Payload.Outbound outbound){
  if (commandProgress != null && report != null && report.getActionExitCode() == ExitCode.SUCCESS) {
    commandProgress.complete();
  }
  super.actionReport=report;
  this.payload=outbound;
  this.completionDate=System.currentTimeMillis();
  if (isManagedJob) {
    if (getState().equals(State.RUNNING_RETRYABLE) && failToRetryable) {
      JobManagerService jobManager=Globals.getDefaultHabitat().getService(JobManagerService.class);
      jobManager.getRetryableJobsInfo().put(id,CheckpointHelper.CheckpointFilename.createBasic(this));
      jobManager.purgeJob(id);
      setState(State.FAILED_RETRYABLE);
    }
 else {
      JobPersistence jobPersistenceService;
      if (scope != null) {
        jobPersistenceService=Globals.getDefaultHabitat().getService(JobPersistence.class,scope + "String_Node_Str");
      }
 else {
        jobPersistenceService=Globals.getDefaultHabitat().getService(JobPersistenceService.class);
      }
      State finalState=State.COMPLETED;
      if (getState().equals(State.REVERTING)) {
        finalState=State.REVERTED;
      }
      jobPersistenceService.persist(new JobInfo(id,commandName,executionDate,report.getActionExitCode().name(),subjectUsernames.get(0),report.getMessage(),getJobsFile(),finalState.name(),completionDate));
      if (getState().equals(State.RUNNING_RETRYABLE) || getState().equals(State.REVERTING)) {
        JobManagerService jobManager=Globals.getDefaultHabitat().getService(JobManagerService.class);
        jobManager.deleteCheckpoint(this);
      }
      setState(finalState);
    }
  }
 else {
    setState(State.COMPLETED);
  }
}