Program: 73843
Project: 73843
Buggy source:
/** 
 * Generate code for transferring enough tokens to fulfill the output production rate.
 * @param outputPort 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 generateTransferOutputsCode(IOPort outputPort,StringBuffer code) throws IllegalActionException {
  code.append(CodeStream.indent(getCodeGenerator().comment("String_Node_Str" + "String_Node_Str")));
  int rate=DFUtilities.getTokenProductionRate(outputPort);
  boolean targetCpp=((BooleanToken)((CCodeGenerator)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 (_portNumber == 0) {
      int numberOfOutputPorts=container.outputPortList().size();
      code.append("String_Node_Str" + _eol);
      code.append("String_Node_Str" + _objClass + "String_Node_Str"+ CCodegenUtilities.jniFindClass("String_Node_Str",targetCpp)+ "String_Node_Str"+ _eol);
      code.append("String_Node_Str" + CCodegenUtilities.jniNewObjectArray(String.valueOf(numberOfOutputPorts),"String_Node_Str",targetCpp) + "String_Node_Str"+ _eol);
    }
    String portName=outputPort.getName();
    String tokensToThisPort="String_Node_Str" + portName;
    if (!(outputPort instanceof TypedIOPort)) {
      throw new InternalErrorException(outputPort,null,"String_Node_Str");
    }
    Type type=((TypedIOPort)outputPort).getType();
    int numberOfChannels=outputPort.getWidthInside();
    code.append("String_Node_Str" + tokensToThisPort + "String_Node_Str"+ _eol);
    if (type == BaseType.INT) {
      if (!_intFlag) {
        code.append("String_Node_Str" + _objClassI + "String_Node_Str"+ CCodegenUtilities.jniFindClass("String_Node_Str",targetCpp)+ "String_Node_Str"+ _eol);
        _intFlag=true;
      }
      code.append(tokensToThisPort + "String_Node_Str" + CCodegenUtilities.jniNewObjectArray(String.valueOf(numberOfChannels),_objClassI,targetCpp)+ "String_Node_Str"+ _eol);
    }
 else     if (type == BaseType.DOUBLE) {
      if (!_doubleFlag) {
        code.append("String_Node_Str" + _objClassD + "String_Node_Str"+ CCodegenUtilities.jniFindClass("String_Node_Str",targetCpp)+ "String_Node_Str"+ _eol);
        _doubleFlag=true;
      }
      code.append(tokensToThisPort + "String_Node_Str" + CCodegenUtilities.jniNewObjectArray(String.valueOf(numberOfChannels),_objClassD,targetCpp)+ "String_Node_Str"+ _eol);
    }
 else     if (type == PointerToken.POINTER) {
      if (!_intFlag) {
        code.append("String_Node_Str" + _objClassI + "String_Node_Str"+ CCodegenUtilities.jniFindClass("String_Node_Str",targetCpp)+ "String_Node_Str"+ _eol);
        _intFlag=true;
      }
      code.append(tokensToThisPort + "String_Node_Str" + CCodegenUtilities.jniNewObjectArray(String.valueOf(numberOfChannels),_objClassI,targetCpp)+ "String_Node_Str"+ _eol);
    }
 else     if (type == BaseType.BOOLEAN) {
      if (!_booleanFlag) {
        code.append("String_Node_Str" + CCodegenUtilities.jniFindClass("String_Node_Str",targetCpp) + "String_Node_Str"+ _eol);
        _booleanFlag=true;
      }
      code.append(tokensToThisPort + "String_Node_Str" + CCodegenUtilities.jniNewObjectArray(String.valueOf(numberOfChannels),"String_Node_Str",targetCpp)+ "String_Node_Str"+ _eol);
    }
 else {
    }
    for (int i=0; i < outputPort.getWidthInside(); i++) {
      String tokensToOneChannel="String_Node_Str" + portName;
      if (i == 0) {
        if (type == BaseType.INT) {
          code.append("String_Node_Str" + tokensToOneChannel + "String_Node_Str"+ rate+ "String_Node_Str"+ _eol);
        }
 else         if (type == BaseType.DOUBLE) {
          code.append("String_Node_Str" + tokensToOneChannel + "String_Node_Str"+ rate+ "String_Node_Str"+ _eol);
        }
 else         if (type == PointerToken.POINTER) {
          code.append("String_Node_Str" + tokensToOneChannel + "String_Node_Str"+ rate+ "String_Node_Str"+ _eol);
        }
 else         if (type == BaseType.BOOLEAN) {
          code.append("String_Node_Str" + tokensToOneChannel + "String_Node_Str"+ rate+ "String_Node_Str"+ _eol);
        }
 else {
        }
      }
      String portNameWithChannelNumber=portName;
      if (outputPort.isMultiport()) {
        portNameWithChannelNumber=portName + '#' + i;
      }
      for (int k=0; k < rate; k++) {
        String portReference=compositeActorAdapter.getReference("String_Node_Str" + portNameWithChannelNumber + "String_Node_Str"+ k);
        if (type == PointerToken.POINTER) {
          code.append(tokensToOneChannel + "String_Node_Str" + k+ "String_Node_Str"+ "String_Node_Str"+ portReference+ "String_Node_Str"+ _eol);
        }
 else {
          code.append(tokensToOneChannel + "String_Node_Str" + k+ "String_Node_Str"+ portReference+ "String_Node_Str"+ _eol);
        }
      }
      String tokensToOneChannelArray="String_Node_Str" + portName + i;
      if (type == BaseType.INT) {
        code.append("String_Node_Str" + tokensToOneChannelArray + "String_Node_Str"+ CCodegenUtilities.jniNewArray("String_Node_Str",String.valueOf(rate),targetCpp)+ "String_Node_Str"+ _eol);
        code.append(CCodegenUtilities.jniSetArrayRegion("String_Node_Str",tokensToOneChannelArray,"String_Node_Str",String.valueOf(rate),tokensToOneChannel,targetCpp) + "String_Node_Str" + _eol);
      }
 else       if (type == BaseType.DOUBLE) {
        code.append("String_Node_Str" + tokensToOneChannelArray + "String_Node_Str"+ CCodegenUtilities.jniNewArray("String_Node_Str",String.valueOf(rate),targetCpp)+ "String_Node_Str"+ _eol);
        code.append(CCodegenUtilities.jniSetArrayRegion("String_Node_Str",tokensToOneChannelArray,"String_Node_Str",String.valueOf(rate),tokensToOneChannel,targetCpp) + "String_Node_Str" + _eol);
      }
 else       if (type == PointerToken.POINTER) {
        code.append("String_Node_Str" + tokensToOneChannelArray + "String_Node_Str"+ CCodegenUtilities.jniNewArray("String_Node_Str",String.valueOf(rate),targetCpp)+ "String_Node_Str"+ _eol);
        code.append(CCodegenUtilities.jniSetArrayRegion("String_Node_Str",tokensToOneChannelArray,"String_Node_Str",String.valueOf(rate),tokensToOneChannel,targetCpp) + "String_Node_Str" + _eol);
      }
 else       if (type == BaseType.BOOLEAN) {
        code.append("String_Node_Str" + tokensToOneChannelArray + "String_Node_Str"+ CCodegenUtilities.jniNewArray("String_Node_Str",String.valueOf(rate),targetCpp)+ "String_Node_Str"+ _eol);
        code.append(CCodegenUtilities.jniSetArrayRegion("String_Node_Str",tokensToOneChannelArray,"String_Node_Str",String.valueOf(rate),tokensToOneChannel,targetCpp) + "String_Node_Str" + _eol);
      }
 else {
      }
      code.append(CCodegenUtilities.jniSetObjectArrayElement(tokensToThisPort,String.valueOf(i),tokensToOneChannelArray,targetCpp) + "String_Node_Str" + _eol);
      code.append(CCodegenUtilities.jniDeleteLocalRef(tokensToOneChannelArray,targetCpp) + "String_Node_Str" + _eol);
    }
    code.append(CCodegenUtilities.jniSetObjectArrayElement("String_Node_Str",String.valueOf(_portNumber),tokensToThisPort,targetCpp) + "String_Node_Str" + _eol);
    code.append(CCodegenUtilities.jniDeleteLocalRef(tokensToThisPort,targetCpp) + "String_Node_Str" + _eol);
    _portNumber++;
  }
 else {
    for (int i=0; i < outputPort.getWidthInside(); i++) {
      if (i < outputPort.getWidth()) {
        String name=outputPort.getName();
        if (outputPort.isMultiport()) {
          name=name + '#' + i;
        }
        for (int k=0; k < rate; k++) {
          code.append(CodeStream.indent(compositeActorAdapter.getReference(name + "String_Node_Str" + k)));
          code.append("String_Node_Str" + _eol);
          code.append(CodeStream.indent(compositeActorAdapter.getReference("String_Node_Str" + name + "String_Node_Str"+ k)));
          code.append("String_Node_Str" + _eol);
        }
      }
    }
  }
  _updatePortOffset(outputPort,code,rate);
}

Fixed version (ground truth):
/** 
 * Generate code for transferring enough tokens to fulfill the output production rate.
 * @param outputPort 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 generateTransferOutputsCode(IOPort outputPort,StringBuffer code) throws IllegalActionException {
  code.append(CodeStream.indent(getCodeGenerator().comment("String_Node_Str" + "String_Node_Str")));
  int rate=DFUtilities.getTokenProductionRate(outputPort);
  boolean targetCpp=((BooleanToken)((CCodeGenerator)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 (_portNumber == 0) {
      int numberOfOutputPorts=container.outputPortList().size();
      code.append("String_Node_Str" + _eol);
      code.append("String_Node_Str" + _objClass + "String_Node_Str"+ CCodegenUtilities.jniFindClass("String_Node_Str",targetCpp)+ "String_Node_Str"+ _eol);
      code.append("String_Node_Str" + CCodegenUtilities.jniNewObjectArray(String.valueOf(numberOfOutputPorts),"String_Node_Str",targetCpp) + "String_Node_Str"+ _eol);
    }
    String portName=outputPort.getName();
    String tokensToThisPort="String_Node_Str" + portName;
    if (!(outputPort instanceof TypedIOPort)) {
      throw new InternalErrorException(outputPort,null,"String_Node_Str");
    }
    Type type=((TypedIOPort)outputPort).getType();
    int numberOfChannels=outputPort.getWidthInside();
    code.append("String_Node_Str" + tokensToThisPort + "String_Node_Str"+ _eol);
    if (type == BaseType.INT) {
      if (!_intFlag) {
        code.append("String_Node_Str" + _objClassI + "String_Node_Str"+ CCodegenUtilities.jniFindClass("String_Node_Str",targetCpp)+ "String_Node_Str"+ _eol);
        _intFlag=true;
      }
      code.append(tokensToThisPort + "String_Node_Str" + CCodegenUtilities.jniNewObjectArray(String.valueOf(numberOfChannels),_objClassI,targetCpp)+ "String_Node_Str"+ _eol);
    }
 else     if (type == BaseType.DOUBLE) {
      if (!_doubleFlag) {
        code.append("String_Node_Str" + _objClassD + "String_Node_Str"+ CCodegenUtilities.jniFindClass("String_Node_Str",targetCpp)+ "String_Node_Str"+ _eol);
        _doubleFlag=true;
      }
      code.append(tokensToThisPort + "String_Node_Str" + CCodegenUtilities.jniNewObjectArray(String.valueOf(numberOfChannels),_objClassD,targetCpp)+ "String_Node_Str"+ _eol);
    }
 else     if (type == PointerToken.POINTER) {
      if (!_intFlag) {
        code.append("String_Node_Str" + _objClassI + "String_Node_Str"+ CCodegenUtilities.jniFindClass("String_Node_Str",targetCpp)+ "String_Node_Str"+ _eol);
        _intFlag=true;
      }
      code.append(tokensToThisPort + "String_Node_Str" + CCodegenUtilities.jniNewObjectArray(String.valueOf(numberOfChannels),_objClassI,targetCpp)+ "String_Node_Str"+ _eol);
    }
 else     if (type == BaseType.BOOLEAN) {
      if (!_booleanFlag) {
        code.append("String_Node_Str" + CCodegenUtilities.jniFindClass("String_Node_Str",targetCpp) + "String_Node_Str"+ _eol);
        _booleanFlag=true;
      }
      code.append(tokensToThisPort + "String_Node_Str" + CCodegenUtilities.jniNewObjectArray(String.valueOf(numberOfChannels),"String_Node_Str",targetCpp)+ "String_Node_Str"+ _eol);
    }
 else {
    }
    for (int i=0; i < outputPort.getWidthInside(); i++) {
      String tokensToOneChannel="String_Node_Str" + portName;
      if (i == 0) {
        if (type == BaseType.INT) {
          code.append("String_Node_Str" + tokensToOneChannel + "String_Node_Str"+ rate+ "String_Node_Str"+ _eol);
        }
 else         if (type == BaseType.DOUBLE) {
          code.append("String_Node_Str" + tokensToOneChannel + "String_Node_Str"+ rate+ "String_Node_Str"+ _eol);
        }
 else         if (type == PointerToken.POINTER) {
          code.append("String_Node_Str" + tokensToOneChannel + "String_Node_Str"+ rate+ "String_Node_Str"+ _eol);
        }
 else         if (type == BaseType.BOOLEAN) {
          code.append("String_Node_Str" + tokensToOneChannel + "String_Node_Str"+ rate+ "String_Node_Str"+ _eol);
        }
 else {
        }
      }
      String portNameWithChannelNumber=portName;
      if (outputPort.isMultiport()) {
        portNameWithChannelNumber=portName + '#' + i;
      }
      for (int k=0; k < rate; k++) {
        String portReference=compositeActorAdapter.getReference("String_Node_Str" + portNameWithChannelNumber + "String_Node_Str"+ k,false);
        if (type == PointerToken.POINTER) {
          code.append(tokensToOneChannel + "String_Node_Str" + k+ "String_Node_Str"+ "String_Node_Str"+ portReference+ "String_Node_Str"+ _eol);
        }
 else {
          code.append(tokensToOneChannel + "String_Node_Str" + k+ "String_Node_Str"+ portReference+ "String_Node_Str"+ _eol);
        }
      }
      String tokensToOneChannelArray="String_Node_Str" + portName + i;
      if (type == BaseType.INT) {
        code.append("String_Node_Str" + tokensToOneChannelArray + "String_Node_Str"+ CCodegenUtilities.jniNewArray("String_Node_Str",String.valueOf(rate),targetCpp)+ "String_Node_Str"+ _eol);
        code.append(CCodegenUtilities.jniSetArrayRegion("String_Node_Str",tokensToOneChannelArray,"String_Node_Str",String.valueOf(rate),tokensToOneChannel,targetCpp) + "String_Node_Str" + _eol);
      }
 else       if (type == BaseType.DOUBLE) {
        code.append("String_Node_Str" + tokensToOneChannelArray + "String_Node_Str"+ CCodegenUtilities.jniNewArray("String_Node_Str",String.valueOf(rate),targetCpp)+ "String_Node_Str"+ _eol);
        code.append(CCodegenUtilities.jniSetArrayRegion("String_Node_Str",tokensToOneChannelArray,"String_Node_Str",String.valueOf(rate),tokensToOneChannel,targetCpp) + "String_Node_Str" + _eol);
      }
 else       if (type == PointerToken.POINTER) {
        code.append("String_Node_Str" + tokensToOneChannelArray + "String_Node_Str"+ CCodegenUtilities.jniNewArray("String_Node_Str",String.valueOf(rate),targetCpp)+ "String_Node_Str"+ _eol);
        code.append(CCodegenUtilities.jniSetArrayRegion("String_Node_Str",tokensToOneChannelArray,"String_Node_Str",String.valueOf(rate),tokensToOneChannel,targetCpp) + "String_Node_Str" + _eol);
      }
 else       if (type == BaseType.BOOLEAN) {
        code.append("String_Node_Str" + tokensToOneChannelArray + "String_Node_Str"+ CCodegenUtilities.jniNewArray("String_Node_Str",String.valueOf(rate),targetCpp)+ "String_Node_Str"+ _eol);
        code.append(CCodegenUtilities.jniSetArrayRegion("String_Node_Str",tokensToOneChannelArray,"String_Node_Str",String.valueOf(rate),tokensToOneChannel,targetCpp) + "String_Node_Str" + _eol);
      }
 else {
      }
      code.append(CCodegenUtilities.jniSetObjectArrayElement(tokensToThisPort,String.valueOf(i),tokensToOneChannelArray,targetCpp) + "String_Node_Str" + _eol);
      code.append(CCodegenUtilities.jniDeleteLocalRef(tokensToOneChannelArray,targetCpp) + "String_Node_Str" + _eol);
    }
    code.append(CCodegenUtilities.jniSetObjectArrayElement("String_Node_Str",String.valueOf(_portNumber),tokensToThisPort,targetCpp) + "String_Node_Str" + _eol);
    code.append(CCodegenUtilities.jniDeleteLocalRef(tokensToThisPort,targetCpp) + "String_Node_Str" + _eol);
    _portNumber++;
  }
 else {
    for (int i=0; i < outputPort.getWidthInside(); i++) {
      if (i < outputPort.getWidth()) {
        String name=outputPort.getName();
        if (outputPort.isMultiport()) {
          name=name + '#' + i;
        }
        for (int k=0; k < rate; k++) {
          code.append(CodeStream.indent(compositeActorAdapter.getReference(name + "String_Node_Str" + k,false)));
          code.append("String_Node_Str" + _eol);
          code.append(CodeStream.indent(compositeActorAdapter.getReference("String_Node_Str" + name + "String_Node_Str"+ k,false)));
          code.append("String_Node_Str" + _eol);
        }
      }
    }
  }
  _updatePortOffset(outputPort,code,rate);
}