Program: 72896
Project: 72896
Buggy source:
/** 
 * Override the base class to throw an exception if renaming this variable results in an error evaluating some variable that depends on it. In this case, the name remains unchanged.
 * @exception IllegalActionException If the name contains a periodor if this variable is referenced in some other expression.
 * @exception NameDuplicationException If there is already anattribute with the same name in the container.
 */
public void setName(String name) throws IllegalActionException, NameDuplicationException {
  String previousName=getName();
  LinkedList<ValueListener> changed=new LinkedList<ValueListener>();
  if (previousName != null && !previousName.equals(name)) {
    try {
      if (_valueListeners != null) {
        Iterator listeners=_valueListeners.iterator();
        while (listeners.hasNext()) {
          ValueListener listener=(ValueListener)listeners.next();
          if (listener instanceof Variable) {
            ParseTreeFreeVariableRenamer renamer=new ParseTreeFreeVariableRenamer();
            ((Variable)listener)._parseIfNecessary();
            renamer.renameVariables(((Variable)listener)._parseTree,(Variable)listener,this,name);
            ParseTreeWriter writer=new ParseTreeWriter();
            ((Variable)listener).setExpression(writer.parseTreeToExpression(((Variable)listener)._parseTree));
            changed.add(listener);
          }
        }
      }
      super.setName(name);
      _invalidateShadowedSettables(getContainer());
      validate();
    }
 catch (    IllegalActionException ex) {
      super.setName(previousName);
      Iterator listeners=changed.iterator();
      while (listeners.hasNext()) {
        Variable listener=(Variable)listeners.next();
        ParseTreeFreeVariableRenamer renamer=new ParseTreeFreeVariableRenamer();
        renamer.renameVariables(listener._parseTree,listener,this,previousName);
        ParseTreeWriter writer=new ParseTreeWriter();
        listener.setExpression(writer.parseTreeToExpression(listener._parseTree));
      }
      validate();
      throw ex;
    }
  }
 else {
    super.setName(name);
  }
}

Fixed version (ground truth):
/** 
 * Override the base class to throw an exception if renaming this variable results in an error evaluating some variable that depends on it. In this case, the name remains unchanged.
 * @exception IllegalActionException If the name contains a periodor if this variable is referenced in some other expression.
 * @exception NameDuplicationException If there is already anattribute with the same name in the container.
 */
public void setName(String name) throws IllegalActionException, NameDuplicationException {
  String previousName=getName();
  LinkedList<ValueListener> changed=new LinkedList<ValueListener>();
  if (previousName != null && !previousName.equals(name)) {
    try {
      if (_valueListeners != null) {
        Iterator listeners=_valueListeners.iterator();
        while (listeners.hasNext()) {
          ValueListener listener=(ValueListener)listeners.next();
          if (listener instanceof Variable) {
            ParseTreeFreeVariableRenamer renamer=new ParseTreeFreeVariableRenamer();
            ((Variable)listener)._parseIfNecessary();
            renamer.renameVariables(((Variable)listener)._parseTree,(Variable)listener,this,name);
            ParseTreeWriter writer=new ParseTreeWriter();
            writer.setStringMode(((Variable)listener).isStringMode());
            ((Variable)listener).setExpression(writer.parseTreeToExpression(((Variable)listener)._parseTree));
            changed.add(listener);
          }
        }
      }
      super.setName(name);
      _invalidateShadowedSettables(getContainer());
      validate();
    }
 catch (    IllegalActionException ex) {
      super.setName(previousName);
      Iterator listeners=changed.iterator();
      while (listeners.hasNext()) {
        Variable listener=(Variable)listeners.next();
        ParseTreeFreeVariableRenamer renamer=new ParseTreeFreeVariableRenamer();
        renamer.renameVariables(listener._parseTree,listener,this,previousName);
        ParseTreeWriter writer=new ParseTreeWriter();
        listener.setExpression(writer.parseTreeToExpression(listener._parseTree));
      }
      validate();
      throw ex;
    }
  }
 else {
    super.setName(name);
  }
}