Program: 75367
Project: 75367
Buggy source:
/** 
 * Specify the container, adding the entity to the list of entities in the container.  If the container already contains an entity with the same name, then throw an exception and do not make any changes.  Similarly, if the container is not in the same workspace as this entity, throw an exception.  If this entity is a class element and the proposed container does not match the current container, then also throw an exception. If the entity is already contained by the container, do nothing. If this entity already has a container, remove it from that container first.  Otherwise, remove it from the directory of the workspace, if it is present. If the argument is null, then unlink the ports of the entity from any relations and remove it from its container. It is not added to the workspace directory, so this could result in this entity being garbage collected. Derived classes may further constrain the container to subclasses of CompositeEntity by overriding the protected method _checkContainer(). This method validates all deeply contained instances of Settable, since they may no longer be valid in the new context.  This method is write-synchronized to the workspace and increments its version number.
 * @param container The proposed container.
 * @exception IllegalActionException If the action would result in arecursive containment structure, or if this entity and container are not in the same workspace, or if the protected method _checkContainer() throws it, or if a contained Settable becomes invalid and the error handler throws it.
 * @exception NameDuplicationException If the name of this entitycollides with a name already in the container.
 * @see #isClassElement()
 */
public void setContainer(Prototype container) throws IllegalActionException, NameDuplicationException {
  if (container != null && _workspace != container.workspace()) {
    throw new IllegalActionException(this,container,"String_Node_Str");
  }
  try {
    _workspace.getWriteAccess();
    _checkContainer(container);
    CompositeEntity previousContainer=(CompositeEntity)getContainer();
    if (previousContainer == container)     return;
    if (container != null) {
      ((CompositeEntity)container)._addEntity(this);
      if (previousContainer == null) {
        _workspace.remove(this);
      }
    }
    super.setContainer(container);
    if (previousContainer != null) {
      previousContainer._removeEntity(this);
    }
    if (container == null) {
      Iterator ports=portList().iterator();
      while (ports.hasNext()) {
        Port port=(Port)ports.next();
        port.unlinkAll();
      }
    }
 else {
      ((CompositeEntity)container)._finishedAddEntity(this);
      setModifiedFromClass(true);
    }
    validateSettables();
  }
  finally {
    _workspace.doneWriting();
  }
}

Fixed version (ground truth):
/** 
 * Backward compatibility form of this method. Before the existence of the Prototype class, the argument to setContainer() was a CompositeEntity.  Subclasses override that method. So that they continue to work, this method is provided to bridge the two.
 * @param container The proposed container.
 * @exception IllegalActionException If the action would result in arecursive containment structure, or if this entity and container are not in the same workspace, or if the protected method _checkContainer() throws it, or if a contained Settable becomes invalid and the error handler throws it.
 * @exception NameDuplicationException If the name of this entitycollides with a name already in the container.
 * @see #isClassElement()
 */
public void setContainer(CompositeEntity container) throws IllegalActionException, NameDuplicationException {
  setContainer((Prototype)container);
}