Program: 75294
Project: 75294
Buggy source:
/** 
 * Override the base class to queue a change request to remove any previously contained entity and its mirrored ports, and to mirror the ports of the added entity.
 * @param entity Entity to contain.
 * @exception IllegalActionException If the entity has no name, or theaction would result in a recursive containment structure, or the argument does not implement the TypedActor interface.
 * @exception NameDuplicationException If the name collides with a namealready on the actor contents list, or if the added element is a class definition.
 */
protected void _addEntity(ComponentEntity entity) throws IllegalActionException, NameDuplicationException {
  if (entity.isClassDefinition()) {
    throw new IllegalActionException(this,"String_Node_Str" + "String_Node_Str");
  }
  super._addEntity(entity);
  if (isDerived() || _cloning) {
    return;
  }
  ChangeRequest request=new ChangeRequest(this,"String_Node_Str"){
    protected void _execute() throws Exception {
synchronized (this) {
        ComponentEntity entity=null;
        Iterator priors=entityList().iterator();
        while (priors.hasNext()) {
          ComponentEntity prior=(ComponentEntity)priors.next();
          if (priors.hasNext()) {
            prior.setContainer(null);
          }
 else {
            entity=prior;
          }
        }
        if (entity == null) {
          return;
        }
        int count=1;
        Iterator entityPorts=entity.portList().iterator();
        while (entityPorts.hasNext()) {
          ComponentPort insidePort=(ComponentPort)entityPorts.next();
          String name=insidePort.getName();
          IteratePort newPort=(IteratePort)getPort(name);
          if (newPort == null) {
            newPort=(IteratePort)newPort(name);
          }
          if (insidePort instanceof IOPort) {
            IOPort castPort=(IOPort)insidePort;
            newPort.setMultiport(castPort.isMultiport());
            newPort.setInput(castPort.isInput());
            newPort.setOutput(castPort.isOutput());
          }
          List connectedPorts=insidePort.connectedPortList();
          if (!connectedPorts.contains(newPort)) {
            ComponentRelation relation=newRelation(uniqueName("String_Node_Str"));
            newPort.link(relation);
            insidePort.liberalLink(relation);
          }
        }
      }
    }
  }
;
  requestChange(request);
}

Fixed version (ground truth):
/** 
 * Override the base class to queue a change request to remove any previously contained entity and its mirrored ports, and to mirror the ports of the added entity.
 * @param entity Entity to contain.
 * @exception IllegalActionException If the entity has no name, or theaction would result in a recursive containment structure, or the argument does not implement the TypedActor interface.
 * @exception NameDuplicationException If the name collides with a namealready on the actor contents list, or if the added element is a class definition.
 */
protected void _addEntity(ComponentEntity entity) throws IllegalActionException, NameDuplicationException {
  if (entity.isClassDefinition()) {
    throw new IllegalActionException(this,"String_Node_Str" + "String_Node_Str");
  }
  super._addEntity(entity);
  ChangeRequest request=new ChangeRequest(this,"String_Node_Str"){
    protected void _execute() throws Exception {
synchronized (this) {
        ComponentEntity entity=null;
        Iterator priors=entityList().iterator();
        while (priors.hasNext()) {
          ComponentEntity prior=(ComponentEntity)priors.next();
          if (priors.hasNext() && !isDerived()) {
            prior.setContainer(null);
          }
 else {
            entity=prior;
          }
        }
        if (entity == null) {
          return;
        }
        int count=1;
        Iterator entityPorts=entity.portList().iterator();
        while (entityPorts.hasNext()) {
          ComponentPort insidePort=(ComponentPort)entityPorts.next();
          String name=insidePort.getName();
          IteratePort newPort=(IteratePort)getPort(name);
          if (newPort == null) {
            newPort=(IteratePort)newPort(name);
          }
          if (insidePort instanceof IOPort) {
            IOPort castPort=(IOPort)insidePort;
            newPort.setMultiport(castPort.isMultiport());
            newPort.setInput(castPort.isInput());
            newPort.setOutput(castPort.isOutput());
          }
          List connectedPorts=insidePort.connectedPortList();
          if (!connectedPorts.contains(newPort)) {
            ComponentRelation relation=newRelation(uniqueName("String_Node_Str"));
            newPort.link(relation);
            insidePort.link(relation);
          }
        }
      }
    }
  }
;
  requestChange(request);
}