Program: 72902
Project: 72902
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);
  boolean targetCpp=((BooleanToken)getCodeGenerator().generateCpp.getToken()).booleanValue();
  CompositeActor container=(CompositeActor)getComponent().getContainer();
  TypedCompositeActor compositeActorAdapter=(TypedCompositeActor)getCodeGenerator().getAdapter(container);
  if (container instanceof CompiledCompositeActor && ((BooleanToken)getCodeGenerator().generateEmbeddedCode.getToken()).booleanValue()) {
    if (!(inputPort instanceof TypedIOPort)) {
      throw new InternalErrorException(inputPort,null,"String_Node_Str");
    }
    Type type=((TypedIOPort)inputPort).getType();
    String portName=inputPort.getName();
    String exceptionMessage="String_Node_Str" + "String_Node_Str" + "String_Node_Str" + portName + "String_Node_Str"+ type+ "String_Node_Str"+ "String_Node_Str"+ portName+ "String_Node_Str"+ "String_Node_Str";
    for (int i=0; i < inputPort.getWidth(); i++) {
      if (i < inputPort.getWidthInside()) {
        String tokensFromOneChannel="String_Node_Str" + portName + i;
        String pointerToTokensFromOneChannel="String_Node_Str" + tokensFromOneChannel;
        code.append("String_Node_Str" + tokensFromOneChannel + "String_Node_Str"+ CCodegenUtilities.jniGetObjectArrayElement(portName,String.valueOf(i),targetCpp)+ "String_Node_Str"+ _eol);
        if (type == BaseType.INT) {
          code.append("String_Node_Str" + pointerToTokensFromOneChannel + "String_Node_Str"+ CCodegenUtilities.jniGetArrayElements("String_Node_Str",tokensFromOneChannel,targetCpp)+ "String_Node_Str"+ _eol);
        }
 else         if (type == BaseType.DOUBLE) {
          code.append("String_Node_Str" + pointerToTokensFromOneChannel + "String_Node_Str"+ CCodegenUtilities.jniGetArrayElements("String_Node_Str",tokensFromOneChannel,targetCpp)+ "String_Node_Str"+ _eol);
        }
 else         if (type == PointerToken.POINTER) {
          code.append("String_Node_Str" + pointerToTokensFromOneChannel + "String_Node_Str"+ CCodegenUtilities.jniGetArrayElements("String_Node_Str",tokensFromOneChannel,targetCpp)+ "String_Node_Str"+ _eol);
        }
 else         if (type == BaseType.BOOLEAN) {
          code.append("String_Node_Str" + pointerToTokensFromOneChannel + "String_Node_Str"+ CCodegenUtilities.jniGetArrayElements("String_Node_Str",tokensFromOneChannel,targetCpp)+ "String_Node_Str"+ _eol);
        }
 else {
          throw new IllegalActionException(inputPort,exceptionMessage);
        }
        String portNameWithChannelNumber=portName;
        if (inputPort.isMultiport()) {
          portNameWithChannelNumber=portName + '#' + i;
        }
        for (int k=0; k < rate; k++) {
          code.append(_eol + "String_Node_Str" + portNameWithChannelNumber+ "String_Node_Str");
          if (type == PointerToken.POINTER) {
            code.append("String_Node_Str" + pointerToTokensFromOneChannel + "String_Node_Str"+ k+ "String_Node_Str");
          }
 else {
            code.append(pointerToTokensFromOneChannel + "String_Node_Str" + k+ "String_Node_Str");
          }
          code.append("String_Node_Str" + _eol);
        }
        if (type == BaseType.INT) {
          code.append(CCodegenUtilities.jniReleaseArrayElements("String_Node_Str",tokensFromOneChannel,pointerToTokensFromOneChannel,targetCpp) + "String_Node_Str" + _eol);
        }
 else         if (type == BaseType.DOUBLE) {
          code.append(CCodegenUtilities.jniReleaseArrayElements("String_Node_Str",tokensFromOneChannel,pointerToTokensFromOneChannel,targetCpp) + "String_Node_Str" + _eol);
        }
 else         if (type == PointerToken.POINTER) {
          code.append(CCodegenUtilities.jniReleaseArrayElements("String_Node_Str",tokensFromOneChannel,pointerToTokensFromOneChannel,targetCpp) + "String_Node_Str" + _eol);
        }
 else         if (type == BaseType.BOOLEAN) {
          code.append(CCodegenUtilities.jniReleaseArrayElements("String_Node_Str",tokensFromOneChannel,pointerToTokensFromOneChannel,targetCpp) + "String_Node_Str" + _eol);
        }
 else {
          throw new IllegalActionException(inputPort,exceptionMessage);
        }
      }
    }
  }
 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));
}

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);
  boolean targetCpp=((BooleanToken)getCodeGenerator().generateCpp.getToken()).booleanValue();
  CompositeActor container=(CompositeActor)getComponent().getContainer();
  TypedCompositeActor compositeActorAdapter=(TypedCompositeActor)getCodeGenerator().getAdapter(container);
  if (container instanceof CompiledCompositeActor && ((BooleanToken)getCodeGenerator().generateEmbeddedCode.getToken()).booleanValue()) {
    if (!(inputPort instanceof TypedIOPort)) {
      throw new InternalErrorException(inputPort,null,"String_Node_Str");
    }
    Type type=((TypedIOPort)inputPort).getType();
    String portName=inputPort.getName();
    String exceptionMessage="String_Node_Str" + "String_Node_Str" + "String_Node_Str" + portName + "String_Node_Str"+ type+ "String_Node_Str"+ "String_Node_Str"+ portName+ "String_Node_Str"+ "String_Node_Str";
    for (int i=0; i < inputPort.getWidth(); i++) {
      if (i < inputPort.getWidthInside()) {
        String tokensFromOneChannel="String_Node_Str" + portName + i;
        String pointerToTokensFromOneChannel="String_Node_Str" + tokensFromOneChannel;
        code.append("String_Node_Str" + tokensFromOneChannel + "String_Node_Str"+ CCodegenUtilities.jniGetObjectArrayElement(portName,String.valueOf(i),targetCpp)+ "String_Node_Str"+ _eol);
        if (type == BaseType.INT) {
          code.append("String_Node_Str" + pointerToTokensFromOneChannel + "String_Node_Str"+ CCodegenUtilities.jniGetArrayElements("String_Node_Str",tokensFromOneChannel,targetCpp)+ "String_Node_Str"+ _eol);
        }
 else         if (type == BaseType.DOUBLE) {
          code.append("String_Node_Str" + pointerToTokensFromOneChannel + "String_Node_Str"+ CCodegenUtilities.jniGetArrayElements("String_Node_Str",tokensFromOneChannel,targetCpp)+ "String_Node_Str"+ _eol);
        }
 else         if (type == PointerToken.POINTER) {
          code.append("String_Node_Str" + pointerToTokensFromOneChannel + "String_Node_Str"+ CCodegenUtilities.jniGetArrayElements("String_Node_Str",tokensFromOneChannel,targetCpp)+ "String_Node_Str"+ _eol);
        }
 else         if (type == BaseType.BOOLEAN) {
          code.append("String_Node_Str" + pointerToTokensFromOneChannel + "String_Node_Str"+ CCodegenUtilities.jniGetArrayElements("String_Node_Str",tokensFromOneChannel,targetCpp)+ "String_Node_Str"+ _eol);
        }
 else {
          throw new IllegalActionException(inputPort,exceptionMessage);
        }
        String portNameWithChannelNumber=portName;
        if (inputPort.isMultiport()) {
          portNameWithChannelNumber=portName + '#' + i;
        }
        for (int k=0; k < rate; k++) {
          String putString=_eol + "String_Node_Str" + CodeGeneratorAdapter.generateName(container)+ "String_Node_Str"+ CodeGeneratorAdapter.generateName(container)+ "String_Node_Str"+ inputPort.getName()+ "String_Node_Str"+ i+ "String_Node_Str"+ _eol;
          code.append(_eol + putString);
          if (type == PointerToken.POINTER) {
            code.append("String_Node_Str" + pointerToTokensFromOneChannel + "String_Node_Str"+ k+ "String_Node_Str");
          }
 else           if (type == BaseType.INT) {
            code.append("String_Node_Str" + pointerToTokensFromOneChannel + "String_Node_Str"+ k+ "String_Node_Str");
          }
 else           if (type == BaseType.DOUBLE) {
            code.append("String_Node_Str" + pointerToTokensFromOneChannel + "String_Node_Str"+ k+ "String_Node_Str");
          }
 else           if (type == BaseType.BOOLEAN) {
            code.append("String_Node_Str" + pointerToTokensFromOneChannel + "String_Node_Str"+ k+ "String_Node_Str");
          }
 else {
            throw new IllegalActionException(inputPort,exceptionMessage);
          }
          code.append("String_Node_Str" + _eol);
        }
        if (type == BaseType.INT) {
          code.append(CCodegenUtilities.jniReleaseArrayElements("String_Node_Str",tokensFromOneChannel,pointerToTokensFromOneChannel,targetCpp) + "String_Node_Str" + _eol);
        }
 else         if (type == BaseType.DOUBLE) {
          code.append(CCodegenUtilities.jniReleaseArrayElements("String_Node_Str",tokensFromOneChannel,pointerToTokensFromOneChannel,targetCpp) + "String_Node_Str" + _eol);
        }
 else         if (type == PointerToken.POINTER) {
          code.append(CCodegenUtilities.jniReleaseArrayElements("String_Node_Str",tokensFromOneChannel,pointerToTokensFromOneChannel,targetCpp) + "String_Node_Str" + _eol);
        }
 else         if (type == BaseType.BOOLEAN) {
          code.append(CCodegenUtilities.jniReleaseArrayElements("String_Node_Str",tokensFromOneChannel,pointerToTokensFromOneChannel,targetCpp) + "String_Node_Str" + _eol);
        }
 else {
          throw new IllegalActionException(inputPort,exceptionMessage);
        }
      }
    }
  }
 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));
}