Program: 73415
Project: 73415
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 code needs 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 {
  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 _generatePortReference(port,channelAndOffset,isWrite);
    }
  }
  if (_checkRemote(forComposite,port)) {
    Receiver[][] remoteReceivers;
    if (port.isOutput()) {
      remoteReceivers=port.getRemoteReceivers();
    }
 else {
      remoteReceivers=port.deepGetReceivers();
    }
    if (remoteReceivers.length == 0) {
      result.append(NamedProgramCodeGeneratorAdapter.generateName(target.getComponent()));
      result.append("String_Node_Str");
      result.append(port.getName());
      return result.toString();
    }
    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(NamedProgramCodeGeneratorAdapter.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";
        }
        String res=_ports.generateOffset(sinkPort,channelAndOffset[1],sinkChannelNumber,true);
        if (res.equals("String_Node_Str")) {
          if (sinkPort.getContainer() instanceof CompositeActor) {
            SDFDirector directorAdapter=(SDFDirector)getAdapter(((CompositeActor)sinkPort.getContainer()).getDirector());
            result.append(directorAdapter._ports.generateOffset(sinkPort,channelAndOffset[1],sinkChannelNumber,true));
          }
        }
 else {
          result.append(res);
        }
      }
    }
    return result.toString();
  }
  if (_checkLocal(forComposite,port)) {
    result.append(NamedProgramCodeGeneratorAdapter.generateName(port));
    if (port.isMultiport()) {
      result.append("String_Node_Str" + channelAndOffset[0] + "String_Node_Str");
    }
    if (port.getContainer() instanceof CompositeActor) {
      result.append(_ports.generateOffset(port,channelAndOffset[1],channelNumber,isWrite));
    }
 else {
      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 code needs 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 {
  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 _generatePortReference(port,channelAndOffset,isWrite);
    }
  }
  if (_checkRemote(forComposite,port)) {
    Receiver[][] remoteReceivers;
    if (port.isOutput()) {
      remoteReceivers=port.getRemoteReceivers();
    }
 else {
      remoteReceivers=port.deepGetReceivers();
    }
    if (remoteReceivers.length == 0) {
      result.append(NamedProgramCodeGeneratorAdapter.generateName(target.getComponent()));
      result.append("String_Node_Str");
      result.append(port.getName());
      return result.toString();
    }
    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(NamedProgramCodeGeneratorAdapter.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";
        }
        String res=_ports.generateOffset(sinkPort,channelAndOffset[1],sinkChannelNumber,true);
        if (res.equals("String_Node_Str")) {
          if (sinkPort.getContainer() instanceof CompositeActor) {
            SDFDirector directorAdapter=(SDFDirector)getAdapter(((CompositeActor)sinkPort.getContainer()).getDirector());
            result.append(directorAdapter._ports.generateOffset(sinkPort,channelAndOffset[1],sinkChannelNumber,true));
          }
        }
 else {
          result.append(res);
        }
      }
    }
    return result.toString();
  }
  if (_checkLocal(forComposite,port)) {
    result.append(NamedProgramCodeGeneratorAdapter.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";
}