Program: 73443
Project: 73443
Buggy source:
/** 
 * Add new connections.
 * @exception TransformationException If transformation is unsuccessful.
 */
protected void _addConnections() throws TransformationException {
  for (  NamedObj replacement : _replacementToHost.keySet()) {
    NamedObj host=_replacementToHost.get(replacement);
    List<NamedObj> replacementLinkedList;
    List<NamedObj> hostLinkdList;
    if (host instanceof Port) {
      replacementLinkedList=new LinkedList<NamedObj>(((Port)replacement).linkedRelationList());
      hostLinkdList=new LinkedList<NamedObj>(((Port)host).linkedRelationList());
    }
 else     if (host instanceof Relation) {
      replacementLinkedList=new LinkedList<NamedObj>();
      for (      Object relation : ((Relation)replacement).linkedObjectsList()) {
        if (relation instanceof Relation) {
          replacementLinkedList.add((Relation)relation);
        }
      }
      hostLinkdList=new LinkedList<NamedObj>();
      for (      Object relation : ((Relation)host).linkedObjectsList()) {
        if (relation instanceof Relation) {
          replacementLinkedList.add((Relation)relation);
        }
      }
    }
 else {
      continue;
    }
    for (    NamedObj replacementLinkedObject : replacementLinkedList) {
      NamedObj hostLinkedObject=_replacementToHost.get(replacementLinkedObject);
      if (hostLinkedObject != null && !hostLinkdList.contains(hostLinkedObject)) {
        Relation relation=(hostLinkedObject instanceof Relation) ? (Relation)hostLinkedObject : (Relation)host;
        NamedObj hostContainer=relation.getContainer();
        String moml;
        if (relation == hostLinkedObject) {
          moml=_getLinkMoML(host,relation);
        }
 else {
          moml=_getLinkMoML(hostLinkedObject,relation);
        }
        MoMLChangeRequest request=_createChangeRequest(hostContainer,moml);
        request.execute();
      }
    }
    if (replacement instanceof ComponentPort && host instanceof ComponentPort) {
      ComponentPort replacementComponentPort=(ComponentPort)replacement;
      ComponentPort hostComponentPort=(ComponentPort)host;
      try {
        replacementComponentPort.workspace().getReadAccess();
        for (        Object replacementRelationObject : replacementComponentPort.insideRelationList()) {
          Relation replacementRelation=(Relation)replacementRelationObject;
          Relation hostRelation=(Relation)_replacementToHost.get(replacementRelation);
          if (!hostComponentPort.insideRelationList().contains(hostRelation)) {
            NamedObj hostContainer=hostRelation.getContainer();
            String moml=_getLinkMoML(host,hostRelation);
            MoMLChangeRequest request=_createChangeRequest(hostContainer,moml);
            request.execute();
          }
        }
      }
  finally {
        replacementComponentPort.workspace().doneReading();
      }
    }
  }
}

Fixed version (ground truth):
/** 
 * Add new connections.
 * @exception TransformationException If transformation is unsuccessful.
 */
protected void _addConnections() throws TransformationException {
  for (  NamedObj replacement : _replacementToHost.keySet()) {
    NamedObj host=_replacementToHost.get(replacement);
    List<NamedObj> replacementLinkedList;
    List<NamedObj> hostLinkdList;
    if (host instanceof Port) {
      replacementLinkedList=new LinkedList<NamedObj>(((Port)replacement).linkedRelationList());
      hostLinkdList=new LinkedList<NamedObj>(((Port)host).linkedRelationList());
    }
 else     if (host instanceof Relation) {
      replacementLinkedList=new LinkedList<NamedObj>();
      for (      Object relation : ((Relation)replacement).linkedObjectsList()) {
        if (relation instanceof Relation) {
          replacementLinkedList.add((Relation)relation);
        }
      }
      hostLinkdList=new LinkedList<NamedObj>();
      for (      Object relation : ((Relation)host).linkedObjectsList()) {
        if (relation instanceof Relation) {
          replacementLinkedList.add((Relation)relation);
        }
      }
    }
 else {
      continue;
    }
    for (    NamedObj replacementLinkedObject : replacementLinkedList) {
      NamedObj hostLinkedObject=_replacementToHost.get(replacementLinkedObject);
      if (hostLinkedObject != null && !hostLinkdList.contains(hostLinkedObject)) {
        Relation relation=(hostLinkedObject instanceof Relation) ? (Relation)hostLinkedObject : (Relation)host;
        NamedObj hostContainer=relation.getContainer();
        if (!(hostContainer instanceof MirrorComposite)) {
          String moml;
          if (relation == hostLinkedObject) {
            moml=_getLinkMoML(host,relation);
          }
 else {
            moml=_getLinkMoML(hostLinkedObject,relation);
          }
          MoMLChangeRequest request=_createChangeRequest(hostContainer,moml);
          request.execute();
        }
      }
    }
    if (replacement instanceof ComponentPort && host instanceof ComponentPort) {
      ComponentPort replacementComponentPort=(ComponentPort)replacement;
      ComponentPort hostComponentPort=(ComponentPort)host;
      try {
        replacementComponentPort.workspace().getReadAccess();
        for (        Object replacementRelationObject : replacementComponentPort.insideRelationList()) {
          Relation replacementRelation=(Relation)replacementRelationObject;
          Relation hostRelation=(Relation)_replacementToHost.get(replacementRelation);
          NamedObj hostContainer=host.getContainer();
          if (!(hostContainer instanceof MirrorComposite) && !hostComponentPort.insideRelationList().contains(hostRelation)) {
            String moml=_getLinkMoML(host,hostRelation);
            MoMLChangeRequest request=_createChangeRequest(hostContainer,moml);
            request.execute();
          }
        }
      }
  finally {
        replacementComponentPort.workspace().doneReading();
      }
    }
  }
}