Program: 97470
Project: 97470
Buggy source:
public static void testCompletedCancelledStateAttributesSet(Collection<Artifact> artifacts,SkynetTransaction transaction,HashCollection<String,String> testNameToResultsMap,CountingMap<String> testNameToTimeSpentMap){
  Date date=new Date();
  for (  Artifact artifact : artifacts) {
    try {
      if (artifact instanceof AbstractWorkflowArtifact) {
        AbstractWorkflowArtifact awa=(AbstractWorkflowArtifact)artifact;
        if (awa.isCompleted()) {
          IAtsStateDefinition stateDef=awa.getStateDefinition();
          if (stateDef.getStateType() != StateType.Completed) {
            testNameToResultsMap.put("String_Node_Str",String.format("String_Node_Str",stateDef.getName(),XResultDataUI.getHyperlink(artifact)));
            if (stateDef.getStateType() == StateType.Working) {
              awa.setSoleAttributeFromString(AtsAttributeTypes.CurrentStateType,StateType.Working.name());
              TransitionManager.logWorkflowUnCompletedEvent(awa);
              TransitionManager.logWorkflowUnCancelledEvent(awa);
              awa.persist(transaction);
              testNameToResultsMap.put("String_Node_Str","String_Node_Str");
            }
 else {
              testNameToResultsMap.put("String_Node_Str","String_Node_Str");
            }
          }
 else           if (awa.getCompletedBy() == null || awa.getCompletedDate() == null || !Strings.isValid(awa.getCompletedFromState())) {
            testNameToResultsMap.put("String_Node_Str",String.format("String_Node_Str",awa.getArtifactTypeName(),XResultDataUI.getHyperlink(artifact)));
            fixCompletedByAttributes(transaction,awa,testNameToResultsMap);
          }
        }
        if (awa.isCancelled()) {
          IAtsStateDefinition stateDef=awa.getStateDefinition();
          if (stateDef.getStateType() != StateType.Cancelled) {
            testNameToResultsMap.put("String_Node_Str",String.format("String_Node_Str",stateDef.getName(),XResultDataUI.getHyperlink(artifact)));
            testNameToResultsMap.put("String_Node_Str","String_Node_Str");
          }
 else           if (awa.getCancelledBy() == null || awa.getCancelledDate() == null || !Strings.isValid(awa.getCancelledFromState())) {
            testNameToResultsMap.put("String_Node_Str",String.format("String_Node_Str",XResultDataUI.getHyperlink(artifact)));
            fixCancelledByAttributes(transaction,awa,testNameToResultsMap);
          }
        }
      }
    }
 catch (    Exception ex) {
      testNameToResultsMap.put("String_Node_Str","String_Node_Str" + artifact.toStringWithId() + "String_Node_Str"+ ex.getLocalizedMessage());
    }
  }
  logTestTimeSpent(date,"String_Node_Str",testNameToTimeSpentMap);
}

Fixed version (ground truth):
public static void testCompletedCancelledStateAttributesSet(Collection<Artifact> artifacts,SkynetTransaction transaction,HashCollection<String,String> testNameToResultsMap,CountingMap<String> testNameToTimeSpentMap){
  Date date=new Date();
  for (  Artifact artifact : artifacts) {
    try {
      if (artifact instanceof AbstractWorkflowArtifact) {
        AbstractWorkflowArtifact awa=(AbstractWorkflowArtifact)artifact;
        if (awa.isCompleted()) {
          IAtsStateDefinition stateDef=awa.getStateDefinition();
          if (stateDef.getStateType() != StateType.Completed) {
            testNameToResultsMap.put("String_Node_Str",String.format("String_Node_Str",stateDef.getName(),XResultDataUI.getHyperlink(artifact)));
            if (stateDef.getStateType() == StateType.Working) {
              awa.setSoleAttributeFromString(AtsAttributeTypes.CurrentStateType,StateType.Working.name());
              TransitionManager.logWorkflowUnCompletedEvent(awa,stateDef);
              TransitionManager.logWorkflowUnCancelledEvent(awa,stateDef);
              awa.persist(transaction);
              testNameToResultsMap.put("String_Node_Str","String_Node_Str");
            }
 else {
              testNameToResultsMap.put("String_Node_Str","String_Node_Str");
            }
          }
 else           if (awa.getCompletedBy() == null || awa.getCompletedDate() == null || !Strings.isValid(awa.getCompletedFromState())) {
            testNameToResultsMap.put("String_Node_Str",String.format("String_Node_Str",awa.getArtifactTypeName(),XResultDataUI.getHyperlink(artifact)));
            fixCompletedByAttributes(transaction,awa,testNameToResultsMap);
          }
        }
        if (awa.isCancelled()) {
          IAtsStateDefinition stateDef=awa.getStateDefinition();
          if (stateDef.getStateType() != StateType.Cancelled) {
            testNameToResultsMap.put("String_Node_Str",String.format("String_Node_Str",stateDef.getName(),XResultDataUI.getHyperlink(artifact)));
            testNameToResultsMap.put("String_Node_Str","String_Node_Str");
          }
 else           if (awa.getCancelledBy() == null || awa.getCancelledDate() == null || !Strings.isValid(awa.getCancelledFromState())) {
            testNameToResultsMap.put("String_Node_Str",String.format("String_Node_Str",XResultDataUI.getHyperlink(artifact)));
            fixCancelledByAttributes(transaction,awa,testNameToResultsMap);
          }
        }
      }
    }
 catch (    Exception ex) {
      testNameToResultsMap.put("String_Node_Str","String_Node_Str" + artifact.toStringWithId() + "String_Node_Str"+ ex.getLocalizedMessage());
    }
  }
  logTestTimeSpent(date,"String_Node_Str",testNameToTimeSpentMap);
}