Program: 74517
Project: 74517
Buggy source:
private void _removeObject(NamedObj object) throws TransformationException {
  if (object instanceof CompositeEntity) {
    CompositeEntity entity=(CompositeEntity)object;
    CompositeEntity container=(CompositeEntity)entity.getContainer();
    Map<NamedObj,NamedObj> entityMap=new HashMap<NamedObj,NamedObj>();
    Collection<?> children=_getChildren(entity,false,false,true,true);
    List<Object> childrenRemoved=new LinkedList<Object>();
    childrenRemoved.addAll(children);
    MoMLChangeRequest request=GTTools.getDeletionChangeRequest(this,object);
    request.execute();
    _removeReplacementToHostEntries(object);
    for (    Object childObject : childrenRemoved) {
      NamedObj child=(NamedObj)childObject;
      String moml="String_Node_Str" + child.exportMoMLPlain() + "String_Node_Str";
      request=new MoMLChangeRequest(this,container,moml);
      request.execute();
      NamedObj newlyAddedObject=_getNewlyAddedObject(container,child.getClass());
      _addReplacementToHostEntries(newlyAddedObject);
      entityMap.put(child,newlyAddedObject);
    }
    for (    NamedObj originalObject : entityMap.keySet()) {
      if (originalObject instanceof Relation) {
        Relation originalRelation=(Relation)originalObject;
        Relation relation1=(Relation)entityMap.get(originalRelation);
        for (        Object linkedObject : originalRelation.linkedObjectsList()) {
          if (linkedObject instanceof Relation) {
            Relation relation2=(Relation)entityMap.get(linkedObject);
            String moml="String_Node_Str" + relation1.getName() + "String_Node_Str"+ relation2.getName()+ "String_Node_Str";
            request=new MoMLChangeRequest(this,container,moml);
            request.execute();
          }
 else           if (linkedObject instanceof Port) {
            Port originalPort=(Port)linkedObject;
            Entity linkedEntity=(Entity)entityMap.get(originalPort.getContainer());
            if (linkedEntity != null) {
              Port port2=linkedEntity.getPort(originalPort.getName());
              String moml="String_Node_Str" + linkedEntity.getName() + "String_Node_Str"+ port2.getName()+ "String_Node_Str"+ relation1.getName()+ "String_Node_Str";
              request=new MoMLChangeRequest(this,container,moml);
              request.execute();
            }
          }
        }
      }
    }
  }
 else {
    MoMLChangeRequest request=GTTools.getDeletionChangeRequest(this,object);
    request.execute();
  }
}

Fixed version (ground truth):
private Set<NamedObj> _removeObject(NamedObj object) throws TransformationException {
  if (object instanceof CompositeEntity) {
    CompositeEntity entity=(CompositeEntity)object;
    CompositeEntity container=(CompositeEntity)entity.getContainer();
    TwoWayHashMap<NamedObj,NamedObj> entityMap=new TwoWayHashMap<NamedObj,NamedObj>();
    List<NamedObj> preservedChildren=_getPreservedChildren(entity);
    MoMLChangeRequest request=GTTools.getDeletionChangeRequest(this,object);
    request.execute();
    _removeReplacementToHostEntries(object);
    for (    NamedObj child : preservedChildren) {
      String moml="String_Node_Str" + child.exportMoMLPlain() + "String_Node_Str";
      request=new MoMLChangeRequest(this,container,moml);
      request.execute();
      NamedObj newlyAddedObject=_getNewlyAddedObject(container,child.getClass());
      _addReplacementToHostEntries(newlyAddedObject);
      _replaceMatchResultEntries(child,newlyAddedObject);
      entityMap.put(child,newlyAddedObject);
    }
    for (    NamedObj originalObject : entityMap.keySet()) {
      if (originalObject instanceof Relation) {
        Relation originalRelation=(Relation)originalObject;
        Relation relation1=(Relation)entityMap.get(originalRelation);
        for (        Object linkedObject : originalRelation.linkedObjectsList()) {
          if (linkedObject instanceof Relation) {
            Relation relation2=(Relation)entityMap.get(linkedObject);
            String moml="String_Node_Str" + relation1.getName() + "String_Node_Str"+ relation2.getName()+ "String_Node_Str";
            request=new MoMLChangeRequest(this,container,moml);
            request.execute();
          }
 else           if (linkedObject instanceof Port) {
            Port originalPort=(Port)linkedObject;
            Entity linkedEntity=(Entity)entityMap.get(originalPort.getContainer());
            if (linkedEntity != null) {
              Port port2=linkedEntity.getPort(originalPort.getName());
              String moml="String_Node_Str" + linkedEntity.getName() + "String_Node_Str"+ port2.getName()+ "String_Node_Str"+ relation1.getName()+ "String_Node_Str";
              request=new MoMLChangeRequest(this,container,moml);
              request.execute();
            }
          }
        }
      }
    }
    return entityMap.values();
  }
 else {
    MoMLChangeRequest request=GTTools.getDeletionChangeRequest(this,object);
    request.execute();
    return null;
  }
}