Program: 75302
Project: 75302
Buggy source:
/** 
 * Delete the entity after verifying that it is contained (deeply) by the current environment.
 * @param entityName The relative or absolute name of theentity to delete.
 * @return The deleted object.
 * @exception Exception If there is no such entity or if the entityis defined in the class definition.
 */
private NamedObj _deleteEntity(String entityName) throws Exception {
  ComponentEntity toDelete=_searchForEntity(entityName,_current);
  if (toDelete == null) {
    throw new XmlException("String_Node_Str" + entityName,_currentExternalEntity(),_parser.getLineNumber(),_parser.getColumnNumber());
  }
  if (toDelete.isDerived()) {
    throw new IllegalActionException(toDelete,"String_Node_Str");
  }
  StringBuffer undoMoML=new StringBuffer();
  try {
    Iterator heritage=toDelete.getDerivedList().iterator();
    List reverse=new LinkedList();
    while (heritage.hasNext()) {
      reverse.add(0,heritage.next());
    }
    heritage=reverse.iterator();
    while (heritage.hasNext()) {
      ComponentEntity inherited=(ComponentEntity)heritage.next();
      String toUndo=_getUndoForDeleteEntity(inherited);
      inherited.setContainer(null);
      undoMoML.insert(0,toUndo);
    }
    String toUndo=_getUndoForDeleteEntity(toDelete);
    toDelete.setContainer(null);
    undoMoML.insert(0,toUndo);
  }
  finally {
    if (_undoEnabled && _undoContext.isUndoable()) {
      undoMoML.insert(0,"String_Node_Str");
      undoMoML.append("String_Node_Str");
      _undoContext.appendUndoMoML(undoMoML.toString());
    }
  }
  return toDelete;
}

Fixed version (ground truth):
/** 
 * Delete the entity after verifying that it is contained (deeply) by the current environment.  If no object is found, then do nothing and return null.  This is because deletion of a class may result in deletion of other objects that make this particular delete call redundant.
 * @param entityName The relative or absolute name of theentity to delete.
 * @return The deleted object, or null if none was found.
 * @exception Exception If there is no such entity or if the entityis defined in the class definition.
 */
private NamedObj _deleteEntity(String entityName) throws Exception {
  ComponentEntity toDelete=_searchForEntity(entityName,_current);
  if (toDelete == null) {
    return null;
  }
  if (toDelete.isDerived()) {
    throw new IllegalActionException(toDelete,"String_Node_Str");
  }
  StringBuffer undoMoML=new StringBuffer();
  try {
    Iterator heritage=toDelete.getDerivedList().iterator();
    List reverse=new LinkedList();
    while (heritage.hasNext()) {
      reverse.add(0,heritage.next());
    }
    heritage=reverse.iterator();
    while (heritage.hasNext()) {
      ComponentEntity inherited=(ComponentEntity)heritage.next();
      String toUndo=_getUndoForDeleteEntity(inherited);
      inherited.setContainer(null);
      undoMoML.insert(0,toUndo);
    }
    String toUndo=_getUndoForDeleteEntity(toDelete);
    toDelete.setContainer(null);
    undoMoML.insert(0,toUndo);
  }
  finally {
    if (_undoEnabled && _undoContext.isUndoable()) {
      undoMoML.insert(0,"String_Node_Str");
      undoMoML.append("String_Node_Str");
      _undoContext.appendUndoMoML(undoMoML.toString());
    }
  }
  return toDelete;
}