Program: 73622
Project: 73622
Buggy source:
/** 
 * Link the subscriberPort with a already registered "published port" coming from a publisher. The pattern represents the name being used in the matching process to match publisher and subscriber. A subscriber interested in the output of this publisher uses the  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 pattern The pattern is being used in the matching processto match publisher and subscriber.
 * @param subscriberPort The subscribed port. 
 * @param global Specification of whether the data is subscribedglobally.  If set to true, then subscribers will see values published by publishers anywhere in the model that reference the same channel by name.  If set to false, then only values published by publishers that are fired by the same director are seen by this subscriber.
 * @exception NameDuplicationException If there are name conflictsas a result of the added relations or ports. 
 * @exception IllegalActionException If the published port cannot be found.
 */
public void linkToPublishedPort(Pattern pattern,TypedIOPort subscriberPort,boolean global) throws IllegalActionException, NameDuplicationException {
  NamedObj container=getContainer();
  if (!isOpaque() && container instanceof CompositeActor && !((CompositeActor)container).isClassDefinition()) {
    ((CompositeActor)container).linkToPublishedPort(pattern,subscriberPort,global);
  }
 else {
    if (_publishedPorts == null) {
      if (!global || this == toplevel()) {
        throw new IllegalActionException(subscriberPort.getContainer(),"String_Node_Str" + subscriberPort.getContainer().getFullName());
      }
    }
 else {
      boolean matched=false;
      for (      String name : _publishedPorts.keySet()) {
        Matcher matcher=pattern.matcher(name);
        if (matcher.matches()) {
          matched=true;
          linkToPublishedPort(name,subscriberPort);
        }
      }
      if (!matched && (!global || this == toplevel())) {
        throw new IllegalActionException(subscriberPort.getContainer(),"String_Node_Str" + pattern + "String_Node_Str");
      }
    }
    if (global && this != toplevel()) {
      String portName="String_Node_Str" + StringUtilities.sanitizeName(pattern.toString());
      IOPort port=(IOPort)getPort(portName);
      if (port == null) {
        port=(IOPort)newPort(portName);
        new Parameter(port,"String_Node_Str",BooleanToken.TRUE);
        port.setPersistent(false);
        port.setInput(true);
        port.setMultiport(true);
        port.setDefaultWidth(0);
        IORelation relation=null;
        try {
          relation=(IORelation)newRelation(uniqueName(subscriberPort.getContainer().getName() + "String_Node_Str"));
        }
 catch (        NameDuplicationException e) {
          throw new IllegalStateException(e);
        }
        relation.setPersistent(false);
        new Parameter(relation,"String_Node_Str",BooleanToken.TRUE);
        port.liberalLink(relation);
        if (!subscriberPort.isLinked(relation)) {
          subscriberPort.liberalLink(relation);
          notifyConnectivityChange();
        }
      }
      if (container instanceof CompositeActor) {
        ((CompositeActor)container).linkToPublishedPort(pattern,(TypedIOPort)port,global);
      }
    }
  }
}

Fixed version (ground truth):
/** 
 * Link the subscriberPort with a already registered "published port" coming from a publisher. The pattern represents the name being used in the matching process to match publisher and subscriber. A subscriber interested in the output of this publisher uses the  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 pattern The pattern is being used in the matching processto match publisher and subscriber.
 * @param subscriberPort The subscribed port. 
 * @param global Specification of whether the data is subscribedglobally.  If set to true, then subscribers will see values published by publishers anywhere in the model that reference the same channel by name.  If set to false, then only values published by publishers that are fired by the same director are seen by this subscriber.
 * @exception NameDuplicationException If there are name conflictsas a result of the added relations or ports. 
 * @exception IllegalActionException If the published port cannot be found.
 */
public void linkToPublishedPort(Pattern pattern,TypedIOPort subscriberPort,boolean global) throws IllegalActionException, NameDuplicationException {
  NamedObj container=getContainer();
  if (!isOpaque() && container instanceof CompositeActor && !((CompositeActor)container).isClassDefinition()) {
    ((CompositeActor)container).linkToPublishedPort(pattern,subscriberPort,global);
  }
 else {
    if (_publishedPorts == null) {
      if (!global || this == toplevel()) {
        throw new IllegalActionException(subscriberPort.getContainer(),"String_Node_Str" + subscriberPort.getContainer().getFullName());
      }
    }
 else {
      boolean matched=false;
      for (      String name : _publishedPorts.keySet()) {
        Matcher matcher=pattern.matcher(name);
        if (matcher.matches()) {
          matched=true;
          linkToPublishedPort(name,subscriberPort);
        }
      }
      if (!matched && (!global || this == toplevel())) {
        throw new IllegalActionException(subscriberPort.getContainer(),"String_Node_Str" + pattern + "String_Node_Str");
      }
    }
    if (global && this != toplevel()) {
      String portName="String_Node_Str" + StringUtilities.sanitizeName(pattern.toString());
      IOPort port=(IOPort)getPort(portName);
      if (port == null) {
        port=(IOPort)newPort(portName);
        new Parameter(port,"String_Node_Str",BooleanToken.TRUE);
        port.setPersistent(false);
        port.setInput(true);
        port.setMultiport(true);
        port.setDefaultWidth(0);
      }
      if (!subscriberPort.connectedPortList().contains(port)) {
        IORelation relation=null;
        try {
          relation=(IORelation)newRelation(uniqueName(subscriberPort.getContainer().getName() + "String_Node_Str"));
        }
 catch (        NameDuplicationException e) {
          throw new IllegalStateException(e);
        }
        relation.setPersistent(false);
        new Parameter(relation,"String_Node_Str",BooleanToken.TRUE);
        port.liberalLink(relation);
        if (!subscriberPort.isLinked(relation)) {
          subscriberPort.liberalLink(relation);
          notifyConnectivityChange();
        }
      }
      if (container instanceof CompositeActor) {
        ((CompositeActor)container).linkToPublishedPort(pattern,(TypedIOPort)port,global);
      }
    }
  }
}