Program: 76014
Project: 76014
Buggy source:
private void _updateLinks(ComponentRelation relation){
  List linkedPortList=relation.linkedPortList();
  int allPortCount=linkedPortList.size();
  Iterator links=_linkSet.iterator();
  while (links.hasNext()) {
    Link link=(Link)links.next();
    if (link.getRelation() != relation)     continue;
    Object tail=link.getTail();
    if (tail instanceof Location) {
      tail=((Location)tail).getContainer();
    }
    if (tail != null && linkedPortList.contains(tail)) {
      linkedPortList.remove(tail);
    }
    Object head=link.getHead();
    if (head instanceof Location) {
      head=((Location)head).getContainer();
    }
    if (head != null && linkedPortList.contains(head)) {
      linkedPortList.remove(head);
    }
  }
  int unlinkedPortCount=linkedPortList.size();
  if (unlinkedPortCount == 0)   return;
  Iterator vertexes=relation.attributeList(Vertex.class).iterator();
  Vertex rootVertex=null;
  while (vertexes.hasNext()) {
    Vertex v=(Vertex)vertexes.next();
    if (v.getLinkedVertex() == null) {
      rootVertex=v;
    }
  }
  if (rootVertex == null && allPortCount == 2 && unlinkedPortCount == 2) {
    Port port1=(Port)linkedPortList.get(0);
    Port port2=(Port)linkedPortList.get(1);
    Object head=null;
    Object tail=null;
    if (port1.getContainer().equals(getRoot())) {
      head=_getLocation(port1);
    }
 else {
      head=port1;
    }
    if (port2.getContainer().equals(getRoot())) {
      tail=_getLocation(port2);
    }
 else {
      tail=port2;
    }
    Link link;
    try {
      link=new Link();
      _linkSet.add(link);
    }
 catch (    Exception e) {
      throw new InternalErrorException("String_Node_Str" + "String_Node_Str" + "String_Node_Str"+ e.getMessage());
    }
    link.setRelation(relation);
    link.setHead(head);
    link.setTail(tail);
  }
 else {
    if (rootVertex == null) {
      try {
        rootVertex=new Vertex(relation,relation.uniqueName("String_Node_Str"));
      }
 catch (      Exception e) {
        throw new InternalErrorException("String_Node_Str" + "String_Node_Str" + "String_Node_Str"+ e.getMessage());
      }
    }
    Iterator ports=linkedPortList.iterator();
    while (ports.hasNext()) {
      Port port=(Port)ports.next();
      Object head=null;
      if (port.getContainer().equals(getRoot())) {
        head=_getLocation(port);
      }
 else {
        head=port;
      }
      Link link;
      try {
        link=new Link();
        _linkSet.add(link);
      }
 catch (      Exception e) {
        throw new InternalErrorException("String_Node_Str" + "String_Node_Str" + "String_Node_Str"+ e.getMessage());
      }
      link.setRelation(relation);
      link.setHead(head);
      link.setTail(rootVertex);
    }
  }
}

Fixed version (ground truth):
private void _updateLinks(ComponentRelation relation){
  List linkedPortList=relation.linkedPortList();
  int allPortCount=linkedPortList.size();
  Iterator links=_linkSet.iterator();
  while (links.hasNext()) {
    Link link=(Link)links.next();
    if (link.getRelation() != relation)     continue;
    Object tail=link.getTail();
    Object tailObj=getSemanticObject(tail);
    if (tailObj != null && linkedPortList.contains(tailObj)) {
      linkedPortList.remove(tailObj);
    }
    Object head=link.getHead();
    Object headObj=getSemanticObject(head);
    if (headObj != null && linkedPortList.contains(headObj)) {
      linkedPortList.remove(headObj);
    }
  }
  int unlinkedPortCount=linkedPortList.size();
  if (unlinkedPortCount == 0)   return;
  Iterator vertexes=relation.attributeList(Vertex.class).iterator();
  Vertex rootVertex=null;
  while (vertexes.hasNext()) {
    Vertex v=(Vertex)vertexes.next();
    if (v.getLinkedVertex() == null) {
      rootVertex=v;
    }
  }
  if (rootVertex == null && allPortCount == 2 && unlinkedPortCount == 2) {
    Port port1=(Port)linkedPortList.get(0);
    Port port2=(Port)linkedPortList.get(1);
    Object head=null;
    Object tail=null;
    if (port1.getContainer().equals(getRoot())) {
      head=_getLocation(port1);
    }
 else {
      head=port1;
    }
    if (port2.getContainer().equals(getRoot())) {
      tail=_getLocation(port2);
    }
 else {
      tail=port2;
    }
    Link link;
    try {
      link=new Link();
      _linkSet.add(link);
    }
 catch (    Exception e) {
      throw new InternalErrorException("String_Node_Str" + "String_Node_Str" + "String_Node_Str"+ e.getMessage());
    }
    link.setRelation(relation);
    link.setHead(head);
    link.setTail(tail);
  }
 else {
    if (rootVertex == null) {
      try {
        rootVertex=new Vertex(relation,relation.uniqueName("String_Node_Str"));
      }
 catch (      Exception e) {
        throw new InternalErrorException("String_Node_Str" + "String_Node_Str" + "String_Node_Str"+ e.getMessage());
      }
    }
    Iterator ports=linkedPortList.iterator();
    while (ports.hasNext()) {
      Port port=(Port)ports.next();
      Object head=null;
      if (port.getContainer().equals(getRoot())) {
        head=_getLocation(port);
      }
 else {
        head=port;
      }
      Link link;
      try {
        link=new Link();
        _linkSet.add(link);
      }
 catch (      Exception e) {
        throw new InternalErrorException("String_Node_Str" + "String_Node_Str" + "String_Node_Str"+ e.getMessage());
      }
      link.setRelation(relation);
      link.setHead(head);
      link.setTail(rootVertex);
    }
  }
}