Program: 75303
Project: 75303
Buggy source:
/** 
 * Delete the port after verifying that it is contained (deeply) by the current environment.
 * @param portName The relative or absolute name of theport to delete.
 * @param entityName Optional name of the entity that containsthe port (or null to use the current context).
 * @return The deleted object.
 * @exception Exception If there is no such port or if the portis defined in the class definition.
 */
private Port _deletePort(String portName,String entityName) throws Exception {
  Port toDelete=null;
  Entity portContainer=null;
  if (entityName == null) {
    toDelete=_searchForPort(portName);
    if (toDelete != null) {
      portContainer=(Entity)toDelete.getContainer();
    }
  }
 else {
    portContainer=_searchForEntity(entityName,_current);
    if (portContainer != null) {
      toDelete=portContainer.getPort(portName);
    }
  }
  if (toDelete == null) {
    throw new XmlException("String_Node_Str" + portName,_currentExternalEntity(),_parser.getLineNumber(),_parser.getColumnNumber());
  }
  if (portContainer == null) {
    throw new XmlException("String_Node_Str" + portName,_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()) {
      Port inherited=(Port)heritage.next();
      String toUndo=_getUndoForDeletePort(inherited);
      inherited.setContainer(null);
      undoMoML.insert(0,toUndo);
    }
    String toUndo=_getUndoForDeletePort(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 port 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 portName The relative or absolute name of theport to delete.
 * @param entityName Optional name of the entity that containsthe port (or null to use the current context).
 * @return The deleted object, or null if none is found.
 * @exception Exception If there is no such port or if the portis defined in the class definition.
 */
private Port _deletePort(String portName,String entityName) throws Exception {
  Port toDelete=null;
  Entity portContainer=null;
  if (entityName == null) {
    toDelete=_searchForPort(portName);
    if (toDelete != null) {
      portContainer=(Entity)toDelete.getContainer();
    }
  }
 else {
    portContainer=_searchForEntity(entityName,_current);
    if (portContainer != null) {
      toDelete=portContainer.getPort(portName);
    }
  }
  if (toDelete == null) {
    return null;
  }
  if (portContainer == null) {
    throw new XmlException("String_Node_Str" + portName,_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()) {
      Port inherited=(Port)heritage.next();
      String toUndo=_getUndoForDeletePort(inherited);
      inherited.setContainer(null);
      undoMoML.insert(0,toUndo);
    }
    String toUndo=_getUndoForDeletePort(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;
}