Program: 97602
Project: 97602
Buggy source:
@Override public Result saveToArtifact(SkynetTransaction transaction) throws OseeCoreException {
  Artifact teamDefArt=getArtifact();
  if (teamDefArt == null) {
    throw new OseeArgumentException("String_Node_Str");
  }
  IAtsTeamDefinition teamDef=getTeamDefinition();
  teamDefArt.setName(teamDef.getName());
  teamDefArt.setSoleAttributeValue(AtsAttributeTypes.Active,teamDef.isActive());
  boolean actionable=teamDefArt.getSoleAttributeValue(AtsAttributeTypes.Actionable,true);
  if (actionable != teamDef.isActionable()) {
    teamDefArt.setSoleAttributeValue(AtsAttributeTypes.Actionable,teamDef.isActionable());
  }
  teamDefArt.setSoleAttributeValue(AtsAttributeTypes.TeamUsesVersions,teamDef.isTeamUsesVersions());
  boolean allowCommitBranch=teamDefArt.getSoleAttributeValue(AtsAttributeTypes.AllowCreateBranch,true);
  if (allowCommitBranch != teamDef.isAllowCommitBranch()) {
    teamDefArt.setSoleAttributeValue(AtsAttributeTypes.AllowCommitBranch,teamDef.isAllowCommitBranch());
  }
  boolean allowCreateBranch=teamDefArt.getSoleAttributeValue(AtsAttributeTypes.AllowCreateBranch,true);
  if (allowCreateBranch != teamDef.isAllowCreateBranch()) {
    teamDefArt.setSoleAttributeValue(AtsAttributeTypes.AllowCreateBranch,teamDef.isAllowCreateBranch());
  }
  if (Strings.isValid(teamDef.getBaslineBranchGuid())) {
    teamDefArt.setSoleAttributeValue(AtsAttributeTypes.BaselineBranchGuid,teamDef.getBaslineBranchGuid());
  }
  if (Strings.isValid(teamDef.getWorkflowDefinition())) {
    teamDefArt.setSoleAttributeValue(AtsAttributeTypes.WorkflowDefinition,teamDef.getWorkflowDefinition());
  }
  if (Strings.isValid(teamDef.getRelatedTaskWorkDefinition())) {
    teamDefArt.setSoleAttributeValue(AtsAttributeTypes.RelatedTaskWorkDefinition,teamDef.getRelatedTaskWorkDefinition());
  }
  if (Strings.isValid(teamDef.getDescription())) {
    teamDefArt.setSoleAttributeValue(AtsAttributeTypes.Description,teamDef.getDescription());
  }
  if (Strings.isValid(teamDef.getFullName())) {
    teamDefArt.setSoleAttributeValue(AtsAttributeTypes.FullName,teamDef.getFullName());
  }
  for (  IAtsActionableItem aia : teamDef.getActionableItems()) {
    Artifact aiaArt=new ActionableItemArtifactStore(aia).getArtifact();
    if (aiaArt != null && aiaArt.getRelatedArtifact(AtsRelationTypes.TeamActionableItem_Team) != null) {
      aiaArt.addRelation(AtsRelationTypes.TeamActionableItem_Team,teamDefArt);
    }
  }
  List<String> newGuids=AtsObjects.toGuids(teamDef.getChildrenTeamDefinitions());
  List<String> currGuids=Artifacts.toGuids(teamDefArt.getChildren());
  for (  Artifact child : teamDefArt.getChildren()) {
    if (child.isOfType(AtsArtifactTypes.TeamDefinition)) {
      if (newGuids.contains(child.getGuid())) {
        teamDefArt.deleteRelation(CoreRelationTypes.Default_Hierarchical__Child,child);
      }
    }
  }
  for (  String newGuid : newGuids) {
    if (!currGuids.contains(newGuid)) {
      Artifact newArt=null;
      IAtsTeamDefinition newTeamDef=AtsConfigCache.getSoleByGuid(newGuid,IAtsTeamDefinition.class);
      if (newTeamDef != null) {
        newArt=AtsObjectsClient.getSoleArtifact(newTeamDef);
      }
      if (newArt == null) {
        newArt=ArtifactCache.getActive(newGuid,AtsUtilCore.getAtsBranchToken());
      }
      teamDefArt.addRelation(CoreRelationTypes.Default_Hierarchical__Child,newArt);
    }
  }
  setRelationsOfType(teamDefArt,teamDef.getVersions(),AtsRelationTypes.TeamDefinitionToVersion_Version);
  setRelationsOfType(teamDefArt,teamDef.getSubscribed(),AtsRelationTypes.SubscribedUser_User);
  setRelationsOfType(teamDefArt,teamDef.getLeads(),AtsRelationTypes.TeamLead_Lead);
  setRelationsOfType(teamDefArt,teamDef.getMembers(),AtsRelationTypes.TeamMember_Member);
  setRelationsOfType(teamDefArt,teamDef.getPrivilegedMembers(),AtsRelationTypes.PrivilegedMember_Member);
  teamDefArt.setAttributeValues(AtsAttributeTypes.RuleDefinition,teamDef.getRules());
  if (!teamDef.getStaticIds().isEmpty()) {
    teamDefArt.setAttributeValues(CoreAttributeTypes.StaticId,teamDef.getStaticIds());
  }
  if (teamDef.getParentTeamDef() == null && !teamDef.getGuid().equals(TeamDefinitions.getTopTeamDefinition().getGuid())) {
    Artifact topTeamDefArt=AtsObjectsClient.getSoleArtifact(TeamDefinitions.getTopTeamDefinition());
    topTeamDefArt.addChild(teamDefArt);
    topTeamDefArt.persist(transaction);
  }
 else {
    Artifact parentTeamDefArt=teamDefArt.getParent();
    if (parentTeamDefArt != null) {
      if (parentTeamDefArt.isOfType(AtsArtifactTypes.TeamDefinition)) {
        if (!parentTeamDefArt.getGuid().equals(teamDef.getParentTeamDef().getGuid())) {
          Artifact newParentTeamDefArt=AtsObjectsClient.getSoleArtifact(teamDef);
          newParentTeamDefArt.addChild(teamDefArt);
          newParentTeamDefArt.persist(transaction);
          parentTeamDefArt.persist(transaction);
        }
      }
    }
  }
  teamDefArt.persist(transaction);
  return Result.TrueResult;
}

Fixed version (ground truth):
@Override public Result saveToArtifact(SkynetTransaction transaction) throws OseeCoreException {
  Artifact teamDefArt=getArtifact();
  if (teamDefArt == null) {
    throw new OseeArgumentException("String_Node_Str");
  }
  IAtsTeamDefinition teamDef=getTeamDefinition();
  teamDefArt.setName(teamDef.getName());
  teamDefArt.setSoleAttributeValue(AtsAttributeTypes.Active,teamDef.isActive());
  boolean actionable=teamDefArt.getSoleAttributeValue(AtsAttributeTypes.Actionable,false);
  if (actionable != teamDef.isActionable()) {
    teamDefArt.setSoleAttributeValue(AtsAttributeTypes.Actionable,teamDef.isActionable());
  }
  teamDefArt.setSoleAttributeValue(AtsAttributeTypes.TeamUsesVersions,teamDef.isTeamUsesVersions());
  boolean allowCommitBranch=teamDefArt.getSoleAttributeValue(AtsAttributeTypes.AllowCreateBranch,false);
  if (allowCommitBranch != teamDef.isAllowCommitBranch()) {
    teamDefArt.setSoleAttributeValue(AtsAttributeTypes.AllowCommitBranch,teamDef.isAllowCommitBranch());
  }
  boolean allowCreateBranch=teamDefArt.getSoleAttributeValue(AtsAttributeTypes.AllowCreateBranch,false);
  if (allowCreateBranch != teamDef.isAllowCreateBranch()) {
    teamDefArt.setSoleAttributeValue(AtsAttributeTypes.AllowCreateBranch,teamDef.isAllowCreateBranch());
  }
  if (Strings.isValid(teamDef.getBaslineBranchGuid())) {
    teamDefArt.setSoleAttributeValue(AtsAttributeTypes.BaselineBranchGuid,teamDef.getBaslineBranchGuid());
  }
  if (Strings.isValid(teamDef.getWorkflowDefinition())) {
    teamDefArt.setSoleAttributeValue(AtsAttributeTypes.WorkflowDefinition,teamDef.getWorkflowDefinition());
  }
  if (Strings.isValid(teamDef.getRelatedTaskWorkDefinition())) {
    teamDefArt.setSoleAttributeValue(AtsAttributeTypes.RelatedTaskWorkDefinition,teamDef.getRelatedTaskWorkDefinition());
  }
  if (Strings.isValid(teamDef.getDescription())) {
    teamDefArt.setSoleAttributeValue(AtsAttributeTypes.Description,teamDef.getDescription());
  }
  if (Strings.isValid(teamDef.getFullName())) {
    teamDefArt.setSoleAttributeValue(AtsAttributeTypes.FullName,teamDef.getFullName());
  }
  for (  IAtsActionableItem aia : teamDef.getActionableItems()) {
    Artifact aiaArt=new ActionableItemArtifactStore(aia).getArtifact();
    if (aiaArt != null && aiaArt.getRelatedArtifact(AtsRelationTypes.TeamActionableItem_Team) != null) {
      aiaArt.addRelation(AtsRelationTypes.TeamActionableItem_Team,teamDefArt);
    }
  }
  List<String> newGuids=AtsObjects.toGuids(teamDef.getChildrenTeamDefinitions());
  List<String> currGuids=Artifacts.toGuids(teamDefArt.getChildren());
  for (  Artifact child : teamDefArt.getChildren()) {
    if (child.isOfType(AtsArtifactTypes.TeamDefinition)) {
      if (newGuids.contains(child.getGuid())) {
        teamDefArt.deleteRelation(CoreRelationTypes.Default_Hierarchical__Child,child);
      }
    }
  }
  for (  String newGuid : newGuids) {
    if (!currGuids.contains(newGuid)) {
      Artifact newArt=null;
      IAtsTeamDefinition newTeamDef=AtsConfigCache.getSoleByGuid(newGuid,IAtsTeamDefinition.class);
      if (newTeamDef != null) {
        newArt=AtsObjectsClient.getSoleArtifact(newTeamDef);
      }
      if (newArt == null) {
        newArt=ArtifactCache.getActive(newGuid,AtsUtilCore.getAtsBranchToken());
      }
      teamDefArt.addRelation(CoreRelationTypes.Default_Hierarchical__Child,newArt);
    }
  }
  setRelationsOfType(teamDefArt,teamDef.getVersions(),AtsRelationTypes.TeamDefinitionToVersion_Version);
  setRelationsOfType(teamDefArt,teamDef.getSubscribed(),AtsRelationTypes.SubscribedUser_User);
  setRelationsOfType(teamDefArt,teamDef.getLeads(),AtsRelationTypes.TeamLead_Lead);
  setRelationsOfType(teamDefArt,teamDef.getMembers(),AtsRelationTypes.TeamMember_Member);
  setRelationsOfType(teamDefArt,teamDef.getPrivilegedMembers(),AtsRelationTypes.PrivilegedMember_Member);
  teamDefArt.setAttributeValues(AtsAttributeTypes.RuleDefinition,teamDef.getRules());
  if (!teamDef.getStaticIds().isEmpty()) {
    teamDefArt.setAttributeValues(CoreAttributeTypes.StaticId,teamDef.getStaticIds());
  }
  if (teamDef.getParentTeamDef() == null && !teamDef.getGuid().equals(TeamDefinitions.getTopTeamDefinition().getGuid())) {
    Artifact topTeamDefArt=AtsObjectsClient.getSoleArtifact(TeamDefinitions.getTopTeamDefinition());
    topTeamDefArt.addChild(teamDefArt);
    topTeamDefArt.persist(transaction);
  }
 else {
    Artifact parentTeamDefArt=teamDefArt.getParent();
    if (parentTeamDefArt != null) {
      if (parentTeamDefArt.isOfType(AtsArtifactTypes.TeamDefinition)) {
        if (!parentTeamDefArt.getGuid().equals(teamDef.getParentTeamDef().getGuid())) {
          Artifact newParentTeamDefArt=AtsObjectsClient.getSoleArtifact(teamDef);
          newParentTeamDefArt.addChild(teamDefArt);
          newParentTeamDefArt.persist(transaction);
          parentTeamDefArt.persist(transaction);
        }
      }
    }
  }
  teamDefArt.persist(transaction);
  return Result.TrueResult;
}