Program: 75803
Project: 75803
Buggy source:
/** 
 * Generate Ptolemy II Java code to instantiate a component, and for a composite component, the code to instantiate and connect all components that are nested within the component.
 * @param model The component for which code is to be generated.
 * @return The generated Ptolemy II Java code for implementingthe component.
 */
protected String _generateComponents(ComponentEntity model) throws IllegalActionException {
  String code=new String();
  String className=_getClassName(model);
  String sanitizedName=_name(model);
  CompositeEntity container;
  String containerName;
  String nameAsContainer;
  if ((container=((CompositeEntity)(model.getContainer()))) != null) {
    if (container.getContainer() == null)     containerName="String_Node_Str";
 else     containerName=_name(container);
    nameAsContainer=sanitizedName;
    code+=_indent(3) + className + "String_Node_Str"+ sanitizedName+ "String_Node_Str"+ className+ "String_Node_Str"+ containerName+ "String_Node_Str"+ sanitizedName+ "String_Node_Str";
    code+=_generatePorts(model);
    code+=_generateAttributes(model);
  }
 else   nameAsContainer="String_Node_Str";
  if (!model.isAtomic()) {
    Iterator components=((CompositeEntity)model).entityList().iterator();
    while (components.hasNext()) {
      code+=_generateComponents((ComponentEntity)(components.next()));
    }
    Iterator relations=((CompositeEntity)model).relationList().iterator();
    while (relations.hasNext()) {
      Relation relation=(Relation)(relations.next());
      Iterator ports=relation.linkedPortList().iterator();
      String relationAttributes=_generateAttributes(relation);
      if ((relation.numLinks() == 2) && (relationAttributes.length() == 0)) {
        Port port1=(Port)ports.next();
        Port port2=(Port)ports.next();
        code+=_indent(3);
        if (container != null)         code+=sanitizedName + "String_Node_Str";
        code+="String_Node_Str" + _name(port1) + "String_Node_Str"+ _name(port2)+ "String_Node_Str";
      }
 else {
        String relationClassName=_getClassName(relation);
        code+=_indent(3) + relationClassName + "String_Node_Str"+ _name(relation);
        code+="String_Node_Str" + relationClassName + "String_Node_Str"+ nameAsContainer;
        code+="String_Node_Str" + _name(relation) + "String_Node_Str";
        code+=relationAttributes;
        while (ports.hasNext()) {
          Port p=(Port)ports.next();
          code+=_indent(3) + _name(p) + "String_Node_Str"+ _name(relation)+ "String_Node_Str";
        }
      }
    }
  }
  return code;
}

Fixed version (ground truth):
/** 
 * Generate Ptolemy II Java code to instantiate a component, and for a composite component, the code to instantiate and connect all components that are nested within the component.
 * @param model The component for which code is to be generated.
 * @return The generated Ptolemy II Java code for implementingthe component.
 */
protected String _generateComponents(ComponentEntity model) throws IllegalActionException {
  String code=new String();
  String className=_getClassName(model);
  String sanitizedName=_name(model);
  CompositeEntity container;
  String containerName;
  String nameAsContainer;
  if ((container=((CompositeEntity)(model.getContainer()))) != null) {
    if (container.getContainer() == null) {
      containerName="String_Node_Str";
    }
 else {
      containerName=_name(container);
    }
    nameAsContainer=sanitizedName;
    code+=_indent(3) + className + "String_Node_Str"+ sanitizedName+ "String_Node_Str"+ className+ "String_Node_Str"+ containerName+ "String_Node_Str"+ sanitizedName+ "String_Node_Str";
    code+=_generatePorts(model);
    code+=_generateAttributes(model);
  }
 else   nameAsContainer="String_Node_Str";
  if (!model.isAtomic()) {
    Iterator components=((CompositeEntity)model).entityList().iterator();
    while (components.hasNext()) {
      code+=_generateComponents((ComponentEntity)(components.next()));
    }
    Iterator relations=((CompositeEntity)model).relationList().iterator();
    while (relations.hasNext()) {
      Relation relation=(Relation)(relations.next());
      Iterator ports=relation.linkedPortList().iterator();
      String relationAttributes=_generateAttributes(relation);
      if ((relation.numLinks() == 2) && (relationAttributes.length() == 0)) {
        Port port1=(Port)ports.next();
        Port port2=(Port)ports.next();
        code+=_indent(3);
        if (container != null) {
          code+=sanitizedName + "String_Node_Str";
        }
        code+="String_Node_Str" + _name(port1) + "String_Node_Str"+ _name(port2)+ "String_Node_Str";
      }
 else {
        String relationClassName=_getClassName(relation);
        code+=_indent(3) + relationClassName + "String_Node_Str"+ _name(relation);
        code+="String_Node_Str" + relationClassName + "String_Node_Str"+ nameAsContainer;
        code+="String_Node_Str" + _name(relation) + "String_Node_Str";
        code+=relationAttributes;
        while (ports.hasNext()) {
          Port p=(Port)ports.next();
          code+=_indent(3) + _name(p) + "String_Node_Str"+ _name(relation)+ "String_Node_Str";
        }
      }
    }
  }
  return code;
}