Program: 74396
Project: 74396
Buggy source:
public String updateConnectedPortsOffset(int rate,Director director) throws IllegalActionException {
  boolean padBuffers=((BooleanToken)_codeGenerator.padBuffers.getToken()).booleanValue();
  ptolemy.actor.IOPort port=(ptolemy.actor.IOPort)getComponent();
  StringBuffer code=new StringBuffer();
  code.append(getCodeGenerator().comment("String_Node_Str" + port.getFullName()));
  if (rate == 0) {
    return "String_Node_Str";
  }
 else   if (rate < 0) {
    throw new IllegalActionException(port,"String_Node_Str" + rate + "String_Node_Str");
  }
  CodeGeneratorHelper helper=(CodeGeneratorHelper)_getHelper(port.getContainer());
  int length=0;
  if (port.isInput()) {
    length=port.getWidthInside();
  }
 else {
    length=port.getWidth();
  }
  for (int j=0; j < length; j++) {
    List sinkChannels=helper.getSinkChannels(port,j);
    for (int k=0; k < sinkChannels.size(); k++) {
      Channel channel=(Channel)sinkChannels.get(k);
      ptolemy.actor.IOPort sinkPort=channel.port;
      int sinkChannelNumber=channel.channelNumber;
      Object offsetObject=helper.getWriteOffset(sinkPort,sinkChannelNumber);
      Receiver receiver=_getReceiver(offsetObject.toString(),sinkChannelNumber,sinkPort);
      if (isMpi() && MpiPNDirector.isMpiReceiveBuffer(sinkPort,j)) {
        code.append(_generateMPISendCode(j,rate,sinkPort,sinkChannelNumber,director));
      }
 else       if (!isMpi() && receiver instanceof PNQueueReceiver) {
        code.append(_updatePNOffset(rate,sinkPort,sinkChannelNumber,director,true));
      }
 else {
        if (offsetObject instanceof Integer) {
          int offset=((Integer)offsetObject).intValue();
          int bufferSize=helper.getBufferSize(sinkPort,sinkChannelNumber);
          if (bufferSize != 0) {
            offset=(offset + rate) % bufferSize;
          }
          helper.setWriteOffset(sinkPort,sinkChannelNumber,Integer.valueOf(offset));
        }
 else {
          String offsetVariable=(String)helper.getWriteOffset(sinkPort,sinkChannelNumber);
          if (padBuffers) {
            int modulo=helper.getBufferSize(sinkPort,sinkChannelNumber) - 1;
            code.append(offsetVariable + "String_Node_Str" + offsetVariable+ "String_Node_Str"+ rate+ "String_Node_Str"+ modulo+ "String_Node_Str"+ _eol);
          }
 else {
            code.append(offsetVariable + "String_Node_Str" + offsetVariable+ "String_Node_Str"+ rate+ "String_Node_Str"+ helper.getBufferSize(sinkPort,sinkChannelNumber)+ "String_Node_Str"+ _eol);
          }
        }
      }
    }
  }
  code.append(getCodeGenerator().comment("String_Node_Str" + port.getFullName()));
  return code.toString();
}

Fixed version (ground truth):
public String updateConnectedPortsOffset(int rate,Director director) throws IllegalActionException {
  boolean padBuffers=((BooleanToken)_codeGenerator.padBuffers.getToken()).booleanValue();
  ptolemy.actor.IOPort port=(ptolemy.actor.IOPort)getComponent();
  StringBuffer code=new StringBuffer();
  code.append(getCodeGenerator().comment("String_Node_Str" + port.getFullName()));
  if (rate == 0) {
    return "String_Node_Str";
  }
 else   if (rate < 0) {
    throw new IllegalActionException(port,"String_Node_Str" + rate + "String_Node_Str");
  }
  CodeGeneratorHelper helper=(CodeGeneratorHelper)_getHelper(port.getContainer());
  int length=0;
  if (port.isInput()) {
    length=port.getWidthInside();
  }
 else {
    length=port.getWidth();
  }
  for (int j=0; j < length; j++) {
    List sinkChannels=helper.getSinkChannels(port,j);
    for (int k=0; k < sinkChannels.size(); k++) {
      Channel channel=(Channel)sinkChannels.get(k);
      ptolemy.actor.IOPort sinkPort=channel.port;
      int sinkChannelNumber=channel.channelNumber;
      Object offsetObject=helper.getWriteOffset(sinkPort,sinkChannelNumber);
      Receiver receiver=_getReceiver(offsetObject.toString(),sinkChannelNumber,sinkPort);
      if (isMpi() && MpiPNDirector.isMpiReceiveBuffer(sinkPort,sinkChannelNumber)) {
        code.append(_generateMPISendCode(j,rate,sinkPort,sinkChannelNumber,director));
      }
 else       if (!isMpi() && receiver instanceof PNQueueReceiver) {
        code.append(_updatePNOffset(rate,sinkPort,sinkChannelNumber,director,true));
      }
 else {
        if (offsetObject instanceof Integer) {
          int offset=((Integer)offsetObject).intValue();
          int bufferSize=helper.getBufferSize(sinkPort,sinkChannelNumber);
          if (bufferSize != 0) {
            offset=(offset + rate) % bufferSize;
          }
          helper.setWriteOffset(sinkPort,sinkChannelNumber,Integer.valueOf(offset));
        }
 else {
          String offsetVariable=(String)helper.getWriteOffset(sinkPort,sinkChannelNumber);
          if (padBuffers) {
            int modulo=helper.getBufferSize(sinkPort,sinkChannelNumber) - 1;
            code.append(offsetVariable + "String_Node_Str" + offsetVariable+ "String_Node_Str"+ rate+ "String_Node_Str"+ modulo+ "String_Node_Str"+ _eol);
          }
 else {
            code.append(offsetVariable + "String_Node_Str" + offsetVariable+ "String_Node_Str"+ rate+ "String_Node_Str"+ helper.getBufferSize(sinkPort,sinkChannelNumber)+ "String_Node_Str"+ _eol);
          }
        }
      }
    }
  }
  code.append(getCodeGenerator().comment("String_Node_Str" + port.getFullName()));
  return code.toString();
}