Program: 73678
Project: 73678
Buggy source:
/** 
 * Generate a main loop for an execution under the control of this director. If the associated director has a parameter named <i>iterations</i> with a value greater than zero, then wrap code generated by generateFireCode() in a loop that executes the specified number of iterations. Otherwise, wrap it in a loop that executes forever. In the loop, first get the code returned by generateFireCode(), and follow that with the code produced by the container help for generateModeTransitionCode(). That code will make state transitions in modal models at the conclusion of each iteration. Next, this code calls postfire(), and that returns false, breaks out of the main loop. Finally, if the director has a parameter named <i>period</i>, then increment the variable _currentTime after each pass through the loop.
 * @return Code for the main loop of an execution.
 * @exception IllegalActionException If something goes wrong.
 */
public String generateMainLoop() throws IllegalActionException {
  StringBuffer code=new StringBuffer(_eol + getCodeGenerator().getMethodVisibiliyString() + "String_Node_Str"+ getCodeGenerator().getMethodExceptionString()+ "String_Node_Str"+ _eol);
  Attribute iterations=_director.getAttribute("String_Node_Str");
  if (iterations == null) {
    code.append(_eol + "String_Node_Str" + _eol);
  }
 else {
    int iterationCount=((IntToken)((Variable)iterations).getToken()).intValue();
    if (iterationCount <= 0) {
      code.append(_eol + "String_Node_Str" + _eol);
    }
 else {
      code.append(_eol + "String_Node_Str" + _eol);
      code.append("String_Node_Str" + iterationCount + "String_Node_Str"+ _eol);
    }
  }
  code.append("String_Node_Str" + _eol + "String_Node_Str"+ _eol+ "String_Node_Str"+ _eol+ "String_Node_Str"+ _eol+ "String_Node_Str"+ _eol+ _eol+ getCodeGenerator().getMethodVisibiliyString()+ "String_Node_Str"+ getCodeGenerator().getMethodExceptionString()+ "String_Node_Str"+ _eol);
  code.append(generateFireCode());
  NamedProgramCodeGeneratorAdapter modelAdapter=(NamedProgramCodeGeneratorAdapter)getCodeGenerator().getAdapter(_director.getContainer());
  modelAdapter.generateModeTransitionCode(code);
  _generateUpdatePortOffsetCode(code,(Actor)_director.getContainer());
  code.append(generatePostfireCode());
  code.append("String_Node_Str" + _eol);
  Attribute period=_director.getAttribute("String_Node_Str");
  if (period != null) {
    Double periodValue=((DoubleToken)((Variable)period).getToken()).doubleValue();
    if (periodValue != 0.0) {
      code.append("String_Node_Str" + periodValue + "String_Node_Str"+ _eol);
    }
  }
  code.append("String_Node_Str" + _eol + "String_Node_Str"+ _eol);
  return code.toString();
}

Fixed version (ground truth):
/** 
 * Generate a main loop for an execution under the control of this director. If the associated director has a parameter named <i>iterations</i> with a value greater than zero, then wrap code generated by generateFireCode() in a loop that executes the specified number of iterations. Otherwise, wrap it in a loop that executes forever. In the loop, first get the code returned by generateFireCode(), and follow that with the code produced by the container help for generateModeTransitionCode(). That code will make state transitions in modal models at the conclusion of each iteration. Next, this code calls postfire(), and that returns false, breaks out of the main loop. Finally, if the director has a parameter named <i>period</i>, then increment the variable _currentTime after each pass through the loop.
 * @return Code for the main loop of an execution.
 * @exception IllegalActionException If something goes wrong.
 */
public String generateMainLoop() throws IllegalActionException {
  StringBuffer code=new StringBuffer(_eol + getCodeGenerator().getMethodVisibiliyString() + "String_Node_Str"+ getCodeGenerator().getMethodExceptionString()+ "String_Node_Str"+ _eol);
  Attribute iterations=_director.getAttribute("String_Node_Str");
  if (iterations == null) {
    code.append(_eol + "String_Node_Str" + _eol);
  }
 else {
    int iterationCount=((IntToken)((Variable)iterations).getToken()).intValue();
    if (iterationCount <= 0) {
      code.append(_eol + "String_Node_Str" + _eol);
    }
 else {
      code.append(_eol + "String_Node_Str" + _eol);
      code.append("String_Node_Str" + iterationCount + "String_Node_Str"+ _eol);
    }
  }
  String[] splitFireCode=getCodeGenerator()._splitBody("String_Node_Str" + NamedProgramCodeGeneratorAdapter.generateName(getComponent()) + "String_Node_Str",generateFireCode());
  code.append("String_Node_Str" + _eol + "String_Node_Str"+ _eol+ "String_Node_Str"+ _eol+ "String_Node_Str"+ _eol+ "String_Node_Str"+ _eol+ _eol+ splitFireCode[0]+ _eol+ getCodeGenerator().getMethodVisibiliyString()+ "String_Node_Str"+ getCodeGenerator().getMethodExceptionString()+ "String_Node_Str"+ _eol+ splitFireCode[1]);
  NamedProgramCodeGeneratorAdapter modelAdapter=(NamedProgramCodeGeneratorAdapter)getCodeGenerator().getAdapter(_director.getContainer());
  modelAdapter.generateModeTransitionCode(code);
  _generateUpdatePortOffsetCode(code,(Actor)_director.getContainer());
  code.append(generatePostfireCode());
  code.append("String_Node_Str" + _eol);
  Attribute period=_director.getAttribute("String_Node_Str");
  if (period != null) {
    Double periodValue=((DoubleToken)((Variable)period).getToken()).doubleValue();
    if (periodValue != 0.0) {
      code.append("String_Node_Str" + periodValue + "String_Node_Str"+ _eol);
    }
  }
  code.append("String_Node_Str" + _eol + "String_Node_Str"+ _eol);
  return code.toString();
}