Program: 74306
Project: 74306
Buggy source:
/** 
 * Schedule the next events by evaluating all scheduling relations from this event. This method uses the argument values passed to this event by the previous invocation to   {@link #fire(ArrayToken)}. If   {@link #fire(ArrayToken)} has never been called, it uses a default scope inwhich no argument value has been given. <p> This method searches for all the events that are scheduled or cancelled by this event. For each scheduling relation from this event, the guard is tested. If it is true, the ending event (which could be the same as this event) is scheduled to occur after the specified amount of delay. Arguments to that event, if any, are also computed at this time. For each cancelling edge from this event, the ending event is cancelled in the containing ERG controller's event queue, if it is in it. <p> All the scheduling relations from this events are tested with their guards. If a scheduling relation's guard returns true, then the event that it points to is scheduled to occur after the amount of model time specified by the scheduling relation's delay parameter.
 * @exception IllegalActionException If the scheduling relations cannot beevaluated.
 */
public void scheduleEvents() throws IllegalActionException {
  ERGController controller=(ERGController)getContainer();
  ERGDirector director=controller.director;
  List<SchedulingRelation> schedules=new LinkedList<SchedulingRelation>(preemptiveTransitionList());
  schedules.addAll(nonpreemptiveTransitionList());
  boolean lifo=((BooleanToken)getController().LIFO.getToken()).booleanValue();
  List<SchedulingRelation> sortedSchedules=new LinkedList<SchedulingRelation>();
  for (  SchedulingRelation relation : schedules) {
    int priority1=((IntToken)relation.priority.getToken()).intValue();
    ListIterator<SchedulingRelation> iterator=sortedSchedules.listIterator();
    while (true) {
      if (iterator.hasNext()) {
        SchedulingRelation next=iterator.next();
        int priority2=((IntToken)next.priority.getToken()).intValue();
        if (!lifo && priority1 > priority2 || lifo && priority1 >= priority2) {
          iterator.previous();
          iterator.add(relation);
          break;
        }
      }
 else {
        iterator.add(relation);
        break;
      }
    }
  }
  ParserScope scope=_getParserScope();
  for (  SchedulingRelation schedule : sortedSchedules) {
    if (schedule.isEnabled(scope)) {
      double delay=schedule.getDelay(scope);
      Event nextEvent=(Event)schedule.destinationState();
      if (schedule.isCanceling()) {
        director.cancel(nextEvent);
      }
 else {
        ArrayToken edgeArguments=schedule.getArguments(scope);
        director.fireAt(nextEvent,director.getModelTime().add(delay),edgeArguments,schedule.getTriggers());
      }
    }
  }
}

Fixed version (ground truth):
/** 
 * Schedule the next events by evaluating all scheduling relations from this event. This method uses the argument values passed to this event by the previous invocation to   {@link #fire(ArrayToken)}. If   {@link #fire(ArrayToken)} has never been called, it uses a default scope inwhich no argument value has been given. <p> This method searches for all the events that are scheduled or cancelled by this event. For each scheduling relation from this event, the guard is tested. If it is true, the ending event (which could be the same as this event) is scheduled to occur after the specified amount of delay. Arguments to that event, if any, are also computed at this time. For each cancelling edge from this event, the ending event is cancelled in the containing ERG controller's event queue, if it is in it. <p> All the scheduling relations from this events are tested with their guards. If a scheduling relation's guard returns true, then the event that it points to is scheduled to occur after the amount of model time specified by the scheduling relation's delay parameter.
 * @exception IllegalActionException If the scheduling relations cannot beevaluated.
 */
public void scheduleEvents() throws IllegalActionException {
  ERGController controller=(ERGController)getContainer();
  ERGDirector director=controller.director;
  List<SchedulingRelation> schedules=new LinkedList<SchedulingRelation>(preemptiveTransitionList());
  schedules.addAll(nonpreemptiveTransitionList());
  List<SchedulingRelation> sortedSchedules=new LinkedList<SchedulingRelation>();
  for (  SchedulingRelation relation : schedules) {
    int priority1=((IntToken)relation.priority.getToken()).intValue();
    ListIterator<SchedulingRelation> iterator=sortedSchedules.listIterator();
    while (true) {
      if (iterator.hasNext()) {
        SchedulingRelation next=iterator.next();
        int priority2=((IntToken)next.priority.getToken()).intValue();
        if (priority1 > priority2) {
          iterator.previous();
          iterator.add(relation);
          break;
        }
      }
 else {
        iterator.add(relation);
        break;
      }
    }
  }
  ParserScope scope=_getParserScope();
  for (  SchedulingRelation schedule : sortedSchedules) {
    if (schedule.isEnabled(scope)) {
      double delay=schedule.getDelay(scope);
      Event nextEvent=(Event)schedule.destinationState();
      if (schedule.isCanceling()) {
        director.cancel(nextEvent);
      }
 else {
        ArrayToken edgeArguments=schedule.getArguments(scope);
        director.fireAt(nextEvent,director.getModelTime().add(delay),edgeArguments,schedule.getTriggers());
      }
    }
  }
}