Program: 73723
Project: 73723
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. 
 * @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) {
      for (      String name : _publishedPorts.keySet()) {
        Matcher matcher=pattern.matcher(name);
        if (matcher.matches()) {
          linkToPublishedPort(name,subscriberPort);
        }
      }
      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);
        }
      }
    }
 else {
      throw new IllegalActionException(this,"String_Node_Str" + "String_Node_Str" + subscriberPort.getContainer().getFullName());
    }
  }
}

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. 
 * @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) {
      for (      String name : _publishedPorts.keySet()) {
        Matcher matcher=pattern.matcher(name);
        if (matcher.matches()) {
          linkToPublishedPort(name,subscriberPort);
        }
      }
    }
    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);
      }
    }
  }
}