Program: 72721
Project: 72721
Buggy source:
/** 
 * Generate code for the firing of refinements.
 * @param code The string buffer that the generated code is appended to.
 * @exception IllegalActionException If the helper associated withan actor throws it while generating fire code for the actor.
 */
protected void _generateRefinementCode(StringBuffer code) throws IllegalActionException {
  ProgramCodeGeneratorAdapter controllerHelper=(ProgramCodeGeneratorAdapter)getCodeGenerator().getAdapter(_myController);
  int depth=1;
  code.append(_getIndentPrefix(depth));
  code.append("String_Node_Str" + controllerHelper.processCode("String_Node_Str") + "String_Node_Str"+ _eol);
  Iterator states=_myController.entityList().iterator();
  int stateCount=0;
  depth++;
  while (states.hasNext()) {
    code.append(_getIndentPrefix(depth));
    code.append("String_Node_Str" + stateCount + "String_Node_Str"+ _eol);
    stateCount++;
    depth++;
    State state=(State)states.next();
    Actor[] actors=state.getRefinement();
    if (actors != null) {
      for (      Actor actor : actors) {
        NamedProgramCodeGeneratorAdapter actorHelper=(NamedProgramCodeGeneratorAdapter)getCodeGenerator().getAdapter(actor);
        code.append(actorHelper.generateFireCode());
        List<IOPort> outputPorts=actor.outputPortList();
        for (        IOPort outputPort : outputPorts) {
          String source=outputPort.getFullName().substring(1).replace("String_Node_Str","String_Node_Str");
          int k=source.lastIndexOf("String_Node_Str");
          int l=source.substring(0,k).lastIndexOf("String_Node_Str");
          String destination=source.substring(0,l) + "String_Node_Str" + source.substring(k);
          code.append(_eol + getCodeGenerator().generatePortName((TypedIOPort)outputPort,destination,1) + "String_Node_Str"+ getCodeGenerator().generatePortName((TypedIOPort)outputPort,source,1)+ "String_Node_Str"+ _eol);
        }
      }
    }
    code.append(_getIndentPrefix(depth));
    code.append("String_Node_Str" + _eol);
    depth--;
  }
  depth--;
  code.append(_getIndentPrefix(depth));
  code.append("String_Node_Str" + _eol);
}

Fixed version (ground truth):
/** 
 * Generate code for the firing of refinements.
 * @param code The string buffer that the generated code is appended to.
 * @exception IllegalActionException If the helper associated withan actor throws it while generating fire code for the actor.
 */
protected boolean _generateRefinementCode(StringBuffer code) throws IllegalActionException {
  ProgramCodeGeneratorAdapter controllerHelper=(ProgramCodeGeneratorAdapter)getCodeGenerator().getAdapter(_myController);
  boolean refined=false;
  int depth=1;
  code.append(_getIndentPrefix(depth));
  code.append("String_Node_Str" + controllerHelper.processCode("String_Node_Str") + "String_Node_Str"+ _eol);
  Iterator states=_myController.entityList().iterator();
  int stateCount=0;
  depth++;
  while (states.hasNext()) {
    code.append(_getIndentPrefix(depth));
    code.append("String_Node_Str" + stateCount + "String_Node_Str"+ _eol);
    stateCount++;
    depth++;
    State state=(State)states.next();
    Actor[] actors=state.getRefinement();
    if (actors != null) {
      refined=true;
      for (      Actor actor : actors) {
        NamedProgramCodeGeneratorAdapter actorHelper=(NamedProgramCodeGeneratorAdapter)getCodeGenerator().getAdapter(actor);
        code.append(actorHelper.generateFireCode());
        List<IOPort> outputPorts=actor.outputPortList();
        for (        IOPort outputPort : outputPorts) {
          String source=outputPort.getFullName().substring(1).replace("String_Node_Str","String_Node_Str");
          int k=source.lastIndexOf("String_Node_Str");
          int l=source.substring(0,k).lastIndexOf("String_Node_Str");
          String destination=source.substring(0,l) + "String_Node_Str" + source.substring(k);
          code.append(_eol + getCodeGenerator().generatePortName((TypedIOPort)outputPort,destination,1) + "String_Node_Str"+ getCodeGenerator().generatePortName((TypedIOPort)outputPort,source,1)+ "String_Node_Str"+ _eol);
        }
      }
    }
    code.append(_getIndentPrefix(depth));
    code.append("String_Node_Str" + _eol);
    depth--;
  }
  depth--;
  code.append(_getIndentPrefix(depth));
  code.append("String_Node_Str" + _eol);
  return refined;
}