Program: 24085
Project: 24085
Buggy source:
private void updateFromDefinition(ElementDefinition dest,ElementDefinition source,String pn,ProfileKnowledgeProvider pkp,boolean trimDifferential) throws Exception {
  ElementDefinition base=dest;
  ElementDefinition derived=source;
  if (derived != null) {
    boolean isExtension=base.getPath().equals("String_Node_Str") || base.getPath().endsWith("String_Node_Str") || base.getPath().endsWith("String_Node_Str");
    if (isExtension) {
      base.setDefinition("String_Node_Str");
      base.setShort("String_Node_Str");
      base.setCommentsElement(null);
      base.setRequirementsElement(null);
      base.getAlias().clear();
      base.getMapping().clear();
    }
    if (derived.hasShortElement()) {
      if (!Base.compareDeep(derived.getShortElement(),base.getShortElement(),false))       base.setShortElement(derived.getShortElement().copy());
 else       if (trimDifferential)       derived.setShortElement(null);
 else       if (derived.hasShortElement())       derived.getShortElement().setUserData(DERIVATION_EQUALS,true);
    }
    if (derived.hasDefinitionElement()) {
      if (derived.getDefinition().startsWith("String_Node_Str"))       base.setDefinition(base.getDefinition() + "String_Node_Str" + derived.getDefinition().substring(3));
 else       if (!Base.compareDeep(derived.getDefinitionElement(),base.getDefinitionElement(),false))       base.setDefinitionElement(derived.getDefinitionElement().copy());
 else       if (trimDifferential)       derived.setDefinitionElement(null);
 else       if (derived.hasDefinitionElement())       derived.getDefinitionElement().setUserData(DERIVATION_EQUALS,true);
    }
    if (derived.hasCommentsElement()) {
      if (derived.getComments().startsWith("String_Node_Str"))       base.setComments(base.getComments() + "String_Node_Str" + derived.getComments().substring(3));
 else       if (!Base.compareDeep(derived.getCommentsElement(),base.getCommentsElement(),false))       derived.setCommentsElement(null);
 else       if (trimDifferential)       base.setCommentsElement(derived.getCommentsElement().copy());
 else       if (derived.hasCommentsElement())       derived.getCommentsElement().setUserData(DERIVATION_EQUALS,true);
    }
    if (derived.hasRequirementsElement()) {
      if (derived.getRequirements().startsWith("String_Node_Str"))       base.setRequirements(base.getRequirements() + "String_Node_Str" + derived.getRequirements().substring(3));
 else       if (!Base.compareDeep(derived.getRequirementsElement(),base.getRequirementsElement(),false))       derived.setRequirementsElement(null);
 else       if (trimDifferential)       base.setRequirementsElement(derived.getRequirementsElement().copy());
 else       if (derived.hasRequirementsElement())       derived.getRequirementsElement().setUserData(DERIVATION_EQUALS,true);
    }
    if (derived.hasAlias()) {
      if (!Base.compareDeep(derived.getAlias(),base.getAlias(),false))       for (      StringType s : derived.getAlias()) {
        if (!base.hasAlias(s.getValue()))         base.getAlias().add(s.copy());
      }
 else       if (trimDifferential)       derived.getAlias().clear();
 else       for (      StringType t : derived.getAlias())       t.setUserData(DERIVATION_EQUALS,true);
    }
    if (derived.hasMinElement()) {
      if (!Base.compareDeep(derived.getMinElement(),base.getMinElement(),false))       base.setMinElement(derived.getMinElement().copy());
 else       if (trimDifferential)       derived.setMinElement(null);
 else       derived.getMinElement().setUserData(DERIVATION_EQUALS,true);
    }
    if (derived.hasMaxElement()) {
      if (!Base.compareDeep(derived.getMaxElement(),base.getMaxElement(),false))       base.setMaxElement(derived.getMaxElement().copy());
 else       if (trimDifferential)       derived.setMaxElement(null);
 else       derived.getMaxElement().setUserData(DERIVATION_EQUALS,true);
    }
    if (derived.hasFixed()) {
      if (!Base.compareDeep(derived.getFixed(),base.getFixed(),true)) {
        base.setFixed(derived.getFixed().copy());
      }
 else       if (trimDifferential)       derived.setFixed(null);
 else       derived.getFixed().setUserData(DERIVATION_EQUALS,true);
    }
    if (derived.hasPattern()) {
      if (!Base.compareDeep(derived.getPattern(),base.getPattern(),false)) {
        base.setPattern(derived.getPattern().copy());
      }
 else       if (trimDifferential)       derived.setPattern(null);
 else       derived.getPattern().setUserData(DERIVATION_EQUALS,true);
    }
    if (derived.hasExample()) {
      if (!Base.compareDeep(derived.getExample(),base.getExample(),false))       base.setExample(derived.getExample().copy());
 else       if (trimDifferential)       derived.setExample(null);
 else       derived.getExample().setUserData(DERIVATION_EQUALS,true);
    }
    if (derived.hasMaxLengthElement()) {
      if (!Base.compareDeep(derived.getMaxLengthElement(),base.getMaxLengthElement(),false))       base.setMaxLengthElement(derived.getMaxLengthElement().copy());
 else       if (trimDifferential)       derived.setMaxLengthElement(null);
 else       derived.getMaxLengthElement().setUserData(DERIVATION_EQUALS,true);
    }
    if (derived.hasMustSupportElement()) {
      if (!Base.compareDeep(derived.getMustSupportElement(),base.getMustSupportElement(),false))       base.setMustSupportElement(derived.getMustSupportElement().copy());
 else       if (trimDifferential)       derived.setMustSupportElement(null);
 else       derived.getMustSupportElement().setUserData(DERIVATION_EQUALS,true);
    }
    if (isExtension) {
      if (!Base.compareDeep(derived.getIsModifierElement(),base.getIsModifierElement(),false))       base.setIsModifierElement(derived.getIsModifierElement().copy());
 else       if (trimDifferential)       derived.setIsModifierElement(null);
 else       derived.getIsModifierElement().setUserData(DERIVATION_EQUALS,true);
    }
    if (derived.hasBinding()) {
      if (!Base.compareDeep(derived.getBinding(),base.getBinding(),false)) {
        if (base.hasBinding() && base.getBinding().getStrength() == BindingStrength.REQUIRED && base.getBinding().getStrength() != BindingStrength.REQUIRED)         throw new Exception("String_Node_Str" + pn + "String_Node_Str"+ derived.getPath()+ "String_Node_Str"+ base.getBinding().getStrength().toCode()+ "String_Node_Str"+ base.getBinding().getStrength().toCode());
        base.setBinding(derived.getBinding().copy());
      }
 else       if (trimDifferential)       derived.setBinding(null);
 else       derived.getBinding().setUserData(DERIVATION_EQUALS,true);
    }
    if (derived.hasIsSummaryElement()) {
      if (!Base.compareDeep(derived.getIsSummaryElement(),base.getIsSummaryElement(),false))       base.setIsSummaryElement(derived.getIsSummaryElement().copy());
 else       if (trimDifferential)       derived.setIsSummaryElement(null);
 else       derived.getIsSummaryElement().setUserData(DERIVATION_EQUALS,true);
    }
    if (derived.hasType()) {
      if (!Base.compareDeep(derived.getType(),base.getType(),false)) {
        if (base.hasType()) {
          for (          TypeRefComponent ts : derived.getType()) {
            boolean ok=false;
            CommaSeparatedStringBuilder b=new CommaSeparatedStringBuilder();
            for (            TypeRefComponent td : base.getType()) {
              b.append(td.getCode());
              if (td.getCode().equals(ts.getCode()) || td.getCode().equals("String_Node_Str") || td.getCode().equals("String_Node_Str")|| td.getCode().equals("String_Node_Str")|| ((td.getCode().equals("String_Node_Str") || (td.getCode().equals("String_Node_Str")) && pkp.isResource(ts.getCode()))))               ok=true;
            }
            if (!ok)             throw new Exception("String_Node_Str" + pn + "String_Node_Str"+ derived.getPath()+ "String_Node_Str"+ ts.getCode()+ "String_Node_Str"+ b.toString());
          }
        }
        base.getType().clear();
        for (        TypeRefComponent t : derived.getType())         base.getType().add(t.copy());
      }
 else       if (trimDifferential)       derived.getType().clear();
 else       for (      TypeRefComponent t : derived.getType())       t.setUserData(DERIVATION_EQUALS,true);
    }
    if (derived.hasMapping()) {
      if (!Base.compareDeep(derived.getMapping(),base.getMapping(),false)) {
        for (        ElementDefinitionMappingComponent s : derived.getMapping()) {
          boolean found=false;
          for (          ElementDefinitionMappingComponent d : base.getMapping()) {
            found=found || (d.getIdentity().equals(s.getIdentity()) && d.getMap().equals(s.getMap()));
          }
          if (!found)           base.getMapping().add(s);
        }
      }
 else       if (trimDifferential)       derived.getMapping().clear();
 else       for (      ElementDefinitionMappingComponent t : derived.getMapping())       t.setUserData(DERIVATION_EQUALS,true);
    }
    if (derived.hasConstraint()) {
      for (      ElementDefinitionConstraintComponent s : derived.getConstraint()) {
        base.getConstraint().add(s);
      }
    }
  }
}

Fixed version (ground truth):
private void updateFromDefinition(ElementDefinition dest,ElementDefinition source,String pn,ProfileKnowledgeProvider pkp,boolean trimDifferential) throws Exception {
  ElementDefinition base=dest;
  ElementDefinition derived=source;
  if (derived != null) {
    boolean isExtension=base.getPath().equals("String_Node_Str") || base.getPath().endsWith("String_Node_Str") || base.getPath().endsWith("String_Node_Str");
    if (isExtension) {
      base.setDefinition("String_Node_Str");
      base.setShort("String_Node_Str");
      base.setCommentsElement(null);
      base.setRequirementsElement(null);
      base.getAlias().clear();
      base.getMapping().clear();
    }
    if (derived.hasShortElement()) {
      if (!Base.compareDeep(derived.getShortElement(),base.getShortElement(),false))       base.setShortElement(derived.getShortElement().copy());
 else       if (trimDifferential)       derived.setShortElement(null);
 else       if (derived.hasShortElement())       derived.getShortElement().setUserData(DERIVATION_EQUALS,true);
    }
    if (derived.hasDefinitionElement()) {
      if (derived.getDefinition().startsWith("String_Node_Str"))       base.setDefinition(base.getDefinition() + "String_Node_Str" + derived.getDefinition().substring(3));
 else       if (!Base.compareDeep(derived.getDefinitionElement(),base.getDefinitionElement(),false))       base.setDefinitionElement(derived.getDefinitionElement().copy());
 else       if (trimDifferential)       derived.setDefinitionElement(null);
 else       if (derived.hasDefinitionElement())       derived.getDefinitionElement().setUserData(DERIVATION_EQUALS,true);
    }
    if (derived.hasCommentsElement()) {
      if (derived.getComments().startsWith("String_Node_Str"))       base.setComments(base.getComments() + "String_Node_Str" + derived.getComments().substring(3));
 else       if (!Base.compareDeep(derived.getCommentsElement(),base.getCommentsElement(),false))       base.setCommentsElement(derived.getCommentsElement().copy());
 else       if (trimDifferential)       base.setCommentsElement(derived.getCommentsElement().copy());
 else       if (derived.hasCommentsElement())       derived.getCommentsElement().setUserData(DERIVATION_EQUALS,true);
    }
    if (derived.hasRequirementsElement()) {
      if (derived.getRequirements().startsWith("String_Node_Str"))       base.setRequirements(base.getRequirements() + "String_Node_Str" + derived.getRequirements().substring(3));
 else       if (!Base.compareDeep(derived.getRequirementsElement(),base.getRequirementsElement(),false))       base.setRequirementsElement(derived.getRequirementsElement().copy());
 else       if (trimDifferential)       base.setRequirementsElement(derived.getRequirementsElement().copy());
 else       if (derived.hasRequirementsElement())       derived.getRequirementsElement().setUserData(DERIVATION_EQUALS,true);
    }
    if (derived.hasAlias()) {
      if (!Base.compareDeep(derived.getAlias(),base.getAlias(),false))       for (      StringType s : derived.getAlias()) {
        if (!base.hasAlias(s.getValue()))         base.getAlias().add(s.copy());
      }
 else       if (trimDifferential)       derived.getAlias().clear();
 else       for (      StringType t : derived.getAlias())       t.setUserData(DERIVATION_EQUALS,true);
    }
    if (derived.hasMinElement()) {
      if (!Base.compareDeep(derived.getMinElement(),base.getMinElement(),false))       base.setMinElement(derived.getMinElement().copy());
 else       if (trimDifferential)       derived.setMinElement(null);
 else       derived.getMinElement().setUserData(DERIVATION_EQUALS,true);
    }
    if (derived.hasMaxElement()) {
      if (!Base.compareDeep(derived.getMaxElement(),base.getMaxElement(),false))       base.setMaxElement(derived.getMaxElement().copy());
 else       if (trimDifferential)       derived.setMaxElement(null);
 else       derived.getMaxElement().setUserData(DERIVATION_EQUALS,true);
    }
    if (derived.hasFixed()) {
      if (!Base.compareDeep(derived.getFixed(),base.getFixed(),true)) {
        base.setFixed(derived.getFixed().copy());
      }
 else       if (trimDifferential)       derived.setFixed(null);
 else       derived.getFixed().setUserData(DERIVATION_EQUALS,true);
    }
    if (derived.hasPattern()) {
      if (!Base.compareDeep(derived.getPattern(),base.getPattern(),false)) {
        base.setPattern(derived.getPattern().copy());
      }
 else       if (trimDifferential)       derived.setPattern(null);
 else       derived.getPattern().setUserData(DERIVATION_EQUALS,true);
    }
    if (derived.hasExample()) {
      if (!Base.compareDeep(derived.getExample(),base.getExample(),false))       base.setExample(derived.getExample().copy());
 else       if (trimDifferential)       derived.setExample(null);
 else       derived.getExample().setUserData(DERIVATION_EQUALS,true);
    }
    if (derived.hasMaxLengthElement()) {
      if (!Base.compareDeep(derived.getMaxLengthElement(),base.getMaxLengthElement(),false))       base.setMaxLengthElement(derived.getMaxLengthElement().copy());
 else       if (trimDifferential)       derived.setMaxLengthElement(null);
 else       derived.getMaxLengthElement().setUserData(DERIVATION_EQUALS,true);
    }
    if (derived.hasMustSupportElement()) {
      if (!Base.compareDeep(derived.getMustSupportElement(),base.getMustSupportElement(),false))       base.setMustSupportElement(derived.getMustSupportElement().copy());
 else       if (trimDifferential)       derived.setMustSupportElement(null);
 else       derived.getMustSupportElement().setUserData(DERIVATION_EQUALS,true);
    }
    if (isExtension) {
      if (!Base.compareDeep(derived.getIsModifierElement(),base.getIsModifierElement(),false))       base.setIsModifierElement(derived.getIsModifierElement().copy());
 else       if (trimDifferential)       derived.setIsModifierElement(null);
 else       derived.getIsModifierElement().setUserData(DERIVATION_EQUALS,true);
    }
    if (derived.hasBinding()) {
      if (!Base.compareDeep(derived.getBinding(),base.getBinding(),false)) {
        if (base.hasBinding() && base.getBinding().getStrength() == BindingStrength.REQUIRED && base.getBinding().getStrength() != BindingStrength.REQUIRED)         throw new Exception("String_Node_Str" + pn + "String_Node_Str"+ derived.getPath()+ "String_Node_Str"+ base.getBinding().getStrength().toCode()+ "String_Node_Str"+ base.getBinding().getStrength().toCode());
        base.setBinding(derived.getBinding().copy());
      }
 else       if (trimDifferential)       derived.setBinding(null);
 else       derived.getBinding().setUserData(DERIVATION_EQUALS,true);
    }
    if (derived.hasIsSummaryElement()) {
      if (!Base.compareDeep(derived.getIsSummaryElement(),base.getIsSummaryElement(),false))       base.setIsSummaryElement(derived.getIsSummaryElement().copy());
 else       if (trimDifferential)       derived.setIsSummaryElement(null);
 else       derived.getIsSummaryElement().setUserData(DERIVATION_EQUALS,true);
    }
    if (derived.hasType()) {
      if (!Base.compareDeep(derived.getType(),base.getType(),false)) {
        if (base.hasType()) {
          for (          TypeRefComponent ts : derived.getType()) {
            boolean ok=false;
            CommaSeparatedStringBuilder b=new CommaSeparatedStringBuilder();
            for (            TypeRefComponent td : base.getType()) {
              b.append(td.getCode());
              if (td.getCode().equals(ts.getCode()) || td.getCode().equals("String_Node_Str") || td.getCode().equals("String_Node_Str")|| td.getCode().equals("String_Node_Str")|| ((td.getCode().equals("String_Node_Str") || (td.getCode().equals("String_Node_Str")) && pkp.isResource(ts.getCode()))))               ok=true;
            }
            if (!ok)             throw new Exception("String_Node_Str" + pn + "String_Node_Str"+ derived.getPath()+ "String_Node_Str"+ ts.getCode()+ "String_Node_Str"+ b.toString());
          }
        }
        base.getType().clear();
        for (        TypeRefComponent t : derived.getType())         base.getType().add(t.copy());
      }
 else       if (trimDifferential)       derived.getType().clear();
 else       for (      TypeRefComponent t : derived.getType())       t.setUserData(DERIVATION_EQUALS,true);
    }
    if (derived.hasMapping()) {
      if (!Base.compareDeep(derived.getMapping(),base.getMapping(),false)) {
        for (        ElementDefinitionMappingComponent s : derived.getMapping()) {
          boolean found=false;
          for (          ElementDefinitionMappingComponent d : base.getMapping()) {
            found=found || (d.getIdentity().equals(s.getIdentity()) && d.getMap().equals(s.getMap()));
          }
          if (!found)           base.getMapping().add(s);
        }
      }
 else       if (trimDifferential)       derived.getMapping().clear();
 else       for (      ElementDefinitionMappingComponent t : derived.getMapping())       t.setUserData(DERIVATION_EQUALS,true);
    }
    if (derived.hasConstraint()) {
      for (      ElementDefinitionConstraintComponent s : derived.getConstraint()) {
        base.getConstraint().add(s);
      }
    }
  }
}