Program: 74674
Project: 74674
Buggy source:
/** 
 * Return the reference to the specified parameter or port of the associated actor. For a parameter, the returned string is in the form "fullName_parameterName". For a port, the returned string is in the form "fullName_portName[channelNumber][offset]", if any channel number or offset is given.
 * @param name The name of the parameter or port
 * @param isWrite Whether to generate the write or read offset.
 * @return The reference to that parameter or port (a variable name,for example).
 * @exception IllegalActionException If the parameter or port does notexist or does not have a value.
 */
public String getReference(String name,boolean isWrite) throws IllegalActionException {
  name=processCode(name);
  String castType=null;
  String refType=null;
  StringBuffer result=new StringBuffer();
  StringTokenizer tokenizer=new StringTokenizer(name,"String_Node_Str",true);
  if ((tokenizer.countTokens() != 1) && (tokenizer.countTokens() != 3) && (tokenizer.countTokens() != 5)) {
    throw new IllegalActionException(_component,"String_Node_Str" + name);
  }
  String refName=tokenizer.nextToken().trim();
  StringTokenizer tokenizer2=new StringTokenizer(refName,"String_Node_Str",false);
  if (tokenizer2.countTokens() != 1 && tokenizer2.countTokens() != 2) {
    throw new IllegalActionException(_component,"String_Node_Str" + refName);
  }
  if (tokenizer2.countTokens() == 2) {
    castType=tokenizer2.nextToken().trim();
    refName=tokenizer2.nextToken().trim();
  }
  boolean forComposite=false;
  if (refName.charAt(0) == '@') {
    forComposite=true;
    refName=refName.substring(1);
  }
  TypedIOPort port=getPort(refName);
  String[] channelAndOffset=_getChannelAndOffset(name);
  if (port != null) {
    refType=codeGenType(port.getType());
    int channelNumber=0;
    if (!channelAndOffset[0].equals("String_Node_Str")) {
      channelNumber=(Integer.valueOf(channelAndOffset[0])).intValue();
    }
    if ((port.isOutput() && !forComposite) || (port.isInput() && forComposite)) {
      Receiver[][] remoteReceivers;
      if (port.isOutput()) {
        remoteReceivers=port.getRemoteReceivers();
      }
 else {
        remoteReceivers=port.deepGetReceivers();
      }
      if (remoteReceivers.length == 0) {
        result.append(generateName(_component));
        result.append("String_Node_Str");
        result.append(port.getName());
        return _generateTypeConvertMethod(result.toString(),castType,refType);
      }
      Channel sourceChannel=new Channel(port,channelNumber);
      List typeConvertSinks=_getTypeConvertSinkChannels(sourceChannel);
      List sinkChannels=getSinkChannels(port,channelNumber);
      boolean hasTypeConvertReference=false;
      for (int i=0; i < sinkChannels.size(); i++) {
        Channel channel=(Channel)sinkChannels.get(i);
        IOPort sinkPort=channel.port;
        int sinkChannelNumber=channel.channelNumber;
        if (typeConvertSinks.contains(channel)) {
          if (!hasTypeConvertReference) {
            if (i != 0) {
              result.append("String_Node_Str");
            }
            result.append(_getTypeConvertReference(sourceChannel));
            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(generateName(sinkPort));
          if (sinkPort.isMultiport()) {
            result.append("String_Node_Str" + sinkChannelNumber + "String_Node_Str");
          }
          result.append(generateOffset(channelAndOffset[1],sinkPort,sinkChannelNumber,true));
        }
      }
      return _generateTypeConvertMethod(result.toString(),castType,refType);
    }
    if ((port.isInput() && !forComposite && port.getWidth() > 0) || (port.isOutput() && forComposite)) {
      result.append(generateName(port));
      if (port.isMultiport()) {
        result.append("String_Node_Str" + channelAndOffset[0] + "String_Node_Str");
      }
      result.append(generateOffset(channelAndOffset[1],port,channelNumber,isWrite));
      return _generateTypeConvertMethod(result.toString(),castType,refType);
    }
  }
  Attribute attribute=_component.getAttribute(refName);
  if (attribute != null) {
    if (attribute instanceof Parameter) {
      _referencedParameters.add(attribute);
      refType=codeGenType(((Parameter)attribute).getType());
    }
    result.append(_codeGenerator.generateVariableName(attribute));
    if (!channelAndOffset[0].equals("String_Node_Str")) {
      throw new IllegalActionException(_component,"String_Node_Str");
    }
    if (!channelAndOffset[1].equals("String_Node_Str")) {
      result.insert(0,"String_Node_Str");
      result.append("String_Node_Str" + channelAndOffset[1] + "String_Node_Str");
      Type elementType=((ArrayType)((Parameter)attribute).getType()).getElementType();
      if (isPrimitive(elementType)) {
        result.append("String_Node_Str" + codeGenType(elementType));
      }
    }
    return _generateTypeConvertMethod(result.toString(),castType,refType);
  }
  throw new IllegalActionException(_component,"String_Node_Str" + name);
}

Fixed version (ground truth):
/** 
 * Return the reference to the specified parameter or port of the associated actor. For a parameter, the returned string is in the form "fullName_parameterName". For a port, the returned string is in the form "fullName_portName[channelNumber][offset]", if any channel number or offset is given.
 * @param name The name of the parameter or port
 * @param isWrite Whether to generate the write or read offset.
 * @return The reference to that parameter or port (a variable name,for example).
 * @exception IllegalActionException If the parameter or port does notexist or does not have a value.
 */
public String getReference(String name,boolean isWrite) throws IllegalActionException {
  name=processCode(name);
  String castType=null;
  String refType=null;
  StringBuffer result=new StringBuffer();
  StringTokenizer tokenizer=new StringTokenizer(name,"String_Node_Str",true);
  if ((tokenizer.countTokens() != 1) && (tokenizer.countTokens() != 3) && (tokenizer.countTokens() != 5)) {
    throw new IllegalActionException(_component,"String_Node_Str" + name);
  }
  String refName=tokenizer.nextToken().trim();
  StringTokenizer tokenizer2=new StringTokenizer(refName,"String_Node_Str",false);
  if (tokenizer2.countTokens() != 1 && tokenizer2.countTokens() != 2) {
    throw new IllegalActionException(_component,"String_Node_Str" + refName);
  }
  if (tokenizer2.countTokens() == 2) {
    castType=tokenizer2.nextToken().trim();
    refName=tokenizer2.nextToken().trim();
  }
  boolean forComposite=false;
  if (refName.charAt(0) == '@') {
    forComposite=true;
    refName=refName.substring(1);
  }
  TypedIOPort port=getPort(refName);
  String[] channelAndOffset=_getChannelAndOffset(name);
  if (port != null) {
    refType=codeGenType(port.getType());
    int channelNumber=0;
    if (!channelAndOffset[0].equals("String_Node_Str")) {
      channelNumber=(Integer.valueOf(channelAndOffset[0])).intValue();
    }
    if ((port.isOutput() && !forComposite) || (port.isInput() && forComposite)) {
      Receiver[][] remoteReceivers;
      if (port.isOutput()) {
        remoteReceivers=port.getRemoteReceivers();
      }
 else {
        remoteReceivers=port.deepGetReceivers();
      }
      if (remoteReceivers.length == 0) {
        result.append(generateName(_component));
        result.append("String_Node_Str");
        result.append(port.getName());
        return _generateTypeConvertMethod(result.toString(),castType,refType);
      }
      Channel sourceChannel=new Channel(port,channelNumber);
      List typeConvertSinks=_getTypeConvertSinkChannels(sourceChannel);
      List sinkChannels=getSinkChannels(port,channelNumber);
      boolean hasTypeConvertReference=false;
      for (int i=0; i < sinkChannels.size(); i++) {
        Channel channel=(Channel)sinkChannels.get(i);
        IOPort sinkPort=channel.port;
        int sinkChannelNumber=channel.channelNumber;
        if (typeConvertSinks.contains(channel) && isPrimitive(((TypedIOPort)sourceChannel.port).getType())) {
          if (!hasTypeConvertReference) {
            if (i != 0) {
              result.append("String_Node_Str");
            }
            result.append(_getTypeConvertReference(sourceChannel));
            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(generateName(sinkPort));
          if (sinkPort.isMultiport()) {
            result.append("String_Node_Str" + sinkChannelNumber + "String_Node_Str");
          }
          result.append(generateOffset(channelAndOffset[1],sinkPort,sinkChannelNumber,true));
        }
      }
      return _generateTypeConvertMethod(result.toString(),castType,refType);
    }
    if ((port.isInput() && !forComposite && port.getWidth() > 0) || (port.isOutput() && forComposite)) {
      result.append(generateName(port));
      if (port.isMultiport()) {
        result.append("String_Node_Str" + channelAndOffset[0] + "String_Node_Str");
      }
      result.append(generateOffset(channelAndOffset[1],port,channelNumber,isWrite));
      return _generateTypeConvertMethod(result.toString(),castType,refType);
    }
  }
  Attribute attribute=_component.getAttribute(refName);
  if (attribute != null) {
    if (attribute instanceof Parameter) {
      _referencedParameters.add(attribute);
      refType=codeGenType(((Parameter)attribute).getType());
    }
    result.append(_codeGenerator.generateVariableName(attribute));
    if (!channelAndOffset[0].equals("String_Node_Str")) {
      throw new IllegalActionException(_component,"String_Node_Str");
    }
    if (!channelAndOffset[1].equals("String_Node_Str")) {
      result.insert(0,"String_Node_Str");
      result.append("String_Node_Str" + channelAndOffset[1] + "String_Node_Str");
      Type elementType=((ArrayType)((Parameter)attribute).getType()).getElementType();
      if (isPrimitive(elementType)) {
        result.append("String_Node_Str" + codeGenType(elementType));
      }
    }
    return _generateTypeConvertMethod(result.toString(),castType,refType);
  }
  throw new IllegalActionException(_component,"String_Node_Str" + name);
}