Program: 76016
Project: 76016
Buggy source:
/** 
 * Append moml to the given buffer that connects a link with the given head, tail, and relation.  This may require addinging an anonymous relation to the ptolemy model.  If this is required, the name of the relation is returned.   If no relation need be added, then null is returned.
 */
private String _linkMoML(StringBuffer moml,StringBuffer failmoml,NamedObj linkHead,NamedObj linkTail) throws Exception {
  if (linkHead != null && linkTail != null) {
    NamedObj head=(NamedObj)getSemanticObject(linkHead);
    NamedObj tail=(NamedObj)getSemanticObject(linkTail);
    if (head instanceof ComponentPort && tail instanceof ComponentPort) {
      ComponentPort headPort=(ComponentPort)head;
      ComponentPort tailPort=(ComponentPort)tail;
      String relationName=getToplevel().uniqueName("String_Node_Str");
      moml.append("String_Node_Str" + relationName + "String_Node_Str");
      moml.append("String_Node_Str" + headPort.getName(getToplevel()) + "String_Node_Str"+ relationName+ "String_Node_Str");
      moml.append("String_Node_Str" + tailPort.getName(getToplevel()) + "String_Node_Str"+ relationName+ "String_Node_Str");
      failmoml.append("String_Node_Str" + headPort.getName(getToplevel()) + "String_Node_Str"+ relationName+ "String_Node_Str");
      failmoml.append("String_Node_Str" + tailPort.getName(getToplevel()) + "String_Node_Str"+ relationName+ "String_Node_Str");
      failmoml.append("String_Node_Str" + relationName + "String_Node_Str");
      return relationName;
    }
 else     if (head instanceof ComponentPort && linkTail instanceof Vertex) {
      moml.append("String_Node_Str" + head.getName(getToplevel()) + "String_Node_Str"+ tail.getName(getToplevel())+ "String_Node_Str");
      return linkTail.getName(getToplevel());
    }
 else     if (tail instanceof ComponentPort && linkHead instanceof Vertex) {
      moml.append("String_Node_Str" + tail.getName(getToplevel()) + "String_Node_Str"+ head.getName(getToplevel())+ "String_Node_Str");
      return linkHead.getName(getToplevel());
    }
 else {
      throw new RuntimeException("String_Node_Str" + "String_Node_Str" + head + "String_Node_Str"+ tail);
    }
  }
 else {
    return null;
  }
}

Fixed version (ground truth):
/** 
 * Append moml to the given buffer that connects a link with the given head, tail, and relation.  This may require addinging an anonymous relation to the ptolemy model.  If this is required, the name of the relation is returned.   If no relation need be added, then null is returned.
 */
private String _linkMoML(StringBuffer moml,StringBuffer failmoml,NamedObj linkHead,NamedObj linkTail) throws Exception {
  if (linkHead != null && linkTail != null) {
    NamedObj head=(NamedObj)getSemanticObject(linkHead);
    NamedObj tail=(NamedObj)getSemanticObject(linkTail);
    if (head instanceof ComponentPort && tail instanceof ComponentPort) {
      ComponentPort headPort=(ComponentPort)head;
      ComponentPort tailPort=(ComponentPort)tail;
      String relationName=getToplevel().uniqueName("String_Node_Str");
      moml.append("String_Node_Str" + relationName + "String_Node_Str");
      moml.append("String_Node_Str" + headPort.getName(getToplevel()) + "String_Node_Str"+ relationName+ "String_Node_Str");
      moml.append("String_Node_Str" + tailPort.getName(getToplevel()) + "String_Node_Str"+ relationName+ "String_Node_Str");
      failmoml.append("String_Node_Str" + headPort.getName(getToplevel()) + "String_Node_Str"+ relationName+ "String_Node_Str");
      failmoml.append("String_Node_Str" + tailPort.getName(getToplevel()) + "String_Node_Str"+ relationName+ "String_Node_Str");
      failmoml.append("String_Node_Str" + relationName + "String_Node_Str");
      return relationName;
    }
 else     if (head instanceof ComponentPort && linkTail instanceof Vertex) {
      moml.append("String_Node_Str" + head.getName(getToplevel()) + "String_Node_Str"+ tail.getName(getToplevel())+ "String_Node_Str");
      return tail.getName(getToplevel());
    }
 else     if (tail instanceof ComponentPort && linkHead instanceof Vertex) {
      moml.append("String_Node_Str" + tail.getName(getToplevel()) + "String_Node_Str"+ head.getName(getToplevel())+ "String_Node_Str");
      return head.getName(getToplevel());
    }
 else {
      throw new RuntimeException("String_Node_Str" + "String_Node_Str" + head + "String_Node_Str"+ tail);
    }
  }
 else {
    return null;
  }
}