Program: 189040
Project: 189040
Buggy source:
/** 
 * This method allows you to monitor a running Pegasus workflow using a statusCmd (typically something like "pegasus-status -l dir" and, if something goes wrong, it will return a ReturnValue with exit status of ReturnValue.FAILURE, ReturnValue.PROCESSING if still running, and ReturnValue.SUCCESS if finished OK. This method will watch the workflow for at least the numbers of cycles specified (each last for 5 seconds) before returning the ReturnValue.
 * @param statusCmd
 * @param statusDir
 * @return boolean indicating success or failure, use other methods to getdetails of failure
 */
public ReturnValue watchWorkflow(String statusCmd,String statusDir,int cycles){
  ReturnValue ret=new ReturnValue(ReturnValue.SUCCESS);
  Log.stdout("String_Node_Str" + statusCmd);
  boolean cont=true;
  int currCycle=0;
  try {
    Thread.sleep(20000);
  }
 catch (  InterruptedException ex) {
    Log.error("String_Node_Str" + ex.getMessage());
  }
  int failedCounts=statusCounts;
  int finishedCounts=statusCounts;
  Log.stdout("String_Node_Str");
  while (cont) {
    ReturnValue statusReturn=getWorkflowState(statusCmd);
    if (statusReturn.getExitStatus() == ReturnValue.FAILURE) {
      failedCounts--;
      if (failedCounts < 1) {
        ret.setExitStatus(ReturnValue.FAILURE);
        ret.setProcessExitStatus(ReturnValue.FAILURE);
        ReturnValue[] failedJobsInfo=getFailedJobsInfo(statusDir);
        Log.stdout("String_Node_Str" + failedJobsInfo.length);
        Log.stdout("String_Node_Str");
        if (failedJobsInfo == null || failedJobsInfo.length == 0) {
          Log.stderr("String_Node_Str");
          ret.setStderr("String_Node_Str" + statusDir + "String_Node_Str");
        }
 else {
          for (          ReturnValue failedJob : failedJobsInfo) {
            Log.stdout("String_Node_Str");
            Log.stdout(failedJob.getStdout());
            ret.setStdout(filterNull(ret.getStdout()) + filterNull(failedJob.getStdout()));
            Log.stderr("String_Node_Str");
            Log.stderr(failedJob.getStderr());
            ret.setStderr(filterNull(ret.getStderr()) + filterNull(failedJob.getStderr()));
          }
        }
        Log.error("String_Node_Str");
        cont=false;
      }
    }
 else     if (statusReturn.getExitStatus() == ReturnValue.SUCCESS) {
      finishedCounts--;
      if (finishedCounts < 1) {
        Log.stdout("String_Node_Str");
        cont=false;
        ret.setExitStatus(ReturnValue.SUCCESS);
        ret.setProcessExitStatus(ReturnValue.SUCCESS);
      }
    }
 else     if (cycles > 0 && currCycle > cycles && currCycle > statusCounts) {
      cont=false;
      ret.setExitStatus(ReturnValue.PROCESSING);
      ret.setProcessExitStatus(ReturnValue.PROCESSING);
    }
    currCycle++;
    try {
      Thread.sleep(5000);
    }
 catch (    InterruptedException ex) {
      Log.error("String_Node_Str" + ex.getMessage());
    }
  }
  ret.getAttributes().put("String_Node_Str",new Integer(this.currStep).toString());
  ret.getAttributes().put("String_Node_Str",new Integer(this.totalSteps).toString());
  ret.getAttributes().put("String_Node_Str",new Integer(this.percentage).toString());
  return (ret);
}

Fixed version (ground truth):
/** 
 * This method allows you to monitor a running Pegasus workflow using a statusCmd (typically something like "pegasus-status -l dir" and, if something goes wrong, it will return a ReturnValue with exit status of ReturnValue.FAILURE, ReturnValue.PROCESSING if still running, and ReturnValue.SUCCESS if finished OK. This method will watch the workflow for at least the numbers of cycles specified (each last for 5 seconds) before returning the ReturnValue.
 * @param statusCmd
 * @param statusDir
 * @return boolean indicating success or failure, use other methods to getdetails of failure
 */
public ReturnValue watchWorkflow(String statusCmd,String statusDir,int cycles){
  ReturnValue ret=new ReturnValue(ReturnValue.SUCCESS);
  boolean cont=true;
  int currCycle=0;
  try {
    Thread.sleep(20000);
  }
 catch (  InterruptedException ex) {
    Log.error("String_Node_Str" + ex.getMessage());
  }
  int failedCounts=statusCounts;
  int finishedCounts=statusCounts;
  Log.stdout("String_Node_Str");
  while (cont) {
    ReturnValue statusReturn=getWorkflowState(statusCmd);
    if (statusReturn.getExitStatus() == ReturnValue.FAILURE) {
      failedCounts--;
      if (failedCounts < 1) {
        ret.setExitStatus(ReturnValue.FAILURE);
        ret.setProcessExitStatus(ReturnValue.FAILURE);
        ReturnValue[] failedJobsInfo=getFailedJobsInfo(statusDir);
        Log.stdout("String_Node_Str" + failedJobsInfo.length);
        Log.stdout("String_Node_Str");
        if (failedJobsInfo == null || failedJobsInfo.length == 0) {
          Log.stderr("String_Node_Str");
          ret.setStderr("String_Node_Str" + statusDir + "String_Node_Str");
        }
 else {
          for (          ReturnValue failedJob : failedJobsInfo) {
            Log.stdout("String_Node_Str");
            Log.stdout(failedJob.getStdout());
            ret.setStdout(filterNull(ret.getStdout()) + filterNull(failedJob.getStdout()));
            Log.stderr("String_Node_Str");
            Log.stderr(failedJob.getStderr());
            ret.setStderr(filterNull(ret.getStderr()) + filterNull(failedJob.getStderr()));
          }
        }
        Log.error("String_Node_Str");
        cont=false;
      }
    }
 else     if (statusReturn.getExitStatus() == ReturnValue.SUCCESS) {
      finishedCounts--;
      if (finishedCounts < 1) {
        Log.stdout("String_Node_Str");
        cont=false;
        ret.setExitStatus(ReturnValue.SUCCESS);
        ret.setProcessExitStatus(ReturnValue.SUCCESS);
      }
    }
 else     if (cycles > 0 && currCycle > cycles && currCycle > statusCounts) {
      cont=false;
      ret.setExitStatus(ReturnValue.PROCESSING);
      ret.setProcessExitStatus(ReturnValue.PROCESSING);
    }
    currCycle++;
    try {
      Thread.sleep(5000);
    }
 catch (    InterruptedException ex) {
      Log.error("String_Node_Str" + ex.getMessage());
    }
  }
  ret.getAttributes().put("String_Node_Str",new Integer(this.currStep).toString());
  ret.getAttributes().put("String_Node_Str",new Integer(this.totalSteps).toString());
  ret.getAttributes().put("String_Node_Str",new Integer(this.percentage).toString());
  return (ret);
}