Program: 74189
Project: 74189
Buggy source:
/** 
 * Make sure that there is a Link object representing every link connected to the given relation.  Create links if necessary.
 */
private void _updateLinks(ComponentRelation relation){
  if (_isHidden(relation)) {
    return;
  }
  List<?> linkedObjects=relation.linkedObjectsList();
  int linkedObjectsCount=linkedObjects.size();
  for (  Link link : new LinkedList<Link>(_linkSet)) {
    Object tail=link.getTail();
    Object tailObj=getSemanticObject(tail);
    Object head=link.getHead();
    Object headObj=getSemanticObject(head);
    if ((tailObj != relation) && (headObj != relation) && (link.getRelation() != relation)) {
      continue;
    }
    if ((tailObj != null) && linkedObjects.contains(tailObj)) {
      linkedObjects.remove(tailObj);
    }
 else     if (tailObj != relation) {
      link.setHead(null);
      link.setTail(null);
      _linkSet.remove(link);
    }
    if ((headObj != null) && linkedObjects.contains(headObj)) {
      linkedObjects.remove(headObj);
    }
 else     if (headObj != relation) {
      link.setHead(null);
      link.setTail(null);
      _linkSet.remove(link);
    }
  }
  int unlinkedPortCount=linkedObjects.size();
  if (unlinkedPortCount == 0) {
    return;
  }
  Vertex rootVertex=null;
  Iterator<?> vertexes=relation.attributeList(Vertex.class).iterator();
  while (vertexes.hasNext()) {
    Vertex v=(Vertex)vertexes.next();
    if (v.getLinkedVertex() == null) {
      rootVertex=v;
    }
  }
  if ((rootVertex == null) && (linkedObjectsCount == 2) && (unlinkedPortCount == 2)&& linkedObjects.get(0) instanceof Port&& linkedObjects.get(1) instanceof Port) {
    Port port1=(Port)linkedObjects.get(0);
    Port port2=(Port)linkedObjects.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 {
        String name=relation.uniqueName("String_Node_Str");
        rootVertex=new Vertex(relation,name);
        rootVertex.propagateExistence();
      }
 catch (      Throwable throwable) {
        throw new InternalErrorException(null,throwable,"String_Node_Str" + "String_Node_Str" + "String_Node_Str"+ throwable.getMessage());
      }
    }
    Iterator<?> linkedObjectsIterator=linkedObjects.iterator();
    while (linkedObjectsIterator.hasNext()) {
      Object portOrRelation=linkedObjectsIterator.next();
      Object head=null;
      if (portOrRelation instanceof Port) {
        Port port=(Port)portOrRelation;
        if (port.getContainer().equals(getRoot())) {
          head=_getLocation(port);
        }
 else {
          head=port;
        }
      }
 else {
        vertexes=((Relation)portOrRelation).attributeList(Vertex.class).iterator();
        while (vertexes.hasNext()) {
          Vertex v=(Vertex)vertexes.next();
          if (v.getLinkedVertex() == null) {
            head=v;
          }
        }
      }
      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):
/** 
 * Make sure that there is a Link object representing every link connected to the given relation.  Create links if necessary.
 */
private void _updateLinks(ComponentRelation relation){
  if (_isHidden(relation)) {
    return;
  }
  if (relation.getName().equals("String_Node_Str")) {
    int i=0;
    i++;
  }
  List<?> linkedObjects=relation.linkedObjectsList();
  int linkedObjectsCount=linkedObjects.size();
  for (  Link link : new LinkedList<Link>(_linkSet)) {
    Object tail=link.getTail();
    Object tailObj=getSemanticObject(tail);
    Object head=link.getHead();
    Object headObj=getSemanticObject(head);
    if ((tailObj != relation) && (headObj != relation) && (link.getRelation() != relation)) {
      continue;
    }
    if (tailObj != relation && headObj != relation && linkedObjectsCount > 2) {
      link.setHead(null);
      link.setTail(null);
      _linkSet.remove(link);
      continue;
    }
    if ((tailObj != null) && linkedObjects.contains(tailObj)) {
      linkedObjects.remove(tailObj);
    }
 else     if (tailObj != relation) {
      link.setHead(null);
      link.setTail(null);
      _linkSet.remove(link);
    }
    if ((headObj != null) && linkedObjects.contains(headObj)) {
      linkedObjects.remove(headObj);
    }
 else     if (headObj != relation) {
      link.setHead(null);
      link.setTail(null);
      _linkSet.remove(link);
    }
  }
  int unlinkedPortCount=linkedObjects.size();
  if (unlinkedPortCount == 0) {
    return;
  }
  Vertex rootVertex=null;
  Iterator<?> vertexes=relation.attributeList(Vertex.class).iterator();
  while (vertexes.hasNext()) {
    Vertex v=(Vertex)vertexes.next();
    if (v.getLinkedVertex() == null) {
      rootVertex=v;
    }
  }
  if ((rootVertex == null) && (linkedObjectsCount == 2) && (unlinkedPortCount == 2)&& linkedObjects.get(0) instanceof Port&& linkedObjects.get(1) instanceof Port) {
    Port port1=(Port)linkedObjects.get(0);
    Port port2=(Port)linkedObjects.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 {
        String name=relation.uniqueName("String_Node_Str");
        rootVertex=new Vertex(relation,name);
        rootVertex.propagateExistence();
      }
 catch (      Throwable throwable) {
        throw new InternalErrorException(null,throwable,"String_Node_Str" + "String_Node_Str" + "String_Node_Str"+ throwable.getMessage());
      }
    }
    Iterator<?> linkedObjectsIterator=linkedObjects.iterator();
    while (linkedObjectsIterator.hasNext()) {
      Object portOrRelation=linkedObjectsIterator.next();
      Object head=null;
      if (portOrRelation instanceof Port) {
        Port port=(Port)portOrRelation;
        if (port.getContainer().equals(getRoot())) {
          head=_getLocation(port);
        }
 else {
          head=port;
        }
      }
 else {
        vertexes=((Relation)portOrRelation).attributeList(Vertex.class).iterator();
        while (vertexes.hasNext()) {
          Vertex v=(Vertex)vertexes.next();
          if (v.getLinkedVertex() == null) {
            head=v;
          }
        }
      }
      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);
    }
  }
}