Program: 73354
Project: 73354
Buggy source:
/** 
 * Return a sequence of MoML link attributes that describe any link between objects (ports, entities, and relations) that are present in the <i>filter</i> argument.  Both ends of the link must be present in <i>filter</i> for MoML to be generated for that link.  The <i>filter</i> argument normally contains ports, relations, and entities that are contained by this composite entity. If it contains an entity, then that is equivalent to containing all the ports contained by that entity.  It is recommended to use a collection class (such as HashSet) for which the contains() method is efficient. <p> If the filter argument is null, then return all the links that this composite is responsible for (i.e., apply no filtering).  If the argument is an empty collection, then return none of the links.  The links that this entity is responsible for are the inside links of its ports, and links on ports contained by contained entities. <p> If any link is found where both ends of the link are inherited objects, then that link is not exported. It is assumed that the base class will export that link.  For this purpose, a port of a contained entity is deemed to be an inherited object if it is itself a class element <i>and</i> its container is an inherited object.
 * @param depth The depth below the MoML export in the hierarchy.
 * @param filter A collection of ports, parameters, and entities, ornull to apply no filtering.
 * @return A string that describes the links present in the<i>filter</i>.
 * @exception IOException If an I/O error occurs.
 */
public String exportLinks(int depth,Collection filter) throws IOException {
  StringBuffer result=new StringBuffer();
  Iterator ports=portList().iterator();
  while (ports.hasNext()) {
    ComponentPort port=(ComponentPort)ports.next();
    if (port != null && !port.isPersistent()) {
      continue;
    }
    Iterator relations=port.insideRelationList().iterator();
    int index=-1;
    boolean useIndex=false;
    while (relations.hasNext()) {
      index++;
      ComponentRelation relation=(ComponentRelation)relations.next();
      if (relation != null && !relation.isPersistent()) {
        continue;
      }
      if (relation == null) {
        useIndex=true;
        continue;
      }
      if (_commonImplier(relation,depth,port,depth)) {
        continue;
      }
      if ((filter == null) || (filter.contains(relation) && (filter.contains(port) || filter.contains(port.getContainer())))) {
        if (relation != null && !relation.isPersistent()) {
          continue;
        }
        String relationName;
        if (relation.getContainer() == this) {
          relationName=relation.getName();
        }
 else {
          if (deepContains(relation)) {
            relationName=relation.getName(this);
          }
 else {
            _recordLevelCrossingLink(port,relation,null,index);
            continue;
          }
        }
        String escapedPortName=StringUtilities.escapeForXML(port.getName());
        String escapedRelationName=StringUtilities.escapeForXML(relationName);
        if (useIndex) {
          useIndex=false;
          result.append(_getIndentPrefix(depth) + "String_Node_Str" + escapedPortName+ "String_Node_Str"+ index+ "String_Node_Str"+ escapedRelationName+ "String_Node_Str");
        }
 else {
          result.append(_getIndentPrefix(depth) + "String_Node_Str" + escapedPortName+ "String_Node_Str"+ escapedRelationName+ "String_Node_Str");
        }
      }
    }
  }
  Iterator entities=entityList().iterator();
  while (entities.hasNext()) {
    ComponentEntity entity=(ComponentEntity)entities.next();
    if (entity != null && !entity.isPersistent()) {
      continue;
    }
    ports=entity.portList().iterator();
    while (ports.hasNext()) {
      ComponentPort port=(ComponentPort)ports.next();
      if (port != null && !port.isPersistent()) {
        continue;
      }
      Iterator relations=port.linkedRelationList().iterator();
      int index=-1;
      boolean useIndex=false;
      while (relations.hasNext()) {
        index++;
        ComponentRelation relation=(ComponentRelation)relations.next();
        if (relation != null && !relation.isPersistent()) {
          continue;
        }
        if (relation == null) {
          useIndex=true;
          continue;
        }
        if (port.getDerivedLevel() <= (depth + 1) && _commonImplier(relation,depth,port.getContainer(),depth)) {
          continue;
        }
        if ((filter == null) || (filter.contains(relation) && (filter.contains(port) || filter.contains(port.getContainer())))) {
          if (relation != null && !relation.isPersistent()) {
            continue;
          }
          String relationName;
          if (relation.getContainer() == this) {
            relationName=relation.getName();
          }
 else {
            if (deepContains(relation)) {
              relationName=relation.getName(this);
            }
 else {
              _recordLevelCrossingLink(port,relation,null,index);
              continue;
            }
          }
          String escapedName=StringUtilities.escapeForXML(entity.getName());
          String escapedPortName=StringUtilities.escapeForXML(port.getName());
          String escapedRelationName=StringUtilities.escapeForXML(relationName);
          if (useIndex) {
            useIndex=false;
            result.append(_getIndentPrefix(depth) + "String_Node_Str" + escapedName+ "String_Node_Str"+ escapedPortName+ "String_Node_Str"+ index+ "String_Node_Str"+ escapedRelationName+ "String_Node_Str");
          }
 else {
            result.append(_getIndentPrefix(depth) + "String_Node_Str" + escapedName+ "String_Node_Str"+ escapedPortName+ "String_Node_Str"+ escapedRelationName+ "String_Node_Str");
          }
        }
      }
    }
  }
  Set visitedRelations=new HashSet();
  Iterator relations=relationList().iterator();
  while (relations.hasNext()) {
    ComponentRelation relation=(ComponentRelation)relations.next();
    visitedRelations.add(relation);
    if (relation != null && !relation.isPersistent()) {
      continue;
    }
    Iterator portsAndRelations=relation.linkedObjectsList().iterator();
    while (portsAndRelations.hasNext()) {
      Object portOrRelation=portsAndRelations.next();
      if (portOrRelation instanceof Relation) {
        Relation otherRelation=(Relation)portOrRelation;
        if (otherRelation != null && !otherRelation.isPersistent()) {
          continue;
        }
        if (visitedRelations.contains(otherRelation)) {
          continue;
        }
        if (_commonImplier(relation,depth,otherRelation,depth)) {
          continue;
        }
        if ((filter == null) || (filter.contains(relation) && filter.contains(otherRelation))) {
          String relationName;
          if (relation.getContainer() == this) {
            relationName=relation.getName();
          }
 else {
            if (deepContains(relation)) {
              relationName=relation.getName(this);
            }
 else {
              _recordLevelCrossingLink(null,relation,otherRelation,0);
              continue;
            }
          }
          String otherRelationName;
          if (otherRelation.getContainer() == this) {
            otherRelationName=otherRelation.getName();
          }
 else {
            _recordLevelCrossingLink(null,relation,otherRelation,0);
            continue;
          }
          result.append(_getIndentPrefix(depth) + "String_Node_Str" + relationName+ "String_Node_Str"+ otherRelationName+ "String_Node_Str");
        }
      }
    }
  }
  return result.toString();
}

Fixed version (ground truth):
/** 
 * Return a sequence of MoML link attributes that describe any link between objects (ports, entities, and relations) that are present in the <i>filter</i> argument.  Both ends of the link must be present in <i>filter</i> for MoML to be generated for that link.  The <i>filter</i> argument normally contains ports, relations, and entities that are contained by this composite entity. If it contains an entity, then that is equivalent to containing all the ports contained by that entity.  It is recommended to use a collection class (such as HashSet) for which the contains() method is efficient. <p> If the filter argument is null, then return all the links that this composite is responsible for (i.e., apply no filtering).  If the argument is an empty collection, then return none of the links.  The links that this entity is responsible for are the inside links of its ports, and links on ports contained by contained entities. <p> If any link is found where both ends of the link are inherited objects, then that link is not exported. It is assumed that the base class will export that link.  For this purpose, a port of a contained entity is deemed to be an inherited object if it is itself a class element <i>and</i> its container is an inherited object.
 * @param depth The depth below the MoML export in the hierarchy.
 * @param filter A collection of ports, parameters, and entities, ornull to apply no filtering.
 * @return A string that describes the links present in the<i>filter</i>.
 * @exception IOException If an I/O error occurs.
 */
public String exportLinks(int depth,Collection filter) throws IOException {
  StringBuffer result=new StringBuffer();
  Iterator ports=portList().iterator();
  while (ports.hasNext()) {
    ComponentPort port=(ComponentPort)ports.next();
    if (port == null || !port.isPersistent()) {
      continue;
    }
    Iterator relations=port.insideRelationList().iterator();
    int index=-1;
    boolean useIndex=false;
    while (relations.hasNext()) {
      index++;
      ComponentRelation relation=(ComponentRelation)relations.next();
      if (relation != null && !relation.isPersistent()) {
        continue;
      }
      if (relation == null) {
        useIndex=true;
        continue;
      }
      if (_commonImplier(relation,depth,port,depth)) {
        continue;
      }
      if ((filter == null) || (filter.contains(relation) && (filter.contains(port) || filter.contains(port.getContainer())))) {
        if (relation != null && !relation.isPersistent()) {
          continue;
        }
        String relationName;
        if (relation.getContainer() == this) {
          relationName=relation.getName();
        }
 else {
          if (deepContains(relation)) {
            relationName=relation.getName(this);
          }
 else {
            _recordLevelCrossingLink(port,relation,null,index);
            continue;
          }
        }
        String escapedPortName=StringUtilities.escapeForXML(port.getName());
        String escapedRelationName=StringUtilities.escapeForXML(relationName);
        if (useIndex) {
          useIndex=false;
          result.append(_getIndentPrefix(depth) + "String_Node_Str" + escapedPortName+ "String_Node_Str"+ index+ "String_Node_Str"+ escapedRelationName+ "String_Node_Str");
        }
 else {
          result.append(_getIndentPrefix(depth) + "String_Node_Str" + escapedPortName+ "String_Node_Str"+ escapedRelationName+ "String_Node_Str");
        }
      }
    }
  }
  Iterator entities=entityList().iterator();
  while (entities.hasNext()) {
    ComponentEntity entity=(ComponentEntity)entities.next();
    if (entity == null || !entity.isPersistent()) {
      continue;
    }
    ports=entity.portList().iterator();
    while (ports.hasNext()) {
      ComponentPort port=(ComponentPort)ports.next();
      if (port == null || !port.isPersistent()) {
        continue;
      }
      Iterator relations=port.linkedRelationList().iterator();
      int index=-1;
      boolean useIndex=false;
      while (relations.hasNext()) {
        index++;
        ComponentRelation relation=(ComponentRelation)relations.next();
        if (relation != null && !relation.isPersistent()) {
          continue;
        }
        if (relation == null) {
          useIndex=true;
          continue;
        }
        if (port.getDerivedLevel() <= (depth + 1) && _commonImplier(relation,depth,port.getContainer(),depth)) {
          continue;
        }
        if ((filter == null) || (filter.contains(relation) && (filter.contains(port) || filter.contains(port.getContainer())))) {
          if (relation == null || !relation.isPersistent()) {
            continue;
          }
          String relationName;
          if (relation.getContainer() == this) {
            relationName=relation.getName();
          }
 else {
            if (deepContains(relation)) {
              relationName=relation.getName(this);
            }
 else {
              _recordLevelCrossingLink(port,relation,null,index);
              continue;
            }
          }
          String escapedName=StringUtilities.escapeForXML(entity.getName());
          String escapedPortName=StringUtilities.escapeForXML(port.getName());
          String escapedRelationName=StringUtilities.escapeForXML(relationName);
          if (useIndex) {
            useIndex=false;
            result.append(_getIndentPrefix(depth) + "String_Node_Str" + escapedName+ "String_Node_Str"+ escapedPortName+ "String_Node_Str"+ index+ "String_Node_Str"+ escapedRelationName+ "String_Node_Str");
          }
 else {
            result.append(_getIndentPrefix(depth) + "String_Node_Str" + escapedName+ "String_Node_Str"+ escapedPortName+ "String_Node_Str"+ escapedRelationName+ "String_Node_Str");
          }
        }
      }
    }
  }
  Set visitedRelations=new HashSet();
  Iterator relations=relationList().iterator();
  while (relations.hasNext()) {
    ComponentRelation relation=(ComponentRelation)relations.next();
    visitedRelations.add(relation);
    if (relation == null || !relation.isPersistent()) {
      continue;
    }
    Iterator portsAndRelations=relation.linkedObjectsList().iterator();
    while (portsAndRelations.hasNext()) {
      Object portOrRelation=portsAndRelations.next();
      if (portOrRelation instanceof Relation) {
        Relation otherRelation=(Relation)portOrRelation;
        if (otherRelation == null || !otherRelation.isPersistent()) {
          continue;
        }
        if (visitedRelations.contains(otherRelation)) {
          continue;
        }
        if (_commonImplier(relation,depth,otherRelation,depth)) {
          continue;
        }
        if ((filter == null) || (filter.contains(relation) && filter.contains(otherRelation))) {
          String relationName;
          if (relation.getContainer() == this) {
            relationName=relation.getName();
          }
 else {
            if (deepContains(relation)) {
              relationName=relation.getName(this);
            }
 else {
              _recordLevelCrossingLink(null,relation,otherRelation,0);
              continue;
            }
          }
          String otherRelationName;
          if (otherRelation.getContainer() == this) {
            otherRelationName=otherRelation.getName();
          }
 else {
            _recordLevelCrossingLink(null,relation,otherRelation,0);
            continue;
          }
          result.append(_getIndentPrefix(depth) + "String_Node_Str" + relationName+ "String_Node_Str"+ otherRelationName+ "String_Node_Str");
        }
      }
    }
  }
  return result.toString();
}