Program: 73321
Project: 73321
Buggy source:
/** 
 * Generate the preinitialization method body. <p>Typically, the preinitialize code consists of variable declarations.  However, AutoAdapter generates method calls that instantiate wrapper TypedCompositeActors, so we need to invoke those method calls.</p>
 * @return a string for the preinitialization method body.  Inthis base class, return the empty string.
 * @exception IllegalActionException Not thrown in this base class.
 */
public String generatePreinitializeMethodBodyCode() throws IllegalActionException {
  String actorClassName=getComponent().getClass().getName();
  StringBuffer containmentCode=new StringBuffer();
  NamedObj parentContainer=getComponent().getContainer();
  NamedObj grandparentContainer=parentContainer.getContainer();
  if (grandparentContainer == null) {
    containmentCode.append("String_Node_Str" + getComponent().getContainer().getClass().getName() + "String_Node_Str"+ getComponent().getName()+ "String_Node_Str"+ _eol);
  }
 else {
    while (parentContainer != null) {
      containmentCode.insert(0,"String_Node_Str" + parentContainer.getName() + "String_Node_Str"+ _eol+ "String_Node_Str"+ _eol+ "String_Node_Str"+ parentContainer.getClass().getName()+ "String_Node_Str"+ parentContainer.getName()+ "String_Node_Str"+ _eol+ "String_Node_Str"+ _eol+ "String_Node_Str"+ _eol+ "String_Node_Str"+ _eol);
      parentContainer=parentContainer.getContainer();
    }
    NamedObj container=grandparentContainer;
    containmentCode.insert(0,"String_Node_Str" + _eol + getCodeGenerator().comment(getComponent().getFullName())+ _eol+ "String_Node_Str"+ _eol+ "String_Node_Str"+ _eol+ "String_Node_Str"+ container.getName()+ "String_Node_Str"+ _eol+ "String_Node_Str"+ container.getClass().getName()+ "String_Node_Str"+ container.getName()+ "String_Node_Str"+ _eol+ "String_Node_Str"+ _eol);
    containmentCode.append("String_Node_Str" + getComponent().getContainer().getClass().getName() + "String_Node_Str"+ getComponent().getName()+ "String_Node_Str"+ "String_Node_Str"+ _eol+ "String_Node_Str"+ _eol);
  }
  StringBuffer code=new StringBuffer();
  Iterator entityPorts=((Entity)getComponent()).portList().iterator();
  while (entityPorts.hasNext()) {
    ComponentPort insidePort=(ComponentPort)entityPorts.next();
    if (insidePort instanceof TypedIOPort) {
      TypedIOPort castPort=(TypedIOPort)insidePort;
      String name=TemplateParser.escapePortName(castPort.getName());
      if (!castPort.isMultiport() && castPort.isOutsideConnected()) {
        code.append(_generatePortInstantiation(name,castPort.getName(),castPort,0));
      }
 else {
        TypedIOPort actorPort=null;
        try {
          Field foundPortField=_findFieldByPortName(castPort.getName());
          actorPort=(TypedIOPort)foundPortField.get(getComponent());
          code.append("String_Node_Str" + getComponent().getClass().getName() + "String_Node_Str"+ foundPortField.getName()+ "String_Node_Str"+ _typeToBaseType(actorPort.getType())+ "String_Node_Str"+ _eol);
        }
 catch (        Throwable throwable) {
          actorPort=(TypedIOPort)((Entity)getComponent()).getPort(castPort.getName());
          code.append("String_Node_Str" + actorPort.getName().replace("String_Node_Str","String_Node_Str") + "String_Node_Str"+ actorPort.isInput()+ "String_Node_Str"+ actorPort.isOutput()+ "String_Node_Str"+ _eol);
        }
        int sources=actorPort.numberOfSources();
        for (int i=0; i < sources; i++) {
          code.append(_generatePortInstantiation(name,name + "String_Node_Str" + i,actorPort,i));
        }
        int sinks=actorPort.numberOfSinks();
        for (int i=0; i < sinks; i++) {
          code.append(_generatePortInstantiation(name,name + "String_Node_Str" + i,actorPort,i));
        }
      }
      List<TypeAttribute> typeAttributes=insidePort.attributeList(TypeAttribute.class);
      if (typeAttributes.size() > 0) {
        if (typeAttributes.size() > 1) {
          new Exception("String_Node_Str" + insidePort.getFullName() + "String_Node_Str").printStackTrace();
        }
        TypeAttribute typeAttribute=typeAttributes.get(0);
        code.append("String_Node_Str" + _eol + "String_Node_Str"+ "String_Node_Str"+ "String_Node_Str"+ insidePort.getName().replace("String_Node_Str","String_Node_Str")+ "String_Node_Str"+ _eol+ "String_Node_Str"+ typeAttribute.getExpression()+ "String_Node_Str"+ _eol+ "String_Node_Str"+ _eol);
      }
    }
  }
  String[] splitInitializeConnectionCode=getCodeGenerator()._splitBody("String_Node_Str",code.toString());
  String result=getCodeGenerator().comment("String_Node_Str") + "String_Node_Str" + _eol+ "String_Node_Str"+ getComponent().toplevel().getName()+ "String_Node_Str"+ _eol+ containmentCode+ "String_Node_Str"+ actorClassName+ "String_Node_Str"+ _eol+ "String_Node_Str"+ getComponent().getName()+ "String_Node_Str"+ _eol+ splitInitializeConnectionCode[0]+ splitInitializeConnectionCode[1]+ "String_Node_Str"+ _eol+ "String_Node_Str"+ _eol+ "String_Node_Str"+ _eol+ "String_Node_Str"+ _eol;
  return processCode(result);
}

Fixed version (ground truth):
/** 
 * Generate the preinitialization method body. <p>Typically, the preinitialize code consists of variable declarations.  However, AutoAdapter generates method calls that instantiate wrapper TypedCompositeActors, so we need to invoke those method calls.</p>
 * @return a string for the preinitialization method body.  Inthis base class, return the empty string.
 * @exception IllegalActionException Not thrown in this base class.
 */
public String generatePreinitializeMethodBodyCode() throws IllegalActionException {
  String actorClassName=getComponent().getClass().getName();
  StringBuffer containmentCode=new StringBuffer();
  NamedObj parentContainer=getComponent().getContainer();
  NamedObj grandparentContainer=parentContainer.getContainer();
  if (grandparentContainer == null) {
    containmentCode.append("String_Node_Str" + getComponent().getContainer().getClass().getName() + "String_Node_Str"+ getComponent().getName()+ "String_Node_Str"+ _eol);
  }
 else {
    while (parentContainer != null && parentContainer.getContainer() != null) {
      containmentCode.insert(0,"String_Node_Str" + parentContainer.getName() + "String_Node_Str"+ _eol+ "String_Node_Str"+ _eol+ "String_Node_Str"+ parentContainer.getClass().getName()+ "String_Node_Str"+ parentContainer.getName()+ "String_Node_Str"+ _eol+ "String_Node_Str"+ _eol+ "String_Node_Str"+ _eol+ "String_Node_Str"+ _eol);
      parentContainer=parentContainer.getContainer();
    }
    NamedObj container=grandparentContainer;
    containmentCode.insert(0,"String_Node_Str" + _eol + getCodeGenerator().comment(getComponent().getFullName())+ _eol+ "String_Node_Str"+ _eol+ "String_Node_Str"+ _eol);
    containmentCode.append("String_Node_Str" + getComponent().getContainer().getClass().getName() + "String_Node_Str"+ getComponent().getName()+ "String_Node_Str"+ "String_Node_Str"+ _eol+ "String_Node_Str"+ _eol);
  }
  StringBuffer code=new StringBuffer();
  Iterator entityPorts=((Entity)getComponent()).portList().iterator();
  while (entityPorts.hasNext()) {
    ComponentPort insidePort=(ComponentPort)entityPorts.next();
    if (insidePort instanceof TypedIOPort) {
      TypedIOPort castPort=(TypedIOPort)insidePort;
      String name=TemplateParser.escapePortName(castPort.getName());
      if (!castPort.isMultiport() && castPort.isOutsideConnected()) {
        code.append(_generatePortInstantiation(name,castPort.getName(),castPort,0));
      }
 else {
        TypedIOPort actorPort=null;
        try {
          Field foundPortField=_findFieldByPortName(castPort.getName());
          actorPort=(TypedIOPort)foundPortField.get(getComponent());
          code.append("String_Node_Str" + getComponent().getClass().getName() + "String_Node_Str"+ foundPortField.getName()+ "String_Node_Str"+ _typeToBaseType(actorPort.getType())+ "String_Node_Str"+ _eol);
        }
 catch (        Throwable throwable) {
          actorPort=(TypedIOPort)((Entity)getComponent()).getPort(castPort.getName());
          code.append("String_Node_Str" + actorPort.getName().replace("String_Node_Str","String_Node_Str") + "String_Node_Str"+ actorPort.isInput()+ "String_Node_Str"+ actorPort.isOutput()+ "String_Node_Str"+ _eol);
        }
        int sources=actorPort.numberOfSources();
        for (int i=0; i < sources; i++) {
          code.append(_generatePortInstantiation(name,name + "String_Node_Str" + i,actorPort,i));
        }
        int sinks=actorPort.numberOfSinks();
        for (int i=0; i < sinks; i++) {
          code.append(_generatePortInstantiation(name,name + "String_Node_Str" + i,actorPort,i));
        }
      }
      List<TypeAttribute> typeAttributes=insidePort.attributeList(TypeAttribute.class);
      if (typeAttributes.size() > 0) {
        if (typeAttributes.size() > 1) {
          new Exception("String_Node_Str" + insidePort.getFullName() + "String_Node_Str").printStackTrace();
        }
        TypeAttribute typeAttribute=typeAttributes.get(0);
        code.append("String_Node_Str" + _eol + "String_Node_Str"+ "String_Node_Str"+ "String_Node_Str"+ insidePort.getName().replace("String_Node_Str","String_Node_Str")+ "String_Node_Str"+ _eol+ "String_Node_Str"+ typeAttribute.getExpression()+ "String_Node_Str"+ _eol+ "String_Node_Str"+ _eol);
      }
    }
  }
  code.append(generateParameterCode());
  String[] splitInitializeConnectionCode=getCodeGenerator()._splitBody("String_Node_Str",code.toString());
  String result=getCodeGenerator().comment("String_Node_Str") + "String_Node_Str" + _eol+ "String_Node_Str"+ getComponent().toplevel().getName()+ "String_Node_Str"+ _eol+ containmentCode+ "String_Node_Str"+ actorClassName+ "String_Node_Str"+ _eol+ "String_Node_Str"+ getComponent().getName()+ "String_Node_Str"+ _eol+ splitInitializeConnectionCode[0]+ splitInitializeConnectionCode[1]+ "String_Node_Str"+ _eol+ "String_Node_Str"+ _eol+ "String_Node_Str"+ _eol+ "String_Node_Str"+ _eol;
  return processCode(result);
}