Program: 73837
Project: 73837
Buggy source:
/** 
 * Generate code for transferring enough tokens to complete an internal iteration.
 * @param inputPort The port to transfer tokens.
 * @param code The string buffer that the generated code is appended to.
 * @exception IllegalActionException If thrown while transferring tokens.
 */
public void generateTransferInputsCode(IOPort inputPort,StringBuffer code) throws IllegalActionException {
  code.append(CodeStream.indent(getCodeGenerator().comment("String_Node_Str" + "String_Node_Str")));
  int rate=DFUtilities.getTokenConsumptionRate(inputPort);
  CompositeActor container=(CompositeActor)getComponent().getContainer();
  TypedCompositeActor compositeActorAdapter=(TypedCompositeActor)getCodeGenerator().getAdapter(container);
  if ((container instanceof CompiledCompositeActor && ((BooleanToken)getCodeGenerator().generateEmbeddedCode.getToken()).booleanValue()) || (container instanceof CompositeActor)) {
    if (!(inputPort instanceof TypedIOPort)) {
      throw new InternalErrorException(inputPort,null,"String_Node_Str");
    }
    ptolemy.cg.adapter.generic.program.procedural.adapters.ptolemy.actor.IOPort portAdapter=(ptolemy.cg.adapter.generic.program.procedural.adapters.ptolemy.actor.IOPort)getAdapter(inputPort);
    String offset="String_Node_Str";
    for (int i=0; i < inputPort.getWidth(); i++) {
      code.append("String_Node_Str");
      code.append(portAdapter.generateHasTokenCode(Integer.toString(i),offset));
      code.append("String_Node_Str" + _eol);
      StringBuffer inputCode=new StringBuffer();
      boolean dynamicReferencesAllowed=allowDynamicMultiportReference();
      inputCode.append(NamedProgramCodeGeneratorAdapter.generateName(inputPort));
      int bufferSize=_ports.getBufferSize(inputPort);
      if (inputPort.isMultiport()) {
        inputCode.append("String_Node_Str" + Integer.toString(i) + "String_Node_Str");
        if (bufferSize > 1 || dynamicReferencesAllowed) {
          throw new InternalErrorException("String_Node_Str" + "String_Node_Str" + "String_Node_Str");
        }
      }
 else {
        if (bufferSize > 1) {
          throw new InternalErrorException("String_Node_Str" + "String_Node_Str" + "String_Node_Str");
        }
      }
      code.append(inputCode);
      code.append("String_Node_Str");
      code.append(portAdapter.generateGetCode(Integer.toString(i),offset));
      code.append("String_Node_Str" + _eol);
      code.append("String_Node_Str" + _eol);
    }
  }
 else {
    for (int i=0; i < inputPort.getWidth(); i++) {
      if (i < inputPort.getWidthInside()) {
        String name=inputPort.getName();
        if (inputPort.isMultiport()) {
          name=name + '#' + i;
        }
        for (int k=0; k < rate; k++) {
          code.append(compositeActorAdapter.getReference("String_Node_Str" + name + "String_Node_Str"+ k));
          code.append("String_Node_Str" + _eol);
          code.append(compositeActorAdapter.getReference(name + "String_Node_Str" + k));
          code.append("String_Node_Str" + _eol);
        }
      }
    }
  }
  code.append(compositeActorAdapter.generateTypeConvertFireCode(true));
  _updateConnectedPortsOffset(inputPort,code,rate);
}

Fixed version (ground truth):
/** 
 * Generate code for transferring enough tokens to complete an internal iteration.
 * @param inputPort The port to transfer tokens.
 * @param code The string buffer that the generated code is appended to.
 * @exception IllegalActionException If thrown while transferring tokens.
 */
public void generateTransferInputsCode(IOPort inputPort,StringBuffer code) throws IllegalActionException {
  code.append(CodeStream.indent(getCodeGenerator().comment("String_Node_Str" + "String_Node_Str")));
  int rate=DFUtilities.getTokenConsumptionRate(inputPort);
  CompositeActor container=(CompositeActor)getComponent().getContainer();
  TypedCompositeActor compositeActorAdapter=(TypedCompositeActor)getCodeGenerator().getAdapter(container);
  if ((container instanceof CompiledCompositeActor && ((BooleanToken)getCodeGenerator().generateEmbeddedCode.getToken()).booleanValue()) || (container instanceof CompositeActor)) {
    if (!(inputPort instanceof TypedIOPort)) {
      throw new InternalErrorException(inputPort,null,"String_Node_Str");
    }
    ptolemy.cg.adapter.generic.program.procedural.adapters.ptolemy.actor.IOPort portAdapter=(ptolemy.cg.adapter.generic.program.procedural.adapters.ptolemy.actor.IOPort)getAdapter(inputPort);
    String offset="String_Node_Str";
    for (int i=0; i < inputPort.getWidth(); i++) {
      code.append("String_Node_Str");
      code.append(portAdapter.generateHasTokenCode(Integer.toString(i),offset));
      code.append("String_Node_Str" + _eol);
      StringBuffer inputCode=new StringBuffer();
      boolean dynamicReferencesAllowed=allowDynamicMultiportReference();
      inputCode.append(NamedProgramCodeGeneratorAdapter.generateName(inputPort));
      int bufferSize=_ports.getBufferSize(inputPort);
      if (inputPort.isMultiport()) {
        inputCode.append("String_Node_Str" + Integer.toString(i) + "String_Node_Str");
        if (bufferSize > 1 || dynamicReferencesAllowed) {
          throw new InternalErrorException("String_Node_Str" + "String_Node_Str" + "String_Node_Str");
        }
      }
 else {
        if (bufferSize > 1) {
          throw new InternalErrorException("String_Node_Str" + "String_Node_Str" + "String_Node_Str");
        }
      }
      code.append(inputCode);
      code.append("String_Node_Str");
      code.append(portAdapter.generateGetCode(Integer.toString(i),offset));
      code.append("String_Node_Str" + _eol);
      code.append("String_Node_Str" + _eol);
    }
  }
 else {
    for (int i=0; i < inputPort.getWidth(); i++) {
      if (i < inputPort.getWidthInside()) {
        String name=inputPort.getName();
        if (inputPort.isMultiport()) {
          name=name + '#' + i;
        }
        for (int k=0; k < rate; k++) {
          code.append(compositeActorAdapter.getReference("String_Node_Str" + name + "String_Node_Str"+ k,false));
          code.append("String_Node_Str" + _eol);
          code.append(compositeActorAdapter.getReference(name + "String_Node_Str" + k,false));
          code.append("String_Node_Str" + _eol);
        }
      }
    }
  }
  code.append(compositeActorAdapter.generateTypeConvertFireCode(true));
  _updateConnectedPortsOffset(inputPort,code,rate);
}