Program: 74131
Project: 74131
Buggy source:
/** 
 * Insert initial events into the event queue, and request firing from the director at the higher level, if any.
 * @exception IllegalActionException If whether an event is initial eventcannot be checked, or if the executive director does not support fireAt() precisely (it does not agree to refire this Ptera at the requested time).
 */
protected void _insertInitialEvents() throws IllegalActionException {
  PteraController controller=getController();
  if (_isInController()) {
    PteraModalModel modalModel=(PteraModalModel)getContainer().getContainer();
    _currentTime=modalModel.getDirector().getModelTime();
    Iterator<?> entities=controller.deepEntityList().iterator();
    List<Event> initialEvents=new LinkedList<Event>();
    while (entities.hasNext()) {
      Event event=(Event)entities.next();
      if (event.isInitialEvent()) {
        initialEvents.add(event);
      }
    }
    final boolean lifo=((BooleanToken)LIFO.getToken()).booleanValue();
    Collections.sort(initialEvents,new Comparator<Event>(){
      public int compare(      Event event1,      Event event2){
        int eventCompare=event1.getName().compareTo(event2.getName());
        return lifo ? -eventCompare : eventCompare;
      }
    }
);
    for (    Event event : initialEvents) {
      TimedEvent newEvent=new TimedEvent(event,_currentTime,null,null,false);
      _addEvent(newEvent);
    }
    if (getController().getRefinedState() != null) {
      _requestFiring();
    }
  }
 else {
    TimedEvent newEvent=new TimedEvent(controller,_currentTime,null,null,false);
    _addEvent(newEvent);
    _initializedRefinements.add(controller);
    if (_isEmbedded()) {
      _requestFiring();
    }
  }
  if (_isEmbedded()) {
    _delegateFireAt=true;
  }
}

Fixed version (ground truth):
/** 
 * Insert initial events into the event queue, and request firing from the director at the higher level, if any.
 * @exception IllegalActionException If whether an event is initial eventcannot be checked, or if the executive director does not support fireAt() precisely (it does not agree to refire this Ptera at the requested time).
 */
protected void _insertInitialEvents() throws IllegalActionException {
  PteraController controller=getController();
  if (_isInController()) {
    PteraModalModel modalModel=(PteraModalModel)getContainer().getContainer();
    _currentTime=modalModel.getDirector().getModelTime();
    Iterator<?> entities=controller.deepEntityList().iterator();
    List<Event> initialEvents=new LinkedList<Event>();
    while (entities.hasNext()) {
      Event event=(Event)entities.next();
      if (event.isInitialEvent()) {
        initialEvents.add(event);
      }
    }
    final boolean lifo=((BooleanToken)LIFO.getToken()).booleanValue();
    Collections.sort(initialEvents,new Comparator<Event>(){
      public int compare(      Event event1,      Event event2){
        int eventCompare=event1.getName().compareTo(event2.getName());
        return lifo ? -eventCompare : eventCompare;
      }
    }
);
    for (    Event event : initialEvents) {
      Event refinedEvent=(Event)controller.getRefinedState();
      RecordToken arguments=null;
      if (refinedEvent != null) {
        List<String> names=event.parameters.getParameterNames();
        if (names.size() > 0) {
          String[] tokenNames=new String[names.size()];
          Token[] tokenValues=new Token[names.size()];
          int i=0;
          for (          String name : names) {
            tokenNames[i]=name;
            tokenValues[i]=((Variable)refinedEvent.getAttribute(name)).getToken();
            i++;
          }
          arguments=new RecordToken(tokenNames,tokenValues);
        }
      }
      TimedEvent newEvent=new TimedEvent(event,_currentTime,arguments,null,false);
      _addEvent(newEvent);
    }
    if (getController().getRefinedState() != null) {
      _requestFiring();
    }
  }
 else {
    TimedEvent newEvent=new TimedEvent(controller,_currentTime,null,null,false);
    _addEvent(newEvent);
    _initializedRefinements.add(controller);
    if (_isEmbedded()) {
      _requestFiring();
    }
  }
  if (_isEmbedded()) {
    _delegateFireAt=true;
  }
}