Program: 96871
Project: 96871
Buggy source:
private WordUpdateChange wordArtifactUpdate(WordUpdateData data,Collection<WordExtractorData> extractorDatas,Element oleDataElement){
  List<String> deletedArtifacts=Lists.newArrayList();
  WordUpdateChange updateChange=new WordUpdateChange();
  try {
    TransactionFactory txFactory=orcsApi.getTransactionFactory();
    boolean singleArtifact=extractorDatas.size() == 1;
    boolean containsOleData=false;
    boolean containsWordData=false;
    ArtifactReadable userArtifact=getArtifact(COMMON_ID,data.getUserArtId());
    TransactionBuilder txBuilder=txFactory.createTransaction(data.getBranch(),userArtifact,data.getComment());
    for (    WordExtractorData extractorData : extractorDatas) {
      ArtifactReadable artifact=getArtifact(data.getBranch(),extractorData.getGuid());
      WordArtifactChange artChange=new WordArtifactChange();
      artChange.setArtId(artifact.getLocalId());
      if (artifact.isDeleted()) {
        deletedArtifacts.add(artifact.getName());
      }
 else {
        containsOleData=artifact.getAttributeCount(CoreAttributeTypes.WordOleData) > 0;
        containsWordData=artifact.getAttributeCount(CoreAttributeTypes.WordTemplateContent) > 0;
        if (oleDataElement == null && containsOleData) {
          txBuilder.setSoleAttributeFromString(artifact,CoreAttributeTypes.WordOleData,"String_Node_Str");
          artChange.setChanged(true);
          artChange.addChangedAttrType(CoreAttributeTypes.WordOleData.getGuid());
        }
 else         if (oleDataElement != null && singleArtifact) {
          txBuilder.setSoleAttributeFromStream(artifact,CoreAttributeTypes.WordOleData,new ByteArrayInputStream(WordUtilities.getFormattedContent(oleDataElement)));
          artChange.setChanged(true);
          if (!containsOleData) {
            artChange.setCreated(true);
          }
          artChange.addChangedAttrType(CoreAttributeTypes.WordOleData.getGuid());
        }
        String content=Lib.inputStreamToString(new ByteArrayInputStream(WordUtilities.getFormattedContent(extractorData.getParentEelement())));
        boolean hasTrackedChanges=WordCoreUtil.containsWordAnnotations(content);
        boolean multiSave=data.isMultiEdit() || hasChangedContent(artifact,content);
        if (!hasTrackedChanges && (singleArtifact || multiSave)) {
          if (extractorData.getParentEelement().getNodeName().endsWith("String_Node_Str")) {
            content=content.replace(WordUtilities.LISTNUM_FIELD_HEAD,"String_Node_Str");
          }
          LinkType linkType=LinkType.OSEE_SERVER_LINK;
          content=WordMlLinkHandler.unlink(queryFactory,linkType,artifact,content);
          txBuilder.setSoleAttributeValue(artifact,CoreAttributeTypes.WordTemplateContent,content);
          artChange.setChanged(true);
          if (!containsWordData) {
            artChange.setCreated(true);
          }
          artChange.addChangedAttrType(CoreAttributeTypes.WordTemplateContent.getGuid());
        }
 else {
          updateChange.setTrackedChangeArts(artifact.getId(),artifact.getName());
        }
        if (artChange.isChanged()) {
          artChange.setSafetyRelated(checkIfSafetyRelated(artifact,CoreAttributeTypes.LegacyDAL) || checkIfSafetyRelated(artifact,CoreAttributeTypes.ItemDAL));
          updateChange.addChangedArt(artChange);
          artChange.addChangedAttrType(CoreAttributeTypes.WordTemplateContent.getGuid());
        }
      }
    }
    TransactionReadable tx=txBuilder.commit();
    if (tx != null) {
      postProcessChange(tx,updateChange,userArtifact);
    }
  }
 catch (  Exception ex) {
    throw OseeCoreException.wrap(ex);
  }
 finally {
    if (!deletedArtifacts.isEmpty()) {
      throw new OseeStateException("String_Node_Str",Collections.toString("String_Node_Str",deletedArtifacts));
    }
  }
  return updateChange;
}

Fixed version (ground truth):
private WordUpdateChange wordArtifactUpdate(WordUpdateData data,Collection<WordExtractorData> extractorDatas,Element oleDataElement){
  List<String> deletedArtifacts=Lists.newArrayList();
  WordUpdateChange updateChange=new WordUpdateChange();
  try {
    TransactionFactory txFactory=orcsApi.getTransactionFactory();
    boolean singleArtifact=extractorDatas.size() == 1;
    boolean containsOleData=false;
    boolean containsWordData=false;
    ArtifactReadable userArtifact=getArtifact(COMMON_ID,data.getUserArtId());
    TransactionBuilder txBuilder=txFactory.createTransaction(data.getBranch(),userArtifact,data.getComment());
    for (    WordExtractorData extractorData : extractorDatas) {
      ArtifactReadable artifact=getArtifact(data.getBranch(),extractorData.getGuid());
      WordArtifactChange artChange=new WordArtifactChange();
      artChange.setArtId(artifact.getLocalId());
      if (artifact.isDeleted()) {
        deletedArtifacts.add(artifact.getName());
      }
 else {
        containsOleData=artifact.getAttributeCount(CoreAttributeTypes.WordOleData) > 0;
        containsWordData=artifact.getAttributeCount(CoreAttributeTypes.WordTemplateContent) > 0;
        if (oleDataElement == null && containsOleData) {
          txBuilder.setSoleAttributeFromString(artifact,CoreAttributeTypes.WordOleData,"String_Node_Str");
          artChange.setChanged(true);
          artChange.addChangedAttrType(CoreAttributeTypes.WordOleData.getGuid());
        }
 else         if (oleDataElement != null && singleArtifact) {
          txBuilder.setSoleAttributeFromStream(artifact,CoreAttributeTypes.WordOleData,new ByteArrayInputStream(WordUtilities.getFormattedContent(oleDataElement)));
          artChange.setChanged(true);
          if (!containsOleData) {
            artChange.setCreated(true);
          }
          artChange.addChangedAttrType(CoreAttributeTypes.WordOleData.getGuid());
        }
        String content=Lib.inputStreamToString(new ByteArrayInputStream(WordUtilities.getFormattedContent(extractorData.getParentEelement())));
        boolean hasTrackedChanges=WordCoreUtil.containsWordAnnotations(content);
        boolean multiSave=data.isMultiEdit() || hasChangedContent(artifact,content);
        if (singleArtifact || multiSave) {
          if (!hasTrackedChanges) {
            if (extractorData.getParentEelement().getNodeName().endsWith("String_Node_Str")) {
              content=content.replace(WordUtilities.LISTNUM_FIELD_HEAD,"String_Node_Str");
            }
            LinkType linkType=LinkType.OSEE_SERVER_LINK;
            content=WordMlLinkHandler.unlink(queryFactory,linkType,artifact,content);
            txBuilder.setSoleAttributeValue(artifact,CoreAttributeTypes.WordTemplateContent,content);
            artChange.setChanged(true);
            if (!containsWordData) {
              artChange.setCreated(true);
            }
            artChange.addChangedAttrType(CoreAttributeTypes.WordTemplateContent.getGuid());
          }
 else {
            updateChange.setTrackedChangeArts(artifact.getId(),artifact.getName());
          }
        }
        if (artChange.isChanged()) {
          artChange.setSafetyRelated(checkIfSafetyRelated(artifact,CoreAttributeTypes.LegacyDAL) || checkIfSafetyRelated(artifact,CoreAttributeTypes.ItemDAL));
          updateChange.addChangedArt(artChange);
          artChange.addChangedAttrType(CoreAttributeTypes.WordTemplateContent.getGuid());
        }
      }
    }
    TransactionReadable tx=txBuilder.commit();
    if (tx != null) {
      postProcessChange(tx,updateChange,userArtifact);
    }
  }
 catch (  Exception ex) {
    throw OseeCoreException.wrap(ex);
  }
 finally {
    if (!deletedArtifacts.isEmpty()) {
      throw new OseeStateException("String_Node_Str",Collections.toString("String_Node_Str",deletedArtifacts));
    }
  }
  return updateChange;
}