Program: 75883
Project: 75883
Buggy source:
/** 
 * Append moml to the given buffer that connects a link with the given head, tail, and relation.  Names in the returned moml will be relative to the given container.  This may require adding an anonymous relation to the ptolemy model.  If this is required, the name of the relation <b>relative to the toplevel object of this graph model</b> is returned. If no relation need be added, then null is returned.
 */
private String _linkMoML(NamedObj container,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");
      if (getToplevel() != container) {
        String contextString="String_Node_Str" + getToplevel().getName(container) + "String_Node_Str";
        moml.append(contextString);
        failmoml.append(contextString);
      }
      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");
      if (getToplevel() != container) {
        moml.append("String_Node_Str");
        failmoml.append("String_Node_Str");
      }
      return relationName;
    }
 else     if (head instanceof ComponentPort && linkTail instanceof Vertex) {
      moml.append("String_Node_Str" + head.getName(container) + "String_Node_Str"+ tail.getName(container)+ "String_Node_Str");
      return tail.getName(container);
    }
 else     if (tail instanceof ComponentPort && linkHead instanceof Vertex) {
      moml.append("String_Node_Str" + tail.getName(container) + "String_Node_Str"+ head.getName(container)+ "String_Node_Str");
      return head.getName(container);
    }
 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.  Names in the returned moml will be relative to the given container.  This may require adding an anonymous relation to the ptolemy model.   If no relation need be added, then null is returned.
 */
private String _linkMoML(NamedObj container,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");
      if (getToplevel() != container) {
        String contextString="String_Node_Str" + getToplevel().getName(container) + "String_Node_Str";
        moml.append(contextString);
        failmoml.append(contextString);
      }
      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");
      if (getToplevel() != container) {
        moml.append("String_Node_Str");
        failmoml.append("String_Node_Str");
      }
      if (getToplevel() != container) {
        return getToplevel().getName(container) + "String_Node_Str" + relationName;
      }
 else {
        return relationName;
      }
    }
 else     if (head instanceof ComponentPort && linkTail instanceof Vertex) {
      moml.append("String_Node_Str" + head.getName(container) + "String_Node_Str"+ tail.getName(container)+ "String_Node_Str");
      return tail.getName(container);
    }
 else     if (tail instanceof ComponentPort && linkHead instanceof Vertex) {
      moml.append("String_Node_Str" + tail.getName(container) + "String_Node_Str"+ head.getName(container)+ "String_Node_Str");
      return head.getName(container);
    }
 else {
      throw new RuntimeException("String_Node_Str" + "String_Node_Str" + head + "String_Node_Str"+ tail);
    }
  }
 else {
    return null;
  }
}