Program: 28546
Project: 28546
Buggy source:
public void attach(Job attached,JobInfo jobInfo,AdminCommandContext context,String jobName){
  ActionReport ar=context.getActionReport();
  String attachedUser=SubjectUtil.getUsernamesFromSubject(context.getSubject()).get(0);
  if ((attached == null && jobInfo == null) || (attached != null && attached.getName().startsWith("String_Node_Str")) || (attached != null && AttachCommand.COMMAND_NAME.equals(attached.getName()))) {
    ar.setActionExitCode(ActionReport.ExitCode.FAILURE);
    ar.setMessage(strings.getLocalString("String_Node_Str","String_Node_Str",jobID));
    return;
  }
  if (attached != null) {
    AdminCommandEventBroker attachedBroker=attached.getEventBroker();
    CommandProgress commandProgress=attached.getCommandProgress();
    if (commandProgress == null) {
synchronized (attachedBroker) {
        onAdminCommandEvent(AdminCommandStateImpl.EVENT_STATE_CHANGED,attached);
        attachedBroker.registerListener("String_Node_Str",this);
      }
    }
 else {
synchronized (commandProgress) {
        onAdminCommandEvent(AdminCommandStateImpl.EVENT_STATE_CHANGED,attached);
        onAdminCommandEvent(CommandProgress.EVENT_PROGRESSSTATUS_STATE,attached.getCommandProgress());
        attachedBroker.registerListener("String_Node_Str",this);
      }
    }
synchronized (attached) {
      while (attached.getState().equals(PREPARED) || attached.getState().equals(RUNNING)) {
        try {
          attached.wait(1000 * 60 * 5);
        }
 catch (        InterruptedException ex) {
        }
      }
      if (attached.getState().equals(COMPLETED)) {
        String commandUser=SubjectUtil.getUsernamesFromSubject(attached.getSubject()).get(0);
        if (commandUser != null && commandUser.equals(attachedUser)) {
          purgeJob(attached.getId());
        }
        ar.setActionExitCode(attached.getActionReport().getActionExitCode());
        ar.appendMessage(strings.getLocalString("String_Node_Str","String_Node_Str",attached.getName(),attached.getActionReport().getActionExitCode()));
      }
    }
  }
 else {
    if (jobInfo != null && jobInfo.state.equals(COMPLETED.toString())) {
      if (attachedUser != null && attachedUser.equals(jobInfo.user)) {
        purgeJob(jobInfo.jobId);
      }
      ar.setActionExitCode(ActionReport.ExitCode.SUCCESS);
      ar.appendMessage(strings.getLocalString("String_Node_Str","String_Node_Str",jobName,jobInfo.exitCode));
    }
  }
}

Fixed version (ground truth):
public void attach(Job attached,JobInfo jobInfo,AdminCommandContext context,String jobName){
  ActionReport ar=context.getActionReport();
  String attachedUser=SubjectUtil.getUsernamesFromSubject(context.getSubject()).get(0);
  if ((attached == null && jobInfo == null) || (attached != null && attached.getName().startsWith("String_Node_Str")) || (attached != null && AttachCommand.COMMAND_NAME.equals(attached.getName()))) {
    ar.setActionExitCode(ActionReport.ExitCode.FAILURE);
    ar.setMessage(strings.getLocalString("String_Node_Str","String_Node_Str",jobID));
    return;
  }
  if (attached != null) {
    AdminCommandEventBroker attachedBroker=attached.getEventBroker();
    CommandProgress commandProgress=attached.getCommandProgress();
    if (commandProgress == null) {
synchronized (attachedBroker) {
        onAdminCommandEvent(AdminCommandStateImpl.EVENT_STATE_CHANGED,attached);
        attachedBroker.registerListener("String_Node_Str",this);
      }
    }
 else {
synchronized (commandProgress) {
        onAdminCommandEvent(AdminCommandStateImpl.EVENT_STATE_CHANGED,attached);
        onAdminCommandEvent(CommandProgress.EVENT_PROGRESSSTATUS_STATE,attached.getCommandProgress());
        attachedBroker.registerListener("String_Node_Str",this);
      }
    }
synchronized (attached) {
      while (attached.getState().equals(PREPARED) || attached.getState().equals(RUNNING)) {
        try {
          attached.wait(1000 * 60 * 5);
        }
 catch (        InterruptedException ex) {
        }
      }
      if (attached.getState().equals(COMPLETED)) {
        String commandUser=SubjectUtil.getUsernamesFromSubject(attached.getSubject()).get(0);
        if ((commandUser != null && commandUser.equals(attachedUser)) && attached.isOutboundPayloadEmpty()) {
          purgeJob(attached.getId());
        }
        ar.setActionExitCode(attached.getActionReport().getActionExitCode());
        ar.appendMessage(strings.getLocalString("String_Node_Str","String_Node_Str",attached.getName(),attached.getActionReport().getActionExitCode()));
      }
    }
  }
 else {
    if (jobInfo != null && jobInfo.state.equals(COMPLETED.toString())) {
      if (attachedUser != null && attachedUser.equals(jobInfo.user)) {
        purgeJob(jobInfo.jobId);
      }
      ar.setActionExitCode(ActionReport.ExitCode.SUCCESS);
      ar.appendMessage(strings.getLocalString("String_Node_Str","String_Node_Str",jobName,jobInfo.exitCode));
    }
  }
}