Program: 74436
Project: 74436
Buggy source:
private void _removeLinks(CompositeEntity pattern){
  Set<Pair<Relation,Object>> linksToRemove=new HashSet<Pair<Relation,Object>>();
  try {
    pattern.workspace().getReadAccess();
    Collection<?> relations=GTTools.getChildren(pattern,false,false,false,true);
    for (    Object relationObject : relations) {
      Relation relation=(Relation)relationObject;
      Relation replacementRelation=(Relation)_patternToReplacement.get(relation);
      if (replacementRelation == null) {
        continue;
      }
      List<?> linkedObjectList=relation.linkedObjectsList();
      for (      Object linkedObject : linkedObjectList) {
        Object replacementLinkedObject=_patternToReplacement.get(linkedObject);
        if (replacementLinkedObject == null) {
          continue;
        }
        boolean linkRemoved;
        if (replacementLinkedObject instanceof Port) {
          linkRemoved=!((Port)replacementLinkedObject).isLinked(replacementRelation);
        }
 else {
          linkRemoved=!replacementRelation.linkedObjectsList().contains(replacementLinkedObject);
        }
        if (linkRemoved) {
          linksToRemove.add(new Pair<Relation,Object>(relation,linkedObject));
        }
      }
    }
  }
  finally {
    pattern.workspace().doneReading();
  }
  for (  Pair<Relation,Object> link : linksToRemove) {
    Relation hostRelation=(Relation)_matchResult.get(link.getFirst());
    if (hostRelation == null) {
      continue;
    }
    Object hostObject=_matchResult.get(link.getSecond());
    if (hostObject == null) {
      continue;
    }
    String name;
    if (hostObject instanceof Port) {
      Port port=(Port)hostObject;
      name=port.getContainer().getName() + "String_Node_Str" + port.getName();
    }
 else {
      name=((Relation)hostObject).getName();
    }
    String moml="String_Node_Str" + name + "String_Node_Str"+ hostRelation.getName()+ "String_Node_Str";
    MoMLChangeRequest request=new MoMLChangeRequest(this,hostRelation.getContainer(),moml);
    request.execute();
  }
  try {
    pattern.workspace().getReadAccess();
    Collection<?> entities=GTTools.getChildren(pattern,false,false,true,false);
    for (    Object entityObject : entities) {
      if (entityObject instanceof CompositeEntity) {
        _removeLinks((CompositeEntity)entityObject);
      }
    }
  }
  finally {
    pattern.workspace().doneReading();
  }
}

Fixed version (ground truth):
private void _removeLinks(CompositeEntity pattern){
  Set<Pair<Relation,Object>> linksToRemove=new HashSet<Pair<Relation,Object>>();
  try {
    pattern.workspace().getReadAccess();
    Collection<?> relations=GTTools.getChildren(pattern,false,false,false,true);
    for (    Object relationObject : relations) {
      Relation relation=(Relation)relationObject;
      Relation replacementRelation=(Relation)_patternToReplacement.get(relation);
      if (replacementRelation == null) {
        continue;
      }
      List<?> linkedObjectList=relation.linkedObjectsList();
      for (      Object linkedObject : linkedObjectList) {
        Object replacementLinkedObject=_patternToReplacement.get(linkedObject);
        if (replacementLinkedObject == null) {
          continue;
        }
        boolean linkRemoved;
        if (replacementLinkedObject instanceof Port) {
          linkRemoved=!((Port)replacementLinkedObject).isLinked(replacementRelation);
        }
 else {
          linkRemoved=!replacementRelation.linkedObjectsList().contains(replacementLinkedObject);
        }
        if (linkRemoved) {
          linksToRemove.add(new Pair<Relation,Object>(relation,linkedObject));
        }
      }
    }
  }
  finally {
    pattern.workspace().doneReading();
  }
  for (  Pair<Relation,Object> link : linksToRemove) {
    Relation hostRelation=(Relation)_matchResult.get(link.getFirst());
    if (hostRelation == null) {
      continue;
    }
    Object hostObject=_matchResult.get(link.getSecond());
    if (hostObject == null) {
      continue;
    }
    String name;
    if (hostObject instanceof Port && hostRelation.getContainer() != ((Port)hostObject).getContainer()) {
      Port port=(Port)hostObject;
      name=port.getContainer().getName() + "String_Node_Str" + port.getName();
    }
 else {
      name=((NamedObj)hostObject).getName();
    }
    String moml="String_Node_Str" + name + "String_Node_Str"+ hostRelation.getName()+ "String_Node_Str";
    MoMLChangeRequest request=new MoMLChangeRequest(this,hostRelation.getContainer(),moml);
    request.execute();
  }
  try {
    pattern.workspace().getReadAccess();
    Collection<?> entities=GTTools.getChildren(pattern,false,false,true,false);
    for (    Object entityObject : entities) {
      if (entityObject instanceof CompositeEntity) {
        _removeLinks((CompositeEntity)entityObject);
      }
    }
  }
  finally {
    pattern.workspace().doneReading();
  }
}