Program: 74688
Project: 74688
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). NOTE: This will not work if there are level-crossing transitions. The result is an entity with clones of the ports of the original entity, the contained entities, and the contained relations. The ports of the returned entity are not connected to anything. The connections of the relations are duplicated in the new entity, unless they cross levels, in which case an exception is thrown. This method gets read access on the workspace associated with this object.
 * @param workspace The workspace for the cloned object.
 * @exception CloneNotSupportedException If the entity containslevel crossing transitions so that its connections cannot be cloned, or if one of the attributes cannot 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) {
            if (rel.getContainer() != this) {
              throw new CloneNotSupportedException("String_Node_Str" + "String_Node_Str" + "String_Node_Str" + rel + "String_Node_Str"+ rel.getContainer()+ "String_Node_Str"+ this);
            }
            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);
      }
 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();
  }
}