Program: 74374
Project: 74374
Buggy source:
/** 
 * Clone the object into the specified workspace. The new object is <i>not</i> added to the directory of that workspace (you must do this yourself if you want it there). This method gets read access on the workspace associated with this object.
 * @param workspace The workspace for the cloned object.
 * @exception CloneNotSupportedException If one of the attributescannot be cloned.
 * @return A new CompositeEntity.
 */
public Object clone(Workspace workspace) throws CloneNotSupportedException {
  try {
    workspace().getReadAccess();
    CompositeEntity newEntity=(CompositeEntity)super.clone(workspace);
    newEntity._containedEntities=new NamedList(newEntity);
    newEntity._containedRelations=new NamedList(newEntity);
    Iterator relations=relationList().iterator();
    while (relations.hasNext()) {
      ComponentRelation relation=(ComponentRelation)relations.next();
      ComponentRelation newRelation=(ComponentRelation)relation.clone(workspace);
      try {
        newRelation.setContainer(newEntity);
      }
 catch (      KernelException ex) {
        throw new CloneNotSupportedException("String_Node_Str" + ex.getMessage());
      }
    }
    Iterator classes=classDefinitionList().iterator();
    while (classes.hasNext()) {
      ComponentEntity classDefinition=(ComponentEntity)classes.next();
      ComponentEntity newSubentity=(ComponentEntity)classDefinition.clone(workspace);
      try {
        newSubentity.setContainer(newEntity);
      }
 catch (      KernelException ex) {
        throw new CloneNotSupportedException("String_Node_Str" + KernelException.stackTraceToString(ex));
      }
    }
    Iterator entities=entityList().iterator();
    while (entities.hasNext()) {
      ComponentEntity entity=(ComponentEntity)entities.next();
      ComponentEntity newSubentity=(ComponentEntity)entity.clone(workspace);
      try {
        newSubentity.setContainer(newEntity);
      }
 catch (      KernelException ex) {
        throw new CloneNotSupportedException("String_Node_Str" + KernelException.stackTraceToString(ex));
      }
      Iterator ports=entity.portList().iterator();
      while (ports.hasNext()) {
        ComponentPort port=(ComponentPort)ports.next();
        Enumeration linkedRelations=port.linkedRelations();
        while (linkedRelations.hasMoreElements()) {
          ComponentRelation rel=(ComponentRelation)linkedRelations.nextElement();
          if (rel != null) {
            ComponentRelation newRelation=newEntity.getRelation(rel.getName());
            Port newPort=newSubentity.getPort(port.getName());
            try {
              newPort.link(newRelation);
            }
 catch (            IllegalActionException ex) {
              throw new CloneNotSupportedException("String_Node_Str" + ex.getMessage());
            }
          }
        }
      }
    }
    Iterator ports=portList().iterator();
    while (ports.hasNext()) {
      ComponentPort port=(ComponentPort)ports.next();
      relations=port.insideRelationList().iterator();
      while (relations.hasNext()) {
        Relation relation=(Relation)relations.next();
        ComponentRelation newRelation=newEntity.getRelation(relation.getName());
        Port newPort=newEntity.getPort(port.getName());
        try {
          newPort.link(newRelation);
        }
 catch (        IllegalActionException ex) {
          throw new CloneNotSupportedException("String_Node_Str" + ex.getMessage());
        }
      }
    }
    return newEntity;
  }
  finally {
    workspace().doneReading();
  }
}

Fixed version (ground truth):
/** 
 * Clone the object into the specified workspace. The new object is <i>not</i> added to the directory of that workspace (you must do this yourself if you want it there). This method gets read access on the workspace associated with this object.
 * @param workspace The workspace for the cloned object.
 * @exception CloneNotSupportedException If one of the attributescannot be cloned.
 * @return A new CompositeEntity.
 */
public Object clone(Workspace workspace) throws CloneNotSupportedException {
  try {
    workspace().getReadAccess();
    CompositeEntity newEntity=(CompositeEntity)super.clone(workspace);
    newEntity._containedEntities=new NamedList(newEntity);
    newEntity._containedRelations=new NamedList(newEntity);
    Iterator relations=relationList().iterator();
    while (relations.hasNext()) {
      ComponentRelation relation=(ComponentRelation)relations.next();
      ComponentRelation newRelation=(ComponentRelation)relation.clone(workspace);
      try {
        newRelation.setContainer(newEntity);
        Enumeration links=relation._linkList.getContainers();
        while (links.hasMoreElements()) {
          Object link=links.nextElement();
          if (link instanceof Relation) {
            Relation farRelation=newEntity.getRelation(((Nameable)link).getName());
            if (farRelation != null) {
              newRelation.link(farRelation);
            }
          }
        }
      }
 catch (      KernelException ex) {
        throw new CloneNotSupportedException("String_Node_Str" + ex.getMessage());
      }
    }
    Iterator classes=classDefinitionList().iterator();
    while (classes.hasNext()) {
      ComponentEntity classDefinition=(ComponentEntity)classes.next();
      ComponentEntity newSubentity=(ComponentEntity)classDefinition.clone(workspace);
      try {
        newSubentity.setContainer(newEntity);
      }
 catch (      KernelException ex) {
        throw new CloneNotSupportedException("String_Node_Str" + KernelException.stackTraceToString(ex));
      }
    }
    Iterator entities=entityList().iterator();
    while (entities.hasNext()) {
      ComponentEntity entity=(ComponentEntity)entities.next();
      ComponentEntity newSubentity=(ComponentEntity)entity.clone(workspace);
      try {
        newSubentity.setContainer(newEntity);
      }
 catch (      KernelException ex) {
        throw new CloneNotSupportedException("String_Node_Str" + KernelException.stackTraceToString(ex));
      }
      Iterator ports=entity.portList().iterator();
      while (ports.hasNext()) {
        ComponentPort port=(ComponentPort)ports.next();
        Enumeration linkedRelations=port.linkedRelations();
        while (linkedRelations.hasMoreElements()) {
          ComponentRelation rel=(ComponentRelation)linkedRelations.nextElement();
          if (rel != null) {
            ComponentRelation newRelation=newEntity.getRelation(rel.getName());
            Port newPort=newSubentity.getPort(port.getName());
            try {
              newPort.link(newRelation);
            }
 catch (            IllegalActionException ex) {
              throw new CloneNotSupportedException("String_Node_Str" + ex.getMessage());
            }
          }
        }
      }
    }
    Iterator ports=portList().iterator();
    while (ports.hasNext()) {
      ComponentPort port=(ComponentPort)ports.next();
      relations=port.insideRelationList().iterator();
      while (relations.hasNext()) {
        Relation relation=(Relation)relations.next();
        ComponentRelation newRelation=newEntity.getRelation(relation.getName());
        Port newPort=newEntity.getPort(port.getName());
        try {
          newPort.link(newRelation);
        }
 catch (        IllegalActionException ex) {
          throw new CloneNotSupportedException("String_Node_Str" + ex.getMessage());
        }
      }
    }
    return newEntity;
  }
  finally {
    workspace().doneReading();
  }
}