Program: 75324
Project: 75324
Buggy source:
/** 
 * apply any changes that may have been made in the table.
 */
protected void _apply(){
  Iterator portIterator;
  TypedIOPort actualPort;
  String portNameInTable[]=new String[_portTableModel.getRowCount()];
  for (int i=0; i < _portTableModel.getRowCount(); i++) {
    portNameInTable[i]=(String)(_portTableModel.getValueAt(i,PortTableModel.COL_NAME));
  }
  for (int i=0; i < _portTableModel.getRowCount(); i++) {
    if (portNameInTable[i].equals("String_Node_Str")) {
      JOptionPane.showMessageDialog(this,"String_Node_Str");
      return;
    }
  }
  for (int i=0; i < _portTableModel.getRowCount(); i++) {
    for (int j=i + 1; j < _portTableModel.getRowCount(); j++) {
      if (portNameInTable[i].equals(portNameInTable[j])) {
        JOptionPane.showMessageDialog(this,portNameInTable[i] + "String_Node_Str" + "String_Node_Str");
        return;
      }
    }
  }
  Vector portsToBeRemoved=new Vector();
  portIterator=getTarget().portList().iterator();
  actualPort=null;
  while (portIterator.hasNext()) {
    Object candidate=portIterator.next();
    if (candidate instanceof TypedIOPort) {
      boolean foundPort=false;
      actualPort=((TypedIOPort)candidate);
      for (int i=0; i < _ports.size(); i++) {
        Object portInfo[]=(Object[])(_ports.elementAt(i));
        if (actualPort == ((TypedIOPort)portInfo[PortTableModel.COL_ACTUAL_PORT])) {
          foundPort=true;
          break;
        }
      }
      if (!foundPort) {
        portsToBeRemoved.add(actualPort);
      }
    }
  }
  Iterator actualPorts=portsToBeRemoved.iterator();
  while (actualPorts.hasNext()) {
    StringBuffer moml=new StringBuffer();
    actualPort=(TypedIOPort)(actualPorts.next());
    NamedObj container=(NamedObj)actualPort.getContainer();
    NamedObj composite=(NamedObj)container.getContainer();
    if (composite != null) {
      moml.append("String_Node_Str" + actualPort.getName() + "String_Node_Str"+ container.getName()+ "String_Node_Str");
    }
 else {
      moml.append("String_Node_Str" + actualPort.getName(container) + "String_Node_Str");
    }
    MoMLChangeRequest request=null;
    if (composite != null) {
      request=new MoMLChangeRequest(this,composite,moml.toString());
    }
 else {
      request=new MoMLChangeRequest(this,container,moml.toString());
    }
    request.setUndoable(true);
    container.addChangeListener(this);
    if (_debug)     System.out.println("String_Node_Str" + container.toString() + "String_Node_Str"+ moml);
    container.requestChange(request);
  }
  StringBuffer moml=new StringBuffer("String_Node_Str");
  boolean haveSomeUpdate=false;
  for (int i=0; i < _ports.size(); i++) {
    Object portInfo[]=(Object[])(_ports.elementAt(i));
    portIterator=getTarget().portList().iterator();
    actualPort=(TypedIOPort)(portInfo[PortTableModel.COL_ACTUAL_PORT]);
    boolean updates[]=new boolean[_portTableModel.getColumnCount()];
    if (actualPort != null) {
      for (int updateNum=0; updateNum < 7; updateNum++) {
        updates[updateNum]=false;
      }
      boolean havePortUpdate=false;
      if (!(actualPort.getName().equals((String)(portInfo[PortTableModel.COL_NAME])))) {
        havePortUpdate=true;
        updates[PortTableModel.COL_NAME]=true;
      }
      if (actualPort.isInput() != (((Boolean)(portInfo[PortTableModel.COL_INPUT])).booleanValue())) {
        havePortUpdate=true;
        updates[PortTableModel.COL_INPUT]=true;
      }
      if (actualPort.isOutput() != (((Boolean)(portInfo[PortTableModel.COL_OUTPUT])).booleanValue())) {
        havePortUpdate=true;
        updates[PortTableModel.COL_OUTPUT]=true;
      }
      if (actualPort.isMultiport() != (((Boolean)(portInfo[PortTableModel.COL_MULTIPORT])).booleanValue())) {
        havePortUpdate=true;
        updates[PortTableModel.COL_MULTIPORT]=true;
      }
      Attribute _show=(Attribute)(actualPort.getAttribute("String_Node_Str"));
      if ((_show == null) == (((Boolean)(portInfo[PortTableModel.COL_SHOW_NAME])).booleanValue())) {
        havePortUpdate=true;
        updates[PortTableModel.COL_SHOW_NAME]=true;
      }
      Attribute hide=actualPort.getAttribute("String_Node_Str");
      if ((hide == null) == (((Boolean)(portInfo[PortTableModel.COL_HIDE])).booleanValue())) {
        havePortUpdate=true;
        updates[PortTableModel.COL_HIDE]=true;
      }
      String _type=null;
      UnitAttribute _typeAttribute=(UnitAttribute)actualPort.getAttribute("String_Node_Str");
      if (_typeAttribute != null) {
        _type=_typeAttribute.getExpression();
      }
      if ((_type == null && (!((String)(portInfo[PortTableModel.COL_TYPE])).equals("String_Node_Str"))) || ((_type != null) && (!((String)(portInfo[PortTableModel.COL_TYPE])).equals(_type)))) {
        havePortUpdate=true;
        updates[PortTableModel.COL_TYPE]=true;
      }
      String _direction=null;
      String direction=(String)(portInfo[PortTableModel.COL_DIRECTION]);
      StringAttribute _cardinal=(StringAttribute)(actualPort.getAttribute("String_Node_Str"));
      if (_cardinal != null)       _direction=_cardinal.getExpression().toUpperCase();
      if (((_direction == null) && !direction.equals("String_Node_Str")) || ((_direction != null) && (!direction.equals(_direction)))) {
        havePortUpdate=true;
        updates[PortTableModel.COL_DIRECTION]=true;
      }
      String _units=null;
      UnitAttribute _unitsAttribute=(UnitAttribute)actualPort.getAttribute("String_Node_Str");
      if (_unitsAttribute != null) {
        _units=_unitsAttribute.getExpression();
      }
      if ((_units == null && (!((String)(portInfo[PortTableModel.COL_UNITS])).equals("String_Node_Str"))) || ((_units != null) && (!((String)(portInfo[PortTableModel.COL_UNITS])).equals(_units)))) {
        havePortUpdate=true;
        updates[PortTableModel.COL_UNITS]=true;
      }
      if (havePortUpdate) {
        NamedObj parent=(NamedObj)actualPort.getContainer();
        moml.append(_createMoMLUpdate(updates,portInfo,(String)(((TypedIOPort)(portInfo[PortTableModel.COL_ACTUAL_PORT])).getName()),(String)(portInfo[PortTableModel.COL_NAME])));
        haveSomeUpdate=true;
      }
    }
 else {
      for (int updateNum=0; updateNum < 7; updateNum++) {
        updates[updateNum]=true;
      }
      updates[PortTableModel.COL_NAME]=false;
      updates[PortTableModel.COL_SHOW_NAME]=((Boolean)(portInfo[PortTableModel.COL_SHOW_NAME])).booleanValue();
      updates[PortTableModel.COL_HIDE]=((Boolean)(portInfo[PortTableModel.COL_HIDE])).booleanValue();
      String _type=(String)(portInfo[PortTableModel.COL_TYPE]);
      if (!_type.equals("String_Node_Str")) {
        updates[PortTableModel.COL_TYPE]=true;
        _portTableModel.fireTableDataChanged();
      }
 else {
        updates[PortTableModel.COL_TYPE]=false;
      }
      String direction=(String)(portInfo[PortTableModel.COL_DIRECTION]);
      if (!direction.equals("String_Node_Str")) {
        updates[PortTableModel.COL_DIRECTION]=true;
        _portTableModel.fireTableDataChanged();
      }
 else {
        updates[PortTableModel.COL_DIRECTION]=false;
      }
      moml.append(_createMoMLUpdate(updates,portInfo,(String)(portInfo[PortTableModel.COL_NAME]),null));
      haveSomeUpdate=true;
    }
  }
  if (haveSomeUpdate) {
    moml.append("String_Node_Str");
    if (_debug)     System.out.println("String_Node_Str" + getTarget().toString() + "String_Node_Str"+ moml);
    MoMLChangeRequest request=new MoMLChangeRequest(this,getTarget(),moml.toString(),null);
    request.setUndoable(true);
    getTarget().requestChange(request);
    _populateActualPorts();
  }
  _setDirty(false);
  _enableApplyButton(false);
}

Fixed version (ground truth):
/** 
 * apply any changes that may have been made in the table.
 */
protected void _apply(){
  Iterator portIterator;
  TypedIOPort actualPort;
  String portNameInTable[]=new String[_portTableModel.getRowCount()];
  for (int i=0; i < _portTableModel.getRowCount(); i++) {
    portNameInTable[i]=(String)(_portTableModel.getValueAt(i,PortTableModel.COL_NAME));
  }
  for (int i=0; i < _portTableModel.getRowCount(); i++) {
    if (portNameInTable[i].equals("String_Node_Str")) {
      JOptionPane.showMessageDialog(this,"String_Node_Str");
      return;
    }
  }
  for (int i=0; i < _portTableModel.getRowCount(); i++) {
    for (int j=i + 1; j < _portTableModel.getRowCount(); j++) {
      if (portNameInTable[i].equals(portNameInTable[j])) {
        JOptionPane.showMessageDialog(this,portNameInTable[i] + "String_Node_Str" + "String_Node_Str");
        return;
      }
    }
  }
  Vector portsToBeRemoved=new Vector();
  portIterator=getTarget().portList().iterator();
  actualPort=null;
  while (portIterator.hasNext()) {
    Object candidate=portIterator.next();
    if (candidate instanceof TypedIOPort) {
      boolean foundPort=false;
      actualPort=((TypedIOPort)candidate);
      for (int i=0; i < _ports.size(); i++) {
        Object portInfo[]=(Object[])(_ports.elementAt(i));
        if (actualPort == ((TypedIOPort)portInfo[PortTableModel.COL_ACTUAL_PORT])) {
          foundPort=true;
          break;
        }
      }
      if (!foundPort) {
        portsToBeRemoved.add(actualPort);
      }
    }
  }
  Iterator actualPorts=portsToBeRemoved.iterator();
  while (actualPorts.hasNext()) {
    StringBuffer moml=new StringBuffer();
    actualPort=(TypedIOPort)(actualPorts.next());
    NamedObj container=(NamedObj)actualPort.getContainer();
    NamedObj composite=(NamedObj)container.getContainer();
    if (composite != null) {
      moml.append("String_Node_Str" + actualPort.getName() + "String_Node_Str"+ container.getName()+ "String_Node_Str");
    }
 else {
      moml.append("String_Node_Str" + actualPort.getName(container) + "String_Node_Str");
    }
    MoMLChangeRequest request=null;
    if (composite != null) {
      request=new MoMLChangeRequest(this,composite,moml.toString());
    }
 else {
      request=new MoMLChangeRequest(this,container,moml.toString());
    }
    request.setUndoable(true);
    container.addChangeListener(this);
    if (_debug)     System.out.println("String_Node_Str" + container.toString() + "String_Node_Str"+ moml);
    container.requestChange(request);
  }
  StringBuffer moml=new StringBuffer("String_Node_Str");
  boolean haveSomeUpdate=false;
  for (int i=0; i < _ports.size(); i++) {
    Object portInfo[]=(Object[])(_ports.elementAt(i));
    portIterator=getTarget().portList().iterator();
    actualPort=(TypedIOPort)(portInfo[PortTableModel.COL_ACTUAL_PORT]);
    boolean updates[]=new boolean[_portTableModel.getColumnCount()];
    if (actualPort != null) {
      for (int updateNum=0; updateNum < 7; updateNum++) {
        updates[updateNum]=false;
      }
      boolean havePortUpdate=false;
      if (!(actualPort.getName().equals((String)(portInfo[PortTableModel.COL_NAME])))) {
        havePortUpdate=true;
        updates[PortTableModel.COL_NAME]=true;
      }
      if (actualPort.isInput() != (((Boolean)(portInfo[PortTableModel.COL_INPUT])).booleanValue())) {
        havePortUpdate=true;
        updates[PortTableModel.COL_INPUT]=true;
      }
      if (actualPort.isOutput() != (((Boolean)(portInfo[PortTableModel.COL_OUTPUT])).booleanValue())) {
        havePortUpdate=true;
        updates[PortTableModel.COL_OUTPUT]=true;
      }
      if (actualPort.isMultiport() != (((Boolean)(portInfo[PortTableModel.COL_MULTIPORT])).booleanValue())) {
        havePortUpdate=true;
        updates[PortTableModel.COL_MULTIPORT]=true;
      }
      Attribute _show=(Attribute)(actualPort.getAttribute("String_Node_Str"));
      if ((_show == null) == (((Boolean)(portInfo[PortTableModel.COL_SHOW_NAME])).booleanValue())) {
        havePortUpdate=true;
        updates[PortTableModel.COL_SHOW_NAME]=true;
      }
      Attribute hide=actualPort.getAttribute("String_Node_Str");
      if ((hide == null) == (((Boolean)(portInfo[PortTableModel.COL_HIDE])).booleanValue())) {
        havePortUpdate=true;
        updates[PortTableModel.COL_HIDE]=true;
      }
      String _type=null;
      TypeAttribute _typeAttribute=(TypeAttribute)actualPort.getAttribute("String_Node_Str");
      if (_typeAttribute != null) {
        _type=_typeAttribute.getExpression();
      }
      if ((_type == null && (!((String)(portInfo[PortTableModel.COL_TYPE])).equals("String_Node_Str"))) || ((_type != null) && (!((String)(portInfo[PortTableModel.COL_TYPE])).equals(_type)))) {
        havePortUpdate=true;
        updates[PortTableModel.COL_TYPE]=true;
      }
      String _direction=null;
      String direction=(String)(portInfo[PortTableModel.COL_DIRECTION]);
      StringAttribute _cardinal=(StringAttribute)(actualPort.getAttribute("String_Node_Str"));
      if (_cardinal != null)       _direction=_cardinal.getExpression().toUpperCase();
      if (((_direction == null) && !direction.equals("String_Node_Str")) || ((_direction != null) && (!direction.equals(_direction)))) {
        havePortUpdate=true;
        updates[PortTableModel.COL_DIRECTION]=true;
      }
      String _units=null;
      UnitAttribute _unitsAttribute=(UnitAttribute)actualPort.getAttribute("String_Node_Str");
      if (_unitsAttribute != null) {
        _units=_unitsAttribute.getExpression();
      }
      if ((_units == null && (!((String)(portInfo[PortTableModel.COL_UNITS])).equals("String_Node_Str"))) || ((_units != null) && (!((String)(portInfo[PortTableModel.COL_UNITS])).equals(_units)))) {
        havePortUpdate=true;
        updates[PortTableModel.COL_UNITS]=true;
      }
      if (havePortUpdate) {
        NamedObj parent=(NamedObj)actualPort.getContainer();
        moml.append(_createMoMLUpdate(updates,portInfo,(String)(((TypedIOPort)(portInfo[PortTableModel.COL_ACTUAL_PORT])).getName()),(String)(portInfo[PortTableModel.COL_NAME])));
        haveSomeUpdate=true;
      }
    }
 else {
      for (int updateNum=0; updateNum < 7; updateNum++) {
        updates[updateNum]=true;
      }
      updates[PortTableModel.COL_NAME]=false;
      updates[PortTableModel.COL_SHOW_NAME]=((Boolean)(portInfo[PortTableModel.COL_SHOW_NAME])).booleanValue();
      updates[PortTableModel.COL_HIDE]=((Boolean)(portInfo[PortTableModel.COL_HIDE])).booleanValue();
      String _type=(String)(portInfo[PortTableModel.COL_TYPE]);
      if (!_type.equals("String_Node_Str")) {
        updates[PortTableModel.COL_TYPE]=true;
        _portTableModel.fireTableDataChanged();
      }
 else {
        updates[PortTableModel.COL_TYPE]=false;
      }
      String direction=(String)(portInfo[PortTableModel.COL_DIRECTION]);
      if (!direction.equals("String_Node_Str")) {
        updates[PortTableModel.COL_DIRECTION]=true;
        _portTableModel.fireTableDataChanged();
      }
 else {
        updates[PortTableModel.COL_DIRECTION]=false;
      }
      moml.append(_createMoMLUpdate(updates,portInfo,(String)(portInfo[PortTableModel.COL_NAME]),null));
      haveSomeUpdate=true;
    }
  }
  if (haveSomeUpdate) {
    moml.append("String_Node_Str");
    if (_debug)     System.out.println("String_Node_Str" + getTarget().toString() + "String_Node_Str"+ moml);
    MoMLChangeRequest request=new MoMLChangeRequest(this,getTarget(),moml.toString(),null);
    request.setUndoable(true);
    getTarget().requestChange(request);
    _populateActualPorts();
  }
  _setDirty(false);
  _enableApplyButton(false);
}