Program: 73411
Project: 73411
Buggy source:
/** 
 * Return an unique label for the given port channel referenced by the given adapter. By default, this delegates to the adapter 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 adapter 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 codeneeds to be generated.
 * @return an unique reference label for the given port channel.
 * @exception IllegalActionException If the adapter throws it whilegenerating the label.     
 */
public String getReference(TypedIOPort port,String[] channelAndOffset,boolean forComposite,boolean isWrite,NamedProgramCodeGeneratorAdapter target) throws IllegalActionException {
  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 {
      String returnValue=_generatePortReference(port,channelAndOffset,isWrite);
      return returnValue;
    }
  }
  StringBuffer result=new StringBuffer();
  if (_checkRemote(forComposite,port)) {
    Receiver[][] remoteReceivers;
    if (port.isOutput()) {
      remoteReceivers=port.getRemoteReceivers();
    }
 else {
      remoteReceivers=port.deepGetReceivers();
    }
    if (remoteReceivers.length == 0) {
      String returnValue=generatePortName(port);
      return returnValue;
    }
    ProgramCodeGeneratorAdapter.Channel sourceChannel=new ProgramCodeGeneratorAdapter.Channel(port,channelNumber);
    List<ProgramCodeGeneratorAdapter.Channel> typeConvertSinks=target.getTypeConvertSinkChannels(sourceChannel);
    List<ProgramCodeGeneratorAdapter.Channel> sinkChannels=getSinkChannels(port,channelNumber);
    boolean hasTypeConvertReference=false;
    for (int i=0; i < sinkChannels.size(); i++) {
      ProgramCodeGeneratorAdapter.Channel channel=sinkChannels.get(i);
      IOPort sinkPort=channel.port;
      int sinkChannelNumber=channel.channelNumber;
      if (typeConvertSinks.contains(channel) && getCodeGenerator().isPrimitive(((TypedIOPort)sourceChannel.port).getType())) {
        if (!hasTypeConvertReference) {
          if (i != 0) {
            result.append("String_Node_Str");
          }
          result.append(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" + _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(generatePortName((TypedIOPort)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 (_checkLocal(forComposite,port)) {
    result.append(generatePortName(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 adapter. By default, this delegates to the adapter 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 adapter 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 codeneeds to be generated.
 * @return an unique reference label for the given port channel.
 * @exception IllegalActionException If the adapter throws it whilegenerating the label.     
 */
public String getReference(TypedIOPort port,String[] channelAndOffset,boolean forComposite,boolean isWrite,NamedProgramCodeGeneratorAdapter target) throws IllegalActionException {
  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 (      NumberFormatException 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 {
      String returnValue=_generatePortReference(port,channelAndOffset,isWrite);
      return returnValue;
    }
  }
  StringBuffer result=new StringBuffer();
  if (_checkRemote(forComposite,port)) {
    Receiver[][] remoteReceivers;
    if (port.isOutput()) {
      remoteReceivers=port.getRemoteReceivers();
    }
 else {
      remoteReceivers=port.deepGetReceivers();
    }
    if (remoteReceivers.length == 0) {
      String returnValue=generatePortName(port);
      return returnValue;
    }
    ProgramCodeGeneratorAdapter.Channel sourceChannel=new ProgramCodeGeneratorAdapter.Channel(port,channelNumber);
    List<ProgramCodeGeneratorAdapter.Channel> typeConvertSinks=target.getTypeConvertSinkChannels(sourceChannel);
    List<ProgramCodeGeneratorAdapter.Channel> sinkChannels=getSinkChannels(port,channelNumber);
    boolean hasTypeConvertReference=false;
    for (int i=0; i < sinkChannels.size(); i++) {
      ProgramCodeGeneratorAdapter.Channel channel=sinkChannels.get(i);
      TypedIOPort sinkPort=(TypedIOPort)channel.port;
      int sinkChannelNumber=channel.channelNumber;
      if (typeConvertSinks.contains(channel) && getCodeGenerator().isPrimitive(((TypedIOPort)sourceChannel.port).getType())) {
        if (!hasTypeConvertReference) {
          if (i != 0) {
            result.append("String_Node_Str");
          }
          result.append(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" + _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(generatePortName(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 (_checkLocal(forComposite,port)) {
    result.append(generatePortName(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";
}