Program: 74291
Project: 74291
Buggy source:
/** 
 * Set the width of this relation and all relations in its relation group. The width is the number of channels that the relation represents.  If the argument is equal to the value of WIDTH_TO_INFER, then the relation becomes a bus with unspecified width, and the width will be inferred from the way the relation is used (but will never be less than zero). This method invalidates the resolved types on the director of the container, if there is one, and notifies each connected actor that its connections have changed. This method write-synchronizes on the workspace.
 * @param width The width of the relation.
 * @exception IllegalActionException If the argument is not zero, one,or equal to WIDTH_TO_INFER and the relation is linked to a non-multiport. Or when the argument is less than zero and different from WIDTH_TO_INFER.
 * @see ptolemy.kernel.util.Workspace#getWriteAccess()
 * @see #getWidth()
 */
private void _setWidth(int width) throws IllegalActionException {
  if (_USE_NEW_WIDTH_INFERENCE_ALGO) {
    if (width == _width) {
      return;
    }
    try {
      _workspace.getWriteAccess();
      if (width < 0 && width != WIDTH_TO_INFER) {
        throw new IllegalActionException(this,"String_Node_Str" + width + "String_Node_Str");
      }
      _width=width;
      Iterator<?> relations=relationGroupList().iterator();
      while (!_suppressWidthPropagation && relations.hasNext()) {
        IORelation relation=(IORelation)relations.next();
        if (relation == this) {
          continue;
        }
        try {
          relation._suppressWidthPropagation=true;
          relation.width.setToken(new IntToken(width));
        }
  finally {
          relation._suppressWidthPropagation=false;
        }
      }
      Nameable container=getContainer();
      if (container instanceof CompositeActor) {
        Director director=((CompositeActor)container).getDirector();
        if (director != null) {
          director.invalidateSchedule();
          director.invalidateResolvedTypes();
          director.notifyConnectivityChange();
        }
      }
    }
  finally {
      _workspace.doneWriting();
    }
  }
 else {
    if (width == _width) {
      return;
    }
    try {
      _workspace.getWriteAccess();
      if (width <= 0) {
        try {
          _inferWidth();
        }
 catch (        InvalidStateException ex) {
          throw new IllegalActionException(this,ex,"String_Node_Str" + "String_Node_Str");
        }
      }
      _width=width;
      Iterator relations=relationGroupList().iterator();
      while (!_suppressWidthPropagation && relations.hasNext()) {
        IORelation relation=(IORelation)relations.next();
        if (relation == this) {
          continue;
        }
        try {
          relation._suppressWidthPropagation=true;
          relation.width.setToken(new IntToken(width));
        }
  finally {
          relation._suppressWidthPropagation=false;
        }
      }
      Iterator ports=linkedPortList().iterator();
      while (ports.hasNext()) {
        IOPort p=(IOPort)ports.next();
        Entity portContainer=(Entity)p.getContainer();
        if (portContainer != null) {
          portContainer.connectionsChanged(p);
        }
      }
      Nameable container=getContainer();
      if (container instanceof CompositeActor) {
        Director director=((CompositeActor)container).getDirector();
        if (director != null) {
          director.invalidateSchedule();
          director.invalidateResolvedTypes();
        }
      }
    }
  finally {
      _workspace.doneWriting();
    }
  }
}

Fixed version (ground truth):
/** 
 * Set the width of this relation and all relations in its relation group. The width is the number of channels that the relation represents.  If the argument is equal to the value of WIDTH_TO_INFER, then the relation becomes a bus with unspecified width, and the width will be inferred from the way the relation is used (but will never be less than zero). This method invalidates the resolved types on the director of the container, if there is one, and notifies each connected actor that its connections have changed. This method write-synchronizes on the workspace.
 * @param width The width of the relation.
 * @exception IllegalActionException If the argument is not zero, one,or equal to WIDTH_TO_INFER and the relation is linked to a non-multiport. Or when the argument is less than zero and different from WIDTH_TO_INFER.
 * @see ptolemy.kernel.util.Workspace#getWriteAccess()
 * @see #getWidth()
 */
private void _setWidth(int width) throws IllegalActionException {
  if (_USE_NEW_WIDTH_INFERENCE_ALGO) {
    if (width == _width) {
      return;
    }
    try {
      _workspace.getWriteAccess();
      if (width < 0 && width != WIDTH_TO_INFER) {
        throw new IllegalActionException(this,"String_Node_Str" + width + "String_Node_Str");
      }
      _width=width;
      Iterator<?> relations=relationGroupList().iterator();
      while (!_suppressWidthPropagation && relations.hasNext()) {
        IORelation relation=(IORelation)relations.next();
        if (relation == this) {
          continue;
        }
        try {
          relation._suppressWidthPropagation=true;
          relation.width.setToken(new IntToken(width));
        }
  finally {
          relation._suppressWidthPropagation=false;
        }
      }
      for (      Object port : linkedPortList()) {
        IOPort p=(IOPort)port;
        Entity portContainer=(Entity)p.getContainer();
        if (portContainer != null) {
          portContainer.connectionsChanged(p);
        }
      }
      Nameable container=getContainer();
      if (container instanceof CompositeActor) {
        Director director=((CompositeActor)container).getDirector();
        if (director != null) {
          director.invalidateSchedule();
          director.invalidateResolvedTypes();
          director.notifyConnectivityChange();
        }
      }
    }
  finally {
      _workspace.doneWriting();
    }
  }
 else {
    if (width == _width) {
      return;
    }
    try {
      _workspace.getWriteAccess();
      if (width <= 0) {
        try {
          _inferWidth();
        }
 catch (        InvalidStateException ex) {
          throw new IllegalActionException(this,ex,"String_Node_Str" + "String_Node_Str");
        }
      }
      _width=width;
      Iterator relations=relationGroupList().iterator();
      while (!_suppressWidthPropagation && relations.hasNext()) {
        IORelation relation=(IORelation)relations.next();
        if (relation == this) {
          continue;
        }
        try {
          relation._suppressWidthPropagation=true;
          relation.width.setToken(new IntToken(width));
        }
  finally {
          relation._suppressWidthPropagation=false;
        }
      }
      Iterator ports=linkedPortList().iterator();
      while (ports.hasNext()) {
        IOPort p=(IOPort)ports.next();
        Entity portContainer=(Entity)p.getContainer();
        if (portContainer != null) {
          portContainer.connectionsChanged(p);
        }
      }
      Nameable container=getContainer();
      if (container instanceof CompositeActor) {
        Director director=((CompositeActor)container).getDirector();
        if (director != null) {
          director.invalidateSchedule();
          director.invalidateResolvedTypes();
        }
      }
    }
  finally {
      _workspace.doneWriting();
    }
  }
}