Program: 72825
Project: 72825
Buggy source:
/** 
 * Return the list of communication aspects in this port. A communication aspect is a   {@link Parameter} whose value is an{@link ObjectToken} that references an object that implementsthe  {@link CommunicationAspect} interface.Update the sequence number of communication aspects.
 * @return The list of communication aspects.
 * @exception IllegalActionException Thrown if the token of the parametercontaining the communication aspect object cannot be retrieved.
 */
public List<CommunicationAspect> getCommunicationAspects() throws IllegalActionException {
  if (_communicationAspects == null) {
    _communicationAspects=new ArrayList<CommunicationAspect>();
  }
  HashMap<Integer,CommunicationAspectAttributes> _communicationAspectMap=new HashMap<Integer,CommunicationAspectAttributes>();
  int sequenceNumber=1;
  List<CommunicationAspectAttributes> communicationAspectList=this.attributeList(CommunicationAspectAttributes.class);
  if (communicationAspectList.size() > 0) {
    try {
      _workspace.getWriteAccess();
      List<CommunicationAspectAttributes> enabledAttributes=new ArrayList();
      for (int i=0; i < communicationAspectList.size(); i++) {
        CommunicationAspectAttributes attribute=communicationAspectList.get(i);
        if (((BooleanToken)attribute.enable.getToken()).booleanValue()) {
          enabledAttributes.add(attribute);
          int s=((IntToken)attribute.sequenceNumber.getToken()).intValue();
          if (s > sequenceNumber) {
            sequenceNumber=s;
          }
        }
 else {
          attribute.sequenceNumber.setToken(new IntToken(-1));
        }
      }
      sequenceNumber=sequenceNumber + 1;
      for (int i=0; i < enabledAttributes.size(); i++) {
        final CommunicationAspectAttributes attribute=enabledAttributes.get(i);
        final int seqNum=sequenceNumber;
        CommunicationAspect communicationAspect=(CommunicationAspect)attribute.getDecorator();
        int oldSeqNum=((IntToken)attribute.sequenceNumber.getToken()).intValue();
        if (oldSeqNum == -1 && communicationAspect != null && !_communicationAspects.contains(communicationAspect)) {
          attribute.sequenceNumber.setToken(new IntToken(seqNum));
          _communicationAspectMap.put(seqNum,attribute);
          sequenceNumber=sequenceNumber + 1;
        }
 else {
          _communicationAspectMap.put(oldSeqNum,attribute);
        }
      }
      _communicationAspects.clear();
      Iterator<Integer> iterator=_communicationAspectMap.keySet().iterator();
      int i=1;
      while (iterator.hasNext()) {
        CommunicationAspectAttributes attribute=_communicationAspectMap.get(iterator.next());
        attribute.sequenceNumber.setToken(new IntToken(i));
        i=i + 1;
        _communicationAspects.add((CommunicationAspect)attribute.getDecorator());
      }
    }
 catch (    Exception e) {
      e.printStackTrace();
    }
 finally {
      _workspace.doneWriting();
    }
  }
  _communicationAspectsValid=true;
  return _communicationAspects;
}

Fixed version (ground truth):
/** 
 * Return the list of communication aspects in this port. A communication aspect is a   {@link Parameter} whose value is an{@link ObjectToken} that references an object that implementsthe  {@link CommunicationAspect} interface.Update the sequence number of communication aspects.
 * @return The list of communication aspects.
 * @exception IllegalActionException Thrown if the token of the parametercontaining the communication aspect object cannot be retrieved.
 */
public List<CommunicationAspect> getCommunicationAspects() throws IllegalActionException {
  if (_communicationAspects == null) {
    _communicationAspects=new ArrayList<CommunicationAspect>();
  }
  HashMap<Integer,CommunicationAspectAttributes> _communicationAspectMap=new HashMap<Integer,CommunicationAspectAttributes>();
  int sequenceNumber=1;
  List<CommunicationAspectAttributes> communicationAspectList=this.attributeList(CommunicationAspectAttributes.class);
  if (communicationAspectList.size() > 0) {
    try {
      _workspace.getWriteAccess();
      List<CommunicationAspectAttributes> enabledAttributes=new ArrayList();
      for (int i=0; i < communicationAspectList.size(); i++) {
        CommunicationAspectAttributes attribute=communicationAspectList.get(i);
        if (((BooleanToken)attribute.enable.getToken()).booleanValue()) {
          enabledAttributes.add(attribute);
          int s=((IntToken)attribute.sequenceNumber.getToken()).intValue();
          if (s > sequenceNumber) {
            sequenceNumber=s;
          }
        }
 else {
          attribute.sequenceNumber.setToken(new IntToken(-1));
        }
      }
      sequenceNumber=sequenceNumber + 1;
      for (int i=0; i < enabledAttributes.size(); i++) {
        final CommunicationAspectAttributes attribute=enabledAttributes.get(i);
        final int seqNum=sequenceNumber;
        CommunicationAspect communicationAspect=(CommunicationAspect)attribute.getDecorator();
        int oldSeqNum=((IntToken)attribute.sequenceNumber.getToken()).intValue();
        if (oldSeqNum == -1 && communicationAspect != null && !_communicationAspects.contains(communicationAspect)) {
          attribute.sequenceNumber.setToken(new IntToken(seqNum));
          _communicationAspectMap.put(seqNum,attribute);
          sequenceNumber=sequenceNumber + 1;
        }
 else {
          _communicationAspectMap.put(oldSeqNum,attribute);
        }
      }
      _communicationAspects.clear();
      Iterator<Integer> iterator=_communicationAspectMap.keySet().iterator();
      int i=1;
      while (iterator.hasNext()) {
        CommunicationAspectAttributes attribute=_communicationAspectMap.get(iterator.next());
        attribute.sequenceNumber.setToken(new IntToken(i));
        i=i + 1;
        Decorator decorator=attribute.getDecorator();
        if (decorator != null) {
          _communicationAspects.add((CommunicationAspect)decorator);
        }
      }
    }
 catch (    Exception e) {
      e.printStackTrace();
    }
 finally {
      _workspace.doneWriting();
    }
  }
  _communicationAspectsValid=true;
  return _communicationAspects;
}