Program: 73626
Project: 73626
Buggy source:
/** 
 * Unlink the subscriberPort with a already registered "published port" coming from a publisher. The pattern is the pattern 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 unlinkToPublishedPort(Pattern pattern,TypedIOPort subscriberPort,boolean global) throws IllegalActionException {
  NamedObj container=getContainer();
  if (!isOpaque() && container instanceof CompositeActor && !((CompositeActor)container).isClassDefinition()) {
    ((CompositeActor)container).unlinkToPublishedPort(pattern,subscriberPort,global);
  }
 else {
    if (_publishedPorts != null) {
      for (      String name : _publishedPorts.keySet()) {
        Matcher matcher=pattern.matcher(name);
        if (matcher.matches()) {
          unlinkToPublishedPort(name,subscriberPort);
        }
      }
    }
    for (    Object relationObj : subscriberPort.linkedRelationList()) {
      try {
        for (        Object port : ((IORelation)relationObj).linkedPortList(subscriberPort)) {
          IOPort subscribedPort=(IOPort)port;
          if (subscribedPort.isInput()) {
            ((CompositeActor)container).unlinkToPublishedPort(pattern,(TypedIOPort)subscribedPort,global);
            subscribedPort.setContainer(null);
          }
        }
        ((IORelation)relationObj).setContainer(null);
      }
 catch (      NameDuplicationException ex) {
        throw new InternalErrorException(subscriberPort.getContainer(),ex,"String_Node_Str");
      }
    }
  }
}

Fixed version (ground truth):
/** 
 * Unlink the subscriberPort with a already registered "published port" coming from a publisher. The pattern is the pattern 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 unlinkToPublishedPort(Pattern pattern,TypedIOPort subscriberPort,boolean global) throws IllegalActionException {
  NamedObj container=getContainer();
  if (!isOpaque() && container instanceof CompositeActor && !((CompositeActor)container).isClassDefinition()) {
    ((CompositeActor)container).unlinkToPublishedPort(pattern,subscriberPort,global);
  }
 else {
    if (_publishedPorts != null) {
      for (      String name : _publishedPorts.keySet()) {
        Matcher matcher=pattern.matcher(name);
        if (matcher.matches()) {
          unlinkToPublishedPort(name,subscriberPort);
        }
      }
    }
    for (    Object relationObj : subscriberPort.linkedRelationList()) {
      try {
        for (        Object port : ((IORelation)relationObj).linkedPortList(subscriberPort)) {
          IOPort subscribedPort=(IOPort)port;
          if (subscribedPort.isInput()) {
            Set connectedInsidePort=new HashSet(subscribedPort.insidePortList());
            connectedInsidePort.remove(subscriberPort);
            if (connectedInsidePort.size() == 0) {
              ((CompositeActor)container).unlinkToPublishedPort(pattern,(TypedIOPort)subscribedPort,global);
              subscribedPort.setContainer(null);
            }
          }
        }
        ((IORelation)relationObj).setContainer(null);
      }
 catch (      NameDuplicationException ex) {
        throw new InternalErrorException(subscriberPort.getContainer(),ex,"String_Node_Str");
      }
    }
  }
}