Program: 75686
Project: 75686
Buggy source:
/** 
 * Generate code for the composite agent.
 * @param CompositeActor The composite agent generated code from.
 * @return The composite agent code.
 */
private String _compositeAgentCode(CompositeActor actor) throws IllegalActionException {
  if (FSMDirector.class.isInstance(actor.getDirector())) {
    return _agentCode(actor);
  }
  LinkedList subAgents=_agents(actor);
  if (subAgents.size() == 0)   return _agentCode(actor);
  String compositeCodeString="String_Node_Str";
  String subAgentCode="String_Node_Str";
  String privateVariables="String_Node_Str";
  ListIterator subAgentsIterator=subAgents.listIterator();
  while (subAgentsIterator.hasNext()) {
    String subAgentConnectionInputs="String_Node_Str";
    String subAgentConnectionOutputs="String_Node_Str";
    CompositeActor subAgent=(CompositeActor)subAgentsIterator.next();
    subAgentCode+="String_Node_Str" + subAgent.getName().toLowerCase() + "String_Node_Str"+ subAgent.getName()+ "String_Node_Str";
    if (actor.depthInHierarchy() == 0) {
      subAgentCode+=_agentParameterTokens((NamedObj)subAgent);
    }
 else {
      subAgentCode+=_agentParameters((NamedObj)subAgent,false);
    }
    subAgentCode+="String_Node_Str" + _endLine;
    ListIterator subAgentInputs=subAgent.inputPortList().listIterator();
    while (subAgentInputs.hasNext()) {
      TypedIOPort input=(TypedIOPort)subAgentInputs.next();
      LinkedList sourceList=shallowSourcePortList(input);
      ListIterator sources=sourceList.listIterator();
      boolean privateVariable=true;
      while (sources.hasNext()) {
        TypedIOPort source=(TypedIOPort)sources.next();
        if (source.depthInHierarchy() != input.depthInHierarchy()) {
          privateVariable=false;
        }
        if (!(source.getName().equals(input.getName()))) {
          if (subAgentConnectionOutputs == "String_Node_Str") {
            subAgentConnectionOutputs+=source.getName();
            subAgentConnectionInputs+=input.getName();
          }
 else {
            subAgentConnectionOutputs+="String_Node_Str" + source.getName();
            subAgentConnectionInputs+="String_Node_Str" + input.getName();
          }
        }
      }
      if (privateVariable) {
        if (privateVariables == "String_Node_Str") {
          privateVariables+="String_Node_Str" + input.getName();
        }
 else {
          privateVariables+="String_Node_Str" + input.getName();
        }
      }
    }
    if (subAgentConnectionInputs.length() != 0) {
      subAgentCode+="String_Node_Str" + subAgentConnectionInputs + "String_Node_Str"+ subAgentConnectionOutputs+ "String_Node_Str"+ _endLine;
    }
    compositeCodeString+=_compositeAgentCode(subAgent);
  }
  compositeCodeString+="String_Node_Str";
  String parameterString="String_Node_Str";
  String inputString="String_Node_Str";
  String outputString="String_Node_Str";
  String initString="String_Node_Str";
  String modeString="String_Node_Str";
  String modeParameterString="String_Node_Str";
  LinkedList parameterList=(LinkedList)actor.attributeList(Parameter.class);
  int parameterNumber=parameterList.size();
  ListIterator parameters=parameterList.listIterator();
  _inPorts=actor.inputPortList().iterator();
  while (_inPorts.hasNext()) {
    if (inputString == "String_Node_Str") {
      inputString+="String_Node_Str" + ((NamedObj)_inPorts.next()).getName();
    }
 else {
      inputString+="String_Node_Str" + ((NamedObj)_inPorts.next()).getName();
    }
  }
  if (inputString != "String_Node_Str")   inputString+="String_Node_Str";
  _outPorts=actor.outputPortList().iterator();
  if (_outPorts.hasNext()) {
    String outportName=((NamedObj)_outPorts.next()).getName();
    if (outputString == "String_Node_Str") {
      outputString+="String_Node_Str" + outportName;
    }
 else {
      outputString+="String_Node_Str" + outportName;
    }
  }
  if (privateVariables.length() != 0)   privateVariables+="String_Node_Str";
  compositeCodeString+="String_Node_Str" + actor.getName() + "String_Node_Str";
  if (actor.depthInHierarchy() != 0)   compositeCodeString+=_agentParameters((NamedObj)actor,true);
  compositeCodeString+="String_Node_Str" + _endLine + "String_Node_Str"+ _endLine+ "String_Node_Str"+ outputString+ _endLine+ "String_Node_Str"+ inputString+ _endLine+ "String_Node_Str"+ privateVariables+ _endLine+ subAgentCode+ _endLine+ "String_Node_Str"+ _endLine;
  return compositeCodeString;
}

Fixed version (ground truth):
/** 
 * Generate code for the composite agent.
 * @param CompositeActor The composite agent generated code from.
 * @return The composite agent code.
 */
private String _compositeAgentCode(CompositeActor actor) throws IllegalActionException {
  if (FSMDirector.class.isInstance(actor.getDirector())) {
    return _agentCode(actor);
  }
  LinkedList subAgents=_agents(actor);
  if (subAgents.size() == 0)   return _agentCode(actor);
  String compositeCodeString="String_Node_Str";
  String subAgentCode="String_Node_Str";
  String privateVariables="String_Node_Str";
  ListIterator subAgentsIterator=subAgents.listIterator();
  List outputPorts=actor.outputPortList();
  ListIterator outputPortsIterator=actor.outputPortList().listIterator();
  if (outputPorts.size() > 1)   throw new IllegalActionException("String_Node_Str");
  String outputAgentName="String_Node_Str";
  String outputPortName="String_Node_Str";
  String sourceForOutputName="String_Node_Str";
  while (outputPortsIterator.hasNext()) {
    TypedIOPort output=(TypedIOPort)outputPortsIterator.next();
    outputPortName=output.getName();
    ListIterator sourcePorts=output.insidePortList().listIterator();
    TypedIOPort sourcePort=new TypedIOPort();
    while (sourcePorts.hasNext()) {
      TypedIOPort port=(TypedIOPort)sourcePorts.next();
      if (port.isOutput()) {
        if (sourcePort == null) {
          throw new IllegalActionException("String_Node_Str");
        }
 else {
          sourcePort=port;
          sourceForOutputName=sourcePort.getName();
          Nameable sourceContainer=sourcePort.getContainer();
          outputAgentName=sourceContainer.getName();
        }
      }
    }
  }
  while (subAgentsIterator.hasNext()) {
    String subAgentConnectionInputs="String_Node_Str";
    String subAgentConnectionOutputs="String_Node_Str";
    CompositeActor subAgent=(CompositeActor)subAgentsIterator.next();
    if (outputAgentName.equals(subAgent.getName())) {
      subAgentConnectionOutputs+=sourceForOutputName;
      subAgentConnectionInputs+=outputPortName;
    }
    subAgentCode+="String_Node_Str" + subAgent.getName().toLowerCase() + "String_Node_Str"+ subAgent.getName()+ "String_Node_Str";
    if (actor.depthInHierarchy() == 0) {
      subAgentCode+=_agentParameterTokens((NamedObj)subAgent);
    }
 else {
      subAgentCode+=_agentParameters((NamedObj)subAgent,false);
    }
    subAgentCode+="String_Node_Str" + _endLine;
    ListIterator subAgentInputs=subAgent.inputPortList().listIterator();
    while (subAgentInputs.hasNext()) {
      TypedIOPort input=(TypedIOPort)subAgentInputs.next();
      LinkedList sourceList=_shallowSourcePortList(input);
      ListIterator sources=sourceList.listIterator();
      boolean privateVariable=true;
      while (sources.hasNext()) {
        TypedIOPort source=(TypedIOPort)sources.next();
        if (source.depthInHierarchy() != input.depthInHierarchy()) {
          privateVariable=false;
        }
        if (!(source.getName().equals(input.getName()))) {
          if (subAgentConnectionOutputs == "String_Node_Str") {
            subAgentConnectionOutputs+=source.getName();
            subAgentConnectionInputs+=input.getName();
          }
 else {
            subAgentConnectionOutputs+="String_Node_Str" + source.getName();
            subAgentConnectionInputs+="String_Node_Str" + input.getName();
          }
        }
      }
      if (privateVariable) {
        if (privateVariables == "String_Node_Str") {
          privateVariables+="String_Node_Str" + input.getName();
        }
 else {
          privateVariables+="String_Node_Str" + input.getName();
        }
      }
    }
    if (subAgentConnectionInputs.length() != 0) {
      subAgentCode+="String_Node_Str" + subAgentConnectionInputs + "String_Node_Str"+ subAgentConnectionOutputs+ "String_Node_Str"+ _endLine;
    }
    compositeCodeString+=_compositeAgentCode(subAgent);
  }
  compositeCodeString+="String_Node_Str";
  String parameterString="String_Node_Str";
  String inputString="String_Node_Str";
  String outputString="String_Node_Str";
  String initString="String_Node_Str";
  String modeString="String_Node_Str";
  String modeParameterString="String_Node_Str";
  LinkedList parameterList=(LinkedList)actor.attributeList(Parameter.class);
  int parameterNumber=parameterList.size();
  ListIterator parameters=parameterList.listIterator();
  _inPorts=actor.inputPortList().iterator();
  while (_inPorts.hasNext()) {
    if (inputString == "String_Node_Str") {
      inputString+="String_Node_Str" + ((NamedObj)_inPorts.next()).getName();
    }
 else {
      inputString+="String_Node_Str" + ((NamedObj)_inPorts.next()).getName();
    }
  }
  if (inputString != "String_Node_Str")   inputString+="String_Node_Str";
  _outPorts=actor.outputPortList().iterator();
  if (_outPorts.hasNext()) {
    String outportName=((NamedObj)_outPorts.next()).getName();
    if (outputString == "String_Node_Str") {
      outputString+="String_Node_Str" + outportName;
    }
 else {
      outputString+="String_Node_Str" + outportName;
    }
  }
  if (privateVariables.length() != 0)   privateVariables+="String_Node_Str";
  compositeCodeString+="String_Node_Str" + actor.getName() + "String_Node_Str";
  if (actor.depthInHierarchy() != 0)   compositeCodeString+=_agentParameters((NamedObj)actor,true);
  compositeCodeString+="String_Node_Str" + _endLine + "String_Node_Str"+ _endLine+ "String_Node_Str"+ outputString+ _endLine+ "String_Node_Str"+ inputString+ _endLine+ "String_Node_Str"+ privateVariables+ _endLine+ subAgentCode+ _endLine+ "String_Node_Str"+ _endLine;
  return compositeCodeString;
}