Program: 74929
Project: 74929
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. FIXME: need documentation on the input string format.
 * @param name The name of the parameter or port
 * @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) throws IllegalActionException {
  boolean isInputPort=false;
  name=processCode(name);
  String[] nameChannelOffset=parseName(name);
  String portName=nameChannelOffset[0];
  String channel=nameChannelOffset[1];
  TypedIOPort port=getPort(portName);
  CodeGeneratorHelper sourceHelper=this;
  if (port != null && port.isInput()) {
    isInputPort=true;
    TypedIOPort sinkPort=port;
    int sourceChannel=new Integer(channel).intValue();
    port=(TypedIOPort)port.connectedPortList().get(sourceChannel);
    portName=port.getName();
    channel="String_Node_Str" + _getChannelIndex(sinkPort,sourceChannel,port);
    sourceHelper=(CodeGeneratorHelper)_getHelper(port.getContainer());
  }
  String refName=_getReference(name);
  String convertMethod=(String)sourceHelper._portConversions.get(portName + "String_Node_Str" + channel);
  if (convertMethod != null) {
    String type=(String)sourceHelper._portDeclareTypes.get(portName + "String_Node_Str" + channel);
    if (type.equals("String_Node_Str")) {
      String typeName=convertMethod.substring(0,convertMethod.indexOf("String_Node_Str"));
      if (_isPrimitiveType(typeName)) {
        refName+="String_Node_Str" + typeName;
        sourceHelper._newTypesUsed.add(typeName);
      }
    }
 else     if (type.equals("String_Node_Str")) {
      if (!isInputPort) {
        refName=refName.replace('[','_').replace(']','_');
      }
    }
 else {
    }
  }
  return refName;
}

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. FIXME: need documentation on the input string format.
 * @param name The name of the parameter or port
 * @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) throws IllegalActionException {
  boolean isInputPort=false;
  name=processCode(name);
  String[] nameChannelOffset=parseName(name);
  String portName=nameChannelOffset[0];
  String channel=nameChannelOffset[1];
  TypedIOPort port=getPort(portName);
  CodeGeneratorHelper sourceHelper=this;
  if (port != null && port.isInput()) {
    isInputPort=true;
    int channelNumber=new Integer(channel).intValue();
    Receiver receiver=port.getReceivers()[channelNumber][0];
    Iterator sourcePorts=port.sourcePortList().iterator();
    breakOutLabel:     while (sourcePorts.hasNext()) {
      IOPort sourcePort=(IOPort)sourcePorts.next();
      Receiver[][] remoteReceivers=sourcePort.getRemoteReceivers();
      for (int i=0; i < remoteReceivers.length; i++) {
        for (int j=0; j < remoteReceivers[i].length; j++) {
          if (remoteReceivers[i][j] == receiver) {
            portName=sourcePort.getName();
            channel="String_Node_Str" + i;
            sourceHelper=(CodeGeneratorHelper)_getHelper(sourcePort.getContainer());
            break breakOutLabel;
          }
        }
      }
    }
  }
  String refName=_getReference(name);
  String convertMethod=(String)sourceHelper._portConversions.get(portName + "String_Node_Str" + channel);
  if (convertMethod != null) {
    String type=(String)sourceHelper._portDeclareTypes.get(portName + "String_Node_Str" + channel);
    if (type.equals("String_Node_Str")) {
      String typeName=convertMethod.substring(0,convertMethod.indexOf("String_Node_Str"));
      if (_isPrimitiveType(typeName)) {
        refName+="String_Node_Str" + typeName;
        sourceHelper._newTypesUsed.add(typeName);
      }
    }
 else     if (type.equals("String_Node_Str")) {
      if (!isInputPort) {
        refName=refName.replace('[','_').replace(']','_');
      }
    }
 else {
    }
  }
  return refName;
}