Program: 74177
Project: 74177
Buggy source:
public String getReference(TypedIOPort port,String[] channelAndOffset,boolean forComposite,boolean isWrite,CodeGeneratorAdapter target) throws IllegalActionException {
  StringBuffer result=new StringBuffer();
  boolean dynamicReferencesAllowed=((BooleanToken)getCodeGenerator().allowDynamicMultiportReference.getToken()).booleanValue();
  int channelNumber=0;
  boolean isChannelNumberInt=true;
  if (!channelAndOffset[0].equals("String_Node_Str")) {
    if (dynamicReferencesAllowed) {
      try {
        channelNumber=(Integer.valueOf(channelAndOffset[0])).intValue();
      }
 catch (      Exception ex) {
        isChannelNumberInt=false;
      }
    }
 else {
      channelNumber=(Integer.valueOf(channelAndOffset[0])).intValue();
    }
  }
  if (!isChannelNumberInt) {
    if (port.isOutput()) {
      throw new IllegalActionException("String_Node_Str" + "String_Node_Str");
    }
 else {
      return CodeGeneratorAdapterStrategy.generatePortReference(port,channelAndOffset,isWrite);
    }
  }
  if (CodeGeneratorAdapterStrategy.checkRemote(forComposite,port)) {
    Receiver[][] remoteReceivers;
    if (port.isOutput()) {
      remoteReceivers=port.getRemoteReceivers();
    }
 else {
      remoteReceivers=port.deepGetReceivers();
    }
    if (remoteReceivers.length == 0) {
      result.append(CodeGeneratorAdapterStrategy.generateName(target.getComponent()));
      result.append("String_Node_Str");
      result.append(port.getName());
      return result.toString();
    }
    Channel sourceChannel=new Channel(port,channelNumber);
    List<Channel> typeConvertSinks=getStrategy()._getTypeConvertSinkChannels(sourceChannel);
    List<Channel> sinkChannels=CodeGeneratorAdapterStrategy.getSinkChannels(port,channelNumber);
    boolean hasTypeConvertReference=false;
    for (int i=0; i < sinkChannels.size(); i++) {
      Channel channel=sinkChannels.get(i);
      IOPort sinkPort=channel.port;
      int sinkChannelNumber=channel.channelNumber;
      if (typeConvertSinks.contains(channel) && getStrategy().isPrimitive(((TypedIOPort)sourceChannel.port).getType())) {
        if (!hasTypeConvertReference) {
          if (i != 0) {
            result.append("String_Node_Str");
          }
          result.append(CodeGeneratorAdapterStrategy.getTypeConvertReference(sourceChannel));
          if (dynamicReferencesAllowed && port.isInput()) {
            if (channelAndOffset[1].trim().length() > 0) {
              result.append("String_Node_Str" + channelAndOffset[1].trim() + "String_Node_Str");
            }
 else {
              result.append("String_Node_Str" + CodeGeneratorAdapterStrategy.generateChannelOffset(port,isWrite,channelAndOffset[0]) + "String_Node_Str");
            }
          }
 else {
            int rate=Math.max(DFUtilities.getTokenProductionRate(sourceChannel.port),DFUtilities.getTokenConsumptionRate(sourceChannel.port));
            if (rate > 1 && channelAndOffset[1].trim().length() > 0) {
              result.append("String_Node_Str" + channelAndOffset[1].trim() + "String_Node_Str");
            }
          }
          hasTypeConvertReference=true;
        }
 else {
          continue;
        }
      }
 else {
        if (i != 0) {
          result.append("String_Node_Str");
        }
        result.append(CodeGeneratorAdapterStrategy.generateName(sinkPort));
        if (sinkPort.isMultiport()) {
          result.append("String_Node_Str" + sinkChannelNumber + "String_Node_Str");
        }
        if (channelAndOffset[1].equals("String_Node_Str")) {
          channelAndOffset[1]="String_Node_Str";
        }
        result.append(_ports.generateOffset(sinkPort,channelAndOffset[1],sinkChannelNumber,true));
      }
    }
    return result.toString();
  }
  if (CodeGeneratorAdapterStrategy.checkLocal(forComposite,port)) {
    result.append(CodeGeneratorAdapterStrategy.generateName(port));
    if (port.isMultiport()) {
      result.append("String_Node_Str" + channelAndOffset[0] + "String_Node_Str");
    }
    result.append(_ports.generateOffset(port,channelAndOffset[1],channelNumber,isWrite));
    return result.toString();
  }
  return "String_Node_Str";
}

Fixed version (ground truth):
/** 
 * @param target The CodeGeneratorAdapter for which code needs to be generated.
 */
public String getReference(TypedIOPort port,String[] channelAndOffset,boolean forComposite,boolean isWrite,CodeGeneratorAdapter target) throws IllegalActionException {
  StringBuffer result=new StringBuffer();
  boolean dynamicReferencesAllowed=((BooleanToken)getCodeGenerator().allowDynamicMultiportReference.getToken()).booleanValue();
  int channelNumber=0;
  boolean isChannelNumberInt=true;
  if (!channelAndOffset[0].equals("String_Node_Str")) {
    if (dynamicReferencesAllowed) {
      try {
        channelNumber=(Integer.valueOf(channelAndOffset[0])).intValue();
      }
 catch (      Exception ex) {
        isChannelNumberInt=false;
      }
    }
 else {
      channelNumber=(Integer.valueOf(channelAndOffset[0])).intValue();
    }
  }
  if (!isChannelNumberInt) {
    if (port.isOutput()) {
      throw new IllegalActionException("String_Node_Str" + "String_Node_Str");
    }
 else {
      return CodeGeneratorAdapterStrategy.generatePortReference(port,channelAndOffset,isWrite);
    }
  }
  if (CodeGeneratorAdapterStrategy.checkRemote(forComposite,port)) {
    Receiver[][] remoteReceivers;
    if (port.isOutput()) {
      remoteReceivers=port.getRemoteReceivers();
    }
 else {
      remoteReceivers=port.deepGetReceivers();
    }
    if (remoteReceivers.length == 0) {
      result.append(CodeGeneratorAdapterStrategy.generateName(target.getComponent()));
      result.append("String_Node_Str");
      result.append(port.getName());
      return result.toString();
    }
    Channel sourceChannel=new Channel(port,channelNumber);
    List<Channel> typeConvertSinks=getStrategy()._getTypeConvertSinkChannels(sourceChannel);
    List<Channel> sinkChannels=CodeGeneratorAdapterStrategy.getSinkChannels(port,channelNumber);
    boolean hasTypeConvertReference=false;
    for (int i=0; i < sinkChannels.size(); i++) {
      Channel channel=sinkChannels.get(i);
      IOPort sinkPort=channel.port;
      int sinkChannelNumber=channel.channelNumber;
      if (typeConvertSinks.contains(channel) && getStrategy().isPrimitive(((TypedIOPort)sourceChannel.port).getType())) {
        if (!hasTypeConvertReference) {
          if (i != 0) {
            result.append("String_Node_Str");
          }
          result.append(CodeGeneratorAdapterStrategy.getTypeConvertReference(sourceChannel));
          if (dynamicReferencesAllowed && port.isInput()) {
            if (channelAndOffset[1].trim().length() > 0) {
              result.append("String_Node_Str" + channelAndOffset[1].trim() + "String_Node_Str");
            }
 else {
              result.append("String_Node_Str" + CodeGeneratorAdapterStrategy.generateChannelOffset(port,isWrite,channelAndOffset[0]) + "String_Node_Str");
            }
          }
 else {
            int rate=Math.max(DFUtilities.getTokenProductionRate(sourceChannel.port),DFUtilities.getTokenConsumptionRate(sourceChannel.port));
            if (rate > 1 && channelAndOffset[1].trim().length() > 0) {
              result.append("String_Node_Str" + channelAndOffset[1].trim() + "String_Node_Str");
            }
          }
          hasTypeConvertReference=true;
        }
 else {
          continue;
        }
      }
 else {
        if (i != 0) {
          result.append("String_Node_Str");
        }
        result.append(CodeGeneratorAdapterStrategy.generateName(sinkPort));
        if (sinkPort.isMultiport()) {
          result.append("String_Node_Str" + sinkChannelNumber + "String_Node_Str");
        }
        if (channelAndOffset[1].equals("String_Node_Str")) {
          channelAndOffset[1]="String_Node_Str";
        }
        result.append(_ports.generateOffset(sinkPort,channelAndOffset[1],sinkChannelNumber,true));
      }
    }
    return result.toString();
  }
  if (CodeGeneratorAdapterStrategy.checkLocal(forComposite,port)) {
    result.append(CodeGeneratorAdapterStrategy.generateName(port));
    if (port.isMultiport()) {
      result.append("String_Node_Str" + channelAndOffset[0] + "String_Node_Str");
    }
    result.append(_ports.generateOffset(port,channelAndOffset[1],channelNumber,isWrite));
    return result.toString();
  }
  return "String_Node_Str";
}