Program: 74584
Project: 74584
Buggy source:
public void attributeChanged(Attribute attribute) throws IllegalActionException {
  super.attributeChanged(attribute);
  if (attribute == ruleListAttribute) {
    try {
      _workspace.getWriteAccess();
      Set<String> preservedPortNames=new HashSet<String>();
      boolean isIconSet=false;
      int i=1;
      RuleList ruleList=ruleListAttribute.getRuleList();
      for (      Rule rule : ruleList) {
        if (rule instanceof PortRule) {
          PortRule portRule=(PortRule)rule;
          String portID=portRule.getPortID(ruleList);
          preservedPortNames.add(portID);
          TypedIOPort port=(TypedIOPort)getPort(portID);
          if (port != null) {
            port.setInput(portRule.isInput());
            port.setOutput(portRule.isOutput());
            port.setMultiport(portRule.isMultiport());
            port.setPersistent(false);
          }
 else {
            port=new TypedIOPort(this,portID,portRule.isInput(),portRule.isOutput());
            port.setMultiport(portRule.isMultiport());
            port.setPersistent(false);
          }
          port.setPersistent(false);
        }
 else         if (rule instanceof SubclassRule && !isIconSet) {
          SubclassRule subclassRule=(SubclassRule)rule;
          String superclass=subclassRule.getSuperclass();
          isIconSet=_loadActorIcon(superclass);
        }
        i++;
      }
      if (!isIconSet) {
      }
      List<?> portList=portList();
      for (i=0; i < portList.size(); ) {
        Port port=(Port)portList.get(i);
        if (!preservedPortNames.contains(port.getName())) {
          port.setContainer(null);
        }
 else {
          i++;
        }
      }
      for (      Object portObject : portList()) {
        Port port=(Port)portObject;
        if (!preservedPortNames.contains(port.getName())) {
          port.setContainer(null);
        }
      }
    }
 catch (    MalformedStringException e) {
      throw new IllegalActionException(null,e,"String_Node_Str");
    }
catch (    NameDuplicationException e) {
      throw new IllegalActionException(null,e,"String_Node_Str");
    }
 finally {
      _workspace.doneWriting();
    }
  }
}

Fixed version (ground truth):
public void attributeChanged(Attribute attribute) throws IllegalActionException {
  super.attributeChanged(attribute);
  if (attribute == ruleListAttribute) {
    try {
      _workspace.getWriteAccess();
      Set<String> preservedPortNames=new HashSet<String>();
      boolean isIconSet=false;
      int i=1;
      RuleList ruleList=ruleListAttribute.getRuleList();
      for (      Rule rule : ruleList) {
        if (rule instanceof PortRule) {
          PortRule portRule=(PortRule)rule;
          String portID=portRule.getPortID(ruleList);
          preservedPortNames.add(portID);
          TypedIOPort port=(TypedIOPort)getPort(portID);
          if (port != null) {
            port.setInput(portRule.isInput());
            port.setOutput(portRule.isOutput());
            port.setMultiport(portRule.isMultiport());
            port.setPersistent(false);
          }
 else {
            port=new TypedIOPort(this,portID,portRule.isInput(),portRule.isOutput());
            port.setMultiport(portRule.isMultiport());
            port.setPersistent(false);
          }
          port.setPersistent(false);
        }
 else         if (rule instanceof SubclassRule && !isIconSet) {
          SubclassRule subclassRule=(SubclassRule)rule;
          final String superclass=subclassRule.getSuperclass();
          requestChange(new ChangeRequest(this,"String_Node_Str"){
            protected void _execute(){
              _loadActorIcon(superclass);
            }
          }
);
          isIconSet=true;
        }
        i++;
      }
      if (!isIconSet) {
        requestChange(new RestoreAppearanceChangeRequest());
      }
      List<?> portList=portList();
      for (i=0; i < portList.size(); ) {
        Port port=(Port)portList.get(i);
        if (!preservedPortNames.contains(port.getName())) {
          port.setContainer(null);
        }
 else {
          i++;
        }
      }
      for (      Object portObject : portList()) {
        Port port=(Port)portObject;
        if (!preservedPortNames.contains(port.getName())) {
          port.setContainer(null);
        }
      }
    }
 catch (    MalformedStringException e) {
      throw new IllegalActionException(null,e,"String_Node_Str");
    }
catch (    NameDuplicationException e) {
      throw new IllegalActionException(null,e,"String_Node_Str");
    }
 finally {
      _workspace.doneWriting();
    }
  }
}