Program: 73818
Project: 73818
Buggy source:
/** 
 * Register a "published port" coming from a publisher. The name is the name being used in the matching process to match publisher and subscriber. A subscriber interested in the output of this publisher uses the same name. This registration process of publisher typically happens before the model is preinitialized, for example when opening the model. The subscribers will look for publishers during the preinitialization phase.
 * @param name The name is being used in the matching processto match publisher and subscriber.
 * @param port The published port. 
 * @exception NameDuplicationException If the published portis already registered.
 * @exception IllegalActionException If the published port can'tbe added.
 */
public void registerPublisherPort(String name,IOPort port) throws NameDuplicationException, IllegalActionException {
  NamedObj container=getContainer();
  if (!isOpaque() && container instanceof CompositeActor && !((CompositeActor)container).isClassDefinition()) {
    ((CompositeActor)container).registerPublisherPort(name,port);
  }
 else {
    if (_publishedPorts == null) {
      _publishedPorts=new HashMap<String,List<IOPort>>();
    }
    List<IOPort> portList=_publishedPorts.get(name);
    if (portList == null) {
      portList=new LinkedList<IOPort>();
      _publishedPorts.put(name,portList);
    }
    portList.add(port);
    boolean exportPorts=false;
    if (exportPorts) {
      String portName="String_Node_Str" + name;
      IOPort publisherPort=(IOPort)getPort(portName);
      if (publisherPort == null) {
        publisherPort=(IOPort)newPort(portName);
      }
      publisherPort.setPersistent(false);
      publisherPort.setOutput(true);
      linkToPublishedPort(name,publisherPort);
      if (container instanceof CompositeActor) {
        ((CompositeActor)container).registerPublisherPort(name,publisherPort);
      }
    }
  }
}

Fixed version (ground truth):
/** 
 * Register a "published port" coming from a publisher. The name is the name being used in the matching process to match publisher and subscriber. A subscriber interested in the output of this publisher uses the same name. This registration process of publisher typically happens before the model is preinitialized, for example when opening the model. The subscribers will look for publishers during the preinitialization phase.
 * @param name The name is being used in the matching processto match publisher and subscriber.
 * @param port The published port. 
 * @exception NameDuplicationException If the published portis already registered.
 * @exception IllegalActionException If the published port can'tbe added.
 */
public void registerPublisherPort(String name,IOPort port) throws NameDuplicationException, IllegalActionException {
  NamedObj container=getContainer();
  if (!isOpaque() && container instanceof CompositeActor && !((CompositeActor)container).isClassDefinition()) {
    ((CompositeActor)container).registerPublisherPort(name,port);
  }
 else {
    if (_publishedPorts == null) {
      _publishedPorts=new HashMap<String,List<IOPort>>();
    }
    List<IOPort> portList=_publishedPorts.get(name);
    if (portList == null) {
      portList=new LinkedList<IOPort>();
      _publishedPorts.put(name,portList);
    }
    portList.add(port);
    boolean exportPorts=false;
    if (exportPorts) {
      String portName="String_Node_Str" + StringUtilities.sanitizeName(name);
      IOPort publisherPort=(IOPort)getPort(portName);
      if (publisherPort == null) {
        publisherPort=(IOPort)newPort(portName);
      }
      publisherPort.setPersistent(false);
      publisherPort.setOutput(true);
      publisherPort.setMultiport(true);
      linkToPublishedPort(name,publisherPort);
      if (container instanceof CompositeActor) {
        ((CompositeActor)container).registerPublisherPort(name,publisherPort);
      }
    }
  }
}