Program: 72596
Project: 72596
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.
 */
@Override 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"){
    @Override public NamedObj getLocality(){
      return ReflectComposite.this;
    }
    @Override protected void _execute() throws Exception {
synchronized (this) {
        try {
          workspace().getWriteAccess();
          ComponentEntity entity=null;
          List priorEntities=entityList();
          Iterator priors=priorEntities.iterator();
          while (priors.hasNext()) {
            ComponentEntity prior=(ComponentEntity)priors.next();
            if (priors.hasNext()) {
              prior.setContainer(null);
            }
 else {
              entity=prior;
            }
          }
          if (entity == null) {
            return;
          }
          Iterator entityPorts=entity.portList().iterator();
          while (entityPorts.hasNext()) {
            ComponentPort insidePort=(ComponentPort)entityPorts.next();
            if ((!_mirrorParameterPorts && insidePort instanceof ParameterPort) || !(insidePort instanceof MirrorPort)) {
              continue;
            }
            String name=insidePort.getName();
            IOPort newPort=(IOPort)getPort(name);
            if (newPort == null) {
              newPort=(IOPort)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);
            }
          }
        }
  finally {
          workspace().doneWriting();
        }
      }
    }
  }
;
  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.
 */
@Override 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"){
    @Override public NamedObj getLocality(){
      return ReflectComposite.this;
    }
    @Override protected void _execute() throws Exception {
synchronized (ReflectComposite.this) {
        try {
          workspace().getWriteAccess();
          ComponentEntity entity=null;
          List priorEntities=entityList();
          Iterator priors=priorEntities.iterator();
          while (priors.hasNext()) {
            ComponentEntity prior=(ComponentEntity)priors.next();
            if (priors.hasNext()) {
              prior.setContainer(null);
            }
 else {
              entity=prior;
            }
          }
          if (entity == null) {
            return;
          }
          Iterator entityPorts=entity.portList().iterator();
          while (entityPorts.hasNext()) {
            ComponentPort insidePort=(ComponentPort)entityPorts.next();
            if (!_mirrorPort(insidePort)) {
              continue;
            }
            String name=insidePort.getName();
            IOPort newPort=(IOPort)getPort(name);
            if (newPort == null) {
              newPort=(IOPort)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);
            }
          }
        }
  finally {
          workspace().doneWriting();
        }
      }
    }
  }
;
  requestChange(request);
}