Program: 74235
Project: 74235
Buggy source:
/** 
 * @param code The given code buffer.
 * @throws IllegalActionException
 */
private void _generateThreadFunctionCode(StringBuffer code) throws IllegalActionException {
  List actorList=((CompositeActor)_director.getContainer()).deepEntityList();
  boolean inline=((BooleanToken)_codeGenerator.inline.getToken()).booleanValue();
  Iterator actors=actorList.iterator();
  actors=actorList.iterator();
  while (actors.hasNext()) {
    StringBuffer functionCode=new StringBuffer();
    Actor actor=(Actor)actors.next();
    CodeGeneratorHelper helper=(CodeGeneratorHelper)_getHelper((NamedObj)actor);
    if (!inline) {
      code.append(helper.generateFireFunctionCode());
    }
    code.append(_eol + "String_Node_Str" + _getActorThreadLabel(actor)+ "String_Node_Str"+ _eol);
    if (actor instanceof CompositeActor) {
      Director directorHelper=(Director)_getHelper(actor.getDirector());
      assert(directorHelper != this);
      functionCode.append(directorHelper.generateMainLoop());
      functionCode.append("String_Node_Str" + generateDirectorHeader() + "String_Node_Str"+ _eol);
    }
 else {
      String pnPostfireCode="String_Node_Str";
      if (actor instanceof LimitedFiringSource) {
        int firingCount=((IntToken)((LimitedFiringSource)actor).firingCountLimit.getToken()).intValue();
        functionCode.append("String_Node_Str" + _eol);
        functionCode.append("String_Node_Str" + firingCount + "String_Node_Str"+ _eol);
        pnPostfireCode=_eol;
      }
 else {
        functionCode.append("String_Node_Str" + _eol);
      }
      functionCode.append(helper.generateFireCode());
      if (inline) {
        functionCode.append(helper.generateTypeConvertFireCode());
      }
      functionCode.append(helper.generatePostfireCode());
      boolean forComposite=actor instanceof CompositeActor;
      for (      IOPort port : (List<IOPort>)((Entity)actor).portList()) {
        int rate=0;
        try {
          rate=DFUtilities.getRate(port);
        }
 catch (        NullPointerException ex) {
        }
        PortCodeGenerator portHelper=(PortCodeGenerator)_getHelper(port);
        CodeGeneratorHelper portCGHelper=(CodeGeneratorHelper)portHelper;
        if (portCGHelper.checkRemote(forComposite,port)) {
          pnPostfireCode+=portHelper.updateConnectedPortsOffset(rate,_director);
        }
        if (port.isInput()) {
          pnPostfireCode+=portHelper.updateOffset(rate,_director);
        }
      }
      functionCode.append(pnPostfireCode);
      functionCode.append("String_Node_Str" + _eol);
      functionCode.append("String_Node_Str" + generateDirectorHeader() + "String_Node_Str"+ _eol);
    }
    functionCode.append(helper.generateWrapupCode());
    functionCode.append("String_Node_Str" + _eol);
    functionCode.append("String_Node_Str" + _eol);
    String initializeCode=helper.generateInitializeCode();
    String variableInitializeCode=helper.generateVariableInitialization();
    code.append(variableInitializeCode);
    code.append(initializeCode);
    code.append(functionCode);
  }
}

Fixed version (ground truth):
/** 
 * @param code The given code buffer.
 * @throws IllegalActionException
 */
private void _generateThreadFunctionCode(StringBuffer code) throws IllegalActionException {
  List actorList=((CompositeActor)_director.getContainer()).deepEntityList();
  for (  Actor actor : (List<Actor>)actorList) {
    StringBuffer functionCode=new StringBuffer();
    CodeGeneratorHelper helper=(CodeGeneratorHelper)_getHelper((NamedObj)actor);
    code.append(_eol + "String_Node_Str" + _getActorThreadLabel(actor)+ "String_Node_Str"+ _eol);
    if (actor instanceof CompositeActor) {
      Director directorHelper=(Director)_getHelper(actor.getDirector());
      assert(directorHelper != this);
      functionCode.append(directorHelper.generateMainLoop());
      functionCode.append("String_Node_Str" + generateDirectorHeader() + "String_Node_Str"+ _eol);
    }
 else {
      String pnPostfireCode="String_Node_Str";
      if (actor instanceof LimitedFiringSource) {
        int firingCount=((IntToken)((LimitedFiringSource)actor).firingCountLimit.getToken()).intValue();
        functionCode.append("String_Node_Str" + _eol);
        functionCode.append("String_Node_Str" + firingCount + "String_Node_Str"+ _eol);
        pnPostfireCode=_eol;
      }
 else {
        functionCode.append("String_Node_Str" + _eol);
      }
      functionCode.append(helper.generateFireCode());
      functionCode.append(helper.generatePostfireCode());
      boolean forComposite=actor instanceof CompositeActor;
      for (      IOPort port : (List<IOPort>)((Entity)actor).portList()) {
        int rate=0;
        try {
          rate=DFUtilities.getRate(port);
        }
 catch (        NullPointerException ex) {
        }
        PortCodeGenerator portHelper=(PortCodeGenerator)_getHelper(port);
        CodeGeneratorHelper portCGHelper=(CodeGeneratorHelper)portHelper;
        if (portCGHelper.checkRemote(forComposite,port)) {
          pnPostfireCode+=portHelper.updateConnectedPortsOffset(rate,_director);
        }
        if (port.isInput()) {
          pnPostfireCode+=portHelper.updateOffset(rate,_director);
        }
      }
      functionCode.append(pnPostfireCode);
      functionCode.append("String_Node_Str" + _eol);
      functionCode.append("String_Node_Str" + generateDirectorHeader() + "String_Node_Str"+ _eol);
    }
    functionCode.append(helper.generateWrapupCode());
    functionCode.append("String_Node_Str" + _eol);
    functionCode.append("String_Node_Str" + _eol);
    String initializeCode=helper.generateInitializeCode();
    String variableInitializeCode=helper.generateVariableInitialization();
    code.append(variableInitializeCode);
    code.append(initializeCode);
    code.append(functionCode);
  }
}