Program: 97073
Project: 97073
Buggy source:
public static void cleanupBranchTest(IOseeBranch branch) throws Exception {
  String namespace="String_Node_Str" + branch.getName().toLowerCase();
  Artifact aArt=ArtifactQuery.checkArtifactFromTypeAndName(AtsArtifactTypes.Action,branch.getName() + "String_Node_Str",AtsUtilCore.getAtsBranch());
  if (aArt != null) {
    SkynetTransaction transaction=TransactionManager.createTransaction(AtsUtilCore.getAtsBranch(),"String_Node_Str");
    for (    TeamWorkFlowArtifact teamArt : ActionManager.getTeams(aArt)) {
      SMAEditor.close(Collections.singleton(teamArt),false);
      teamArt.deleteAndPersist(transaction,true);
    }
    aArt.deleteAndPersist(transaction,true);
    transaction.execute();
  }
  SkynetTransaction transaction=TransactionManager.createTransaction(AtsUtilCore.getAtsBranch(),"String_Node_Str");
  for (  IAtsVersion version : AtsClientService.get().getConfig().get(IAtsVersion.class)) {
    if (version.getName().contains(branch.getName())) {
      Artifact artifact=AtsClientService.get().getConfigArtifact(version);
      if (artifact != null) {
        artifact.deleteAndPersist(transaction);
      }
    }
    AtsClientService.get().getConfig().invalidate(version);
  }
  transaction.execute();
  transaction=TransactionManager.createTransaction(AtsUtilCore.getAtsBranch(),"String_Node_Str");
  for (  Artifact teamDefArt : ArtifactQuery.getArtifactListFromTypeAndName(AtsArtifactTypes.TeamDefinition,branch.getName(),AtsUtilCore.getAtsBranch())) {
    teamDefArt.deleteAndPersist(transaction,false);
    AtsClientService.get().getConfig().invalidate(AtsClientService.get().getConfig().getSoleByUuid(teamDefArt.getUuid(),IAtsTeamDefinition.class));
  }
  transaction.execute();
  transaction=TransactionManager.createTransaction(AtsUtilCore.getAtsBranch(),"String_Node_Str");
  for (  Artifact aiaArt : ArtifactQuery.getArtifactListFromTypeAndName(AtsArtifactTypes.ActionableItem,branch.getName(),AtsUtilCore.getAtsBranch())) {
    for (    Artifact childArt : aiaArt.getChildren()) {
      childArt.deleteAndPersist(transaction,false);
      AtsClientService.get().getConfig().invalidate(AtsClientService.get().getConfig().getSoleByUuid(childArt.getUuid(),IAtsActionableItem.class));
    }
    aiaArt.deleteAndPersist(transaction,false);
    AtsClientService.get().getConfig().invalidate(AtsClientService.get().getConfig().getSoleByUuid(aiaArt.getUuid(),IAtsActionableItem.class));
    transaction.execute();
  }
  Collection<Artifact> arts=ArtifactQuery.getArtifactListFromType(AtsArtifactTypes.WorkDefinition,AtsUtilCore.getAtsBranch());
  if (arts.size() > 0) {
    transaction=TransactionManager.createTransaction(AtsUtilCore.getAtsBranch(),"String_Node_Str");
    for (    Artifact workArt : arts) {
      if (workArt.getName().startsWith(namespace)) {
        workArt.deleteAndPersist(transaction,true);
      }
    }
    transaction.execute();
  }
  try {
    BranchManager.refreshBranches();
    for (    Branch workingBranch : BranchManager.getBranches(BranchArchivedState.ALL,BranchType.WORKING)) {
      if (workingBranch.getName().contains(branch.getName())) {
        BranchManager.purgeBranch(workingBranch);
        TestUtil.sleep(2000);
      }
    }
    if (BranchManager.branchExists(branch)) {
      BranchManager.purgeBranch(branch);
    }
    TestUtil.sleep(2000);
  }
 catch (  BranchDoesNotExist ex) {
  }
}

Fixed version (ground truth):
public static void cleanupBranchTest(IOseeBranch branch) throws Exception {
  String namespace="String_Node_Str" + branch.getName().toLowerCase();
  Artifact aArt=ArtifactQuery.checkArtifactFromTypeAndName(AtsArtifactTypes.Action,branch.getName() + "String_Node_Str",AtsUtilCore.getAtsBranch());
  if (aArt != null) {
    SkynetTransaction transaction=TransactionManager.createTransaction(AtsUtilCore.getAtsBranch(),"String_Node_Str");
    for (    TeamWorkFlowArtifact teamArt : ActionManager.getTeams(aArt)) {
      SMAEditor.close(Collections.singleton(teamArt),false);
      teamArt.deleteAndPersist(transaction,true);
    }
    aArt.deleteAndPersist(transaction,true);
    transaction.execute();
  }
  SkynetTransaction transaction=TransactionManager.createTransaction(AtsUtilCore.getAtsBranch(),"String_Node_Str");
  for (  IAtsVersion version : AtsClientService.get().getConfig().get(IAtsVersion.class)) {
    if (version.getName().contains(branch.getName())) {
      Artifact artifact=AtsClientService.get().getConfigArtifact(version);
      if (artifact != null) {
        artifact.deleteAndPersist(transaction);
      }
    }
    AtsClientService.get().getConfig().invalidate(version);
  }
  transaction.execute();
  transaction=TransactionManager.createTransaction(AtsUtilCore.getAtsBranch(),"String_Node_Str");
  for (  Artifact teamDefArt : ArtifactQuery.getArtifactListFromTypeAndName(AtsArtifactTypes.TeamDefinition,branch.getName(),AtsUtilCore.getAtsBranch())) {
    teamDefArt.deleteAndPersist(transaction,false);
    IAtsTeamDefinition soleByUuid=AtsClientService.get().getConfig().getSoleByUuid(teamDefArt.getUuid(),IAtsTeamDefinition.class);
    if (soleByUuid != null) {
      AtsClientService.get().getConfig().invalidate(soleByUuid);
    }
  }
  transaction.execute();
  transaction=TransactionManager.createTransaction(AtsUtilCore.getAtsBranch(),"String_Node_Str");
  for (  Artifact aiaArt : ArtifactQuery.getArtifactListFromTypeAndName(AtsArtifactTypes.ActionableItem,branch.getName(),AtsUtilCore.getAtsBranch())) {
    for (    Artifact childArt : aiaArt.getChildren()) {
      childArt.deleteAndPersist(transaction,false);
      IAtsActionableItem soleByUuid=AtsClientService.get().getConfig().getSoleByUuid(childArt.getUuid(),IAtsActionableItem.class);
      if (soleByUuid != null) {
        AtsClientService.get().getConfig().invalidate(soleByUuid);
      }
    }
    aiaArt.deleteAndPersist(transaction,false);
    AtsClientService.get().getConfig().invalidate(AtsClientService.get().getConfig().getSoleByUuid(aiaArt.getUuid(),IAtsActionableItem.class));
    transaction.execute();
  }
  Collection<Artifact> arts=ArtifactQuery.getArtifactListFromType(AtsArtifactTypes.WorkDefinition,AtsUtilCore.getAtsBranch());
  if (arts.size() > 0) {
    transaction=TransactionManager.createTransaction(AtsUtilCore.getAtsBranch(),"String_Node_Str");
    for (    Artifact workArt : arts) {
      if (workArt.getName().startsWith(namespace)) {
        workArt.deleteAndPersist(transaction,true);
      }
    }
    transaction.execute();
  }
  try {
    BranchManager.refreshBranches();
    for (    Branch workingBranch : BranchManager.getBranches(BranchArchivedState.ALL,BranchType.WORKING)) {
      if (workingBranch.getName().contains(branch.getName())) {
        BranchManager.purgeBranch(workingBranch);
        TestUtil.sleep(2000);
      }
    }
    if (BranchManager.branchExists(branch)) {
      BranchManager.purgeBranch(branch);
    }
    TestUtil.sleep(2000);
  }
 catch (  BranchDoesNotExist ex) {
  }
}