Program: 73357
Project: 73357
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). The result is a new entity with clones of the ports of the original entity.  The ports are set to the ports of the new entity. This method gets read access on the workspace associated with this object.
 * @param workspace The workspace for the cloned object.
 * @exception CloneNotSupportedException If cloned ports cannot haveas their container the cloned entity (this should not occur), or if one of the attributes cannot be cloned.
 * @return The new Entity.
 */
public Object clone(Workspace workspace) throws CloneNotSupportedException {
  try {
    workspace().getReadAccess();
    Entity newEntity=(Entity)super.clone(workspace);
    newEntity._portList=new NamedList(newEntity);
    Iterator ports=portList().iterator();
    while (ports.hasNext()) {
      Port port=(Port)ports.next();
      Port newPort=(Port)port.clone(workspace);
      try {
        newPort.setContainer(newEntity);
      }
 catch (      KernelException ex) {
        workspace.remove(newEntity);
        throw new InvalidStateException(this,"String_Node_Str" + ex.getMessage());
      }
    }
    Class myClass=getClass();
    Field[] fields=myClass.getFields();
    for (int i=0; i < fields.length; i++) {
      try {
        if (fields[i].get(newEntity) instanceof Port) {
          String portName=((Port)fields[i].get(this)).getName();
          Port port=newEntity.getPort(portName);
          if (port == null) {
            throw new IllegalActionException(this,"String_Node_Str" + portName + "String_Node_Str");
          }
          fields[i].set(newEntity,port);
        }
      }
 catch (      Exception ex) {
        CloneNotSupportedException cloneException=new CloneNotSupportedException("String_Node_Str" + fields[i].getName() + "String_Node_Str");
        cloneException.initCause(ex);
        throw cloneException;
      }
    }
    _cloneFixAttributeFields(newEntity);
    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). The result is a new entity with clones of the ports of the original entity.  The ports are set to the ports of the new entity. This method gets read access on the workspace associated with this object.
 * @param workspace The workspace for the cloned object.
 * @exception CloneNotSupportedException If cloned ports cannot haveas their container the cloned entity (this should not occur), or if one of the attributes cannot be cloned.
 * @return The new Entity.
 */
public Object clone(Workspace workspace) throws CloneNotSupportedException {
  try {
    workspace().getReadAccess();
    Entity newEntity=(Entity)super.clone(workspace);
    newEntity._portList=new NamedList(newEntity);
    Iterator ports=portList().iterator();
    while (ports.hasNext()) {
      Port port=(Port)ports.next();
      Port newPort=(Port)port.clone(workspace);
      try {
        newPort.setContainer(newEntity);
      }
 catch (      KernelException ex) {
        workspace.remove(newEntity);
        throw new InvalidStateException(this,"String_Node_Str" + ex.getMessage());
      }
    }
    Class myClass=getClass();
    Field[] fields=myClass.getFields();
    for (int i=0; i < fields.length; i++) {
      try {
        if (fields[i].get(newEntity) instanceof Port) {
          String portName=((Port)fields[i].get(this)).getName();
          Port port=newEntity.getPort(portName);
          if (port == null) {
            throw new IllegalActionException(this,"String_Node_Str" + portName + "String_Node_Str");
          }
          fields[i].set(newEntity,port);
        }
      }
 catch (      Throwable throwable) {
        CloneNotSupportedException cloneException=new CloneNotSupportedException("String_Node_Str" + fields[i].getName() + "String_Node_Str");
        cloneException.initCause(throwable);
        throw cloneException;
      }
    }
    _cloneFixAttributeFields(newEntity);
    return newEntity;
  }
  finally {
    workspace().doneReading();
  }
}