Program: 74069
Project: 74069
Buggy source:
/** 
 * Return an unique label for the given port channel referenced by the given helper. By default, this delegates to the helper to  generate the reference. Subclass may override this method to generate the desire label according to the given parameters.
 * @param port The given port.
 * @param channelAndOffset The given channel and offset.
 * @param forComposite Whether the given helper is associated witha CompositeActor
 * @param isWrite The type of the reference. True if this isa write reference; otherwise, this is a read reference.  
 * @param target The ProgramCodeGeneratorAdapter for which code needs to be generated.
 * @return an unique reference label for the given port channel.
 * @throws IllegalActionException If the helper throws it whilegenerating the label.     
 */
public String getReference(TypedIOPort port,String[] channelAndOffset,boolean forComposite,boolean isWrite,ProgramCodeGeneratorAdapter target) throws IllegalActionException {
  StringBuffer result=new StringBuffer();
  boolean dynamicReferencesAllowed=allowDynamicMultiportReference();
  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 ProgramCodeGeneratorAdapterStrategy.generatePortReference(port,channelAndOffset,isWrite);
    }
  }
  if (ProgramCodeGeneratorAdapterStrategy.checkRemote(forComposite,port)) {
    Receiver[][] remoteReceivers;
    if (port.isOutput()) {
      remoteReceivers=port.getRemoteReceivers();
    }
 else {
      remoteReceivers=port.deepGetReceivers();
    }
    if (remoteReceivers.length == 0) {
      result.append(ProgramCodeGeneratorAdapterStrategy.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=ProgramCodeGeneratorAdapterStrategy.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(ProgramCodeGeneratorAdapterStrategy.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" + ProgramCodeGeneratorAdapterStrategy.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(ProgramCodeGeneratorAdapterStrategy.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 (ProgramCodeGeneratorAdapterStrategy.checkLocal(forComposite,port)) {
    result.append(ProgramCodeGeneratorAdapterStrategy.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):
/** 
 * Return an unique label for the given port channel referenced by the given helper. By default, this delegates to the helper to  generate the reference. Subclass may override this method to generate the desire label according to the given parameters.
 * @param port The given port.
 * @param channelAndOffset The given channel and offset.
 * @param forComposite Whether the given helper is associated witha CompositeActor
 * @param isWrite The type of the reference. True if this isa write reference; otherwise, this is a read reference.  
 * @param target The ProgramCodeGeneratorAdapter for which code needs to be generated.
 * @return an unique reference label for the given port channel.
 * @throws IllegalActionException If the helper throws it whilegenerating the label.     
 */
public String getReference(TypedIOPort port,String[] channelAndOffset,boolean forComposite,boolean isWrite,ProgramCodeGeneratorAdapter target) throws IllegalActionException {
  StringBuffer result=new StringBuffer();
  boolean dynamicReferencesAllowed=allowDynamicMultiportReference();
  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 ProgramCodeGeneratorAdapterStrategy.generatePortReference(port,channelAndOffset,isWrite);
    }
  }
  if (ProgramCodeGeneratorAdapterStrategy.checkRemote(forComposite,port)) {
    Receiver[][] remoteReceivers;
    if (port.isOutput()) {
      remoteReceivers=port.getRemoteReceivers();
    }
 else {
      remoteReceivers=port.deepGetReceivers();
    }
    if (remoteReceivers.length == 0) {
      result.append(ProgramCodeGeneratorAdapterStrategy.generateName(target.getComponent()));
      result.append("String_Node_Str");
      result.append(port.getName());
      return result.toString();
    }
    Channel sourceChannel=new Channel(port,channelNumber);
    List<Channel> typeConvertSinks=target.getStrategy().getTypeConvertSinkChannels(sourceChannel);
    List<Channel> sinkChannels=ProgramCodeGeneratorAdapterStrategy.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(ProgramCodeGeneratorAdapterStrategy.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" + ProgramCodeGeneratorAdapterStrategy.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(ProgramCodeGeneratorAdapterStrategy.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 (ProgramCodeGeneratorAdapterStrategy.checkLocal(forComposite,port)) {
    result.append(ProgramCodeGeneratorAdapterStrategy.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";
}