Program: 74238
Project: 74238
Buggy source:
/** 
 * Fire an entry in the event queue. If the entry contains information about a scheduled actor, then the prefire(), fire() and postfire() methods of the actor are called. If the entry contains an event, then the event is processed (which means more events may be placed into the event queue, or existing ones may be cancelled). If the event has a refinement, the the refinement is also fired.
 * @param timedEvent The entry in the event queue.
 * @return True if an event is processed or an actor is fired, or false ifthe prefire() method of the actor returns false.
 * @exception IllegalActionException If firing the actor or processing theevent throws it, or if the contents of the given entry cannot be recognized.
 */
private boolean _fire(TimedEvent timedEvent) throws IllegalActionException {
  _eventQueue.remove(timedEvent);
  _refinementQueue.remove(timedEvent);
  ERGController controller=getController();
  Object contents=timedEvent.contents;
  if (contents instanceof Actor) {
    return _fireActor((Actor)contents,timedEvent);
  }
 else   if (contents instanceof Event) {
    Event event=(Event)contents;
    for (    Set<TimedEvent> set : _eventsListeningToPorts.values()) {
      set.remove(timedEvent);
    }
    for (    Set<TimedEvent> set : _eventsListeningToVariables.values()) {
      set.remove(timedEvent);
    }
    controller._setCurrentEvent(event);
    RefiringData data;
    if (timedEvent.data == null) {
      data=event.fire(timedEvent.arguments);
    }
 else {
      data=event.refire(timedEvent.arguments,timedEvent.data);
    }
    if (data != null) {
      _fireAt(event,getModelTime().add(data.getTimeAdvance()),timedEvent.arguments,null,data,timedEvent.priority,false);
    }
    boolean scheduled=false;
    if (timedEvent.data == null) {
      TypedActor[] refinements=event.getRefinement();
      if (refinements != null) {
        for (        TypedActor refinement : refinements) {
          if (!event._isActiveRefinement(refinement)) {
            continue;
          }
          if (timedEvent.reset || !_initializedRefinements.contains(refinement)) {
            refinement.initialize();
            _initializedRefinements.add(refinement);
            for (            TimedEvent refinementEvent : _refinementQueue) {
              if (refinementEvent.contents == refinement && refinementEvent.timeStamp.equals(getModelTime())) {
                _fire(refinementEvent);
                break;
              }
            }
          }
 else {
            _fireActor(refinement,null);
          }
          scheduled=true;
        }
      }
    }
    boolean scheduleNext=!scheduled && data == null;
    if (scheduleNext) {
      if (event.isFinalEvent()) {
        for (        TimedEvent eventToCancel : _eventQueue) {
          eventToCancel.canceled=true;
        }
        _refinementQueue.clear();
      }
 else {
        event.scheduleEvents();
      }
    }
    return true;
  }
 else {
    throw new InternalErrorException(this,null,"String_Node_Str" + "String_Node_Str");
  }
}

Fixed version (ground truth):
/** 
 * Fire an entry in the event queue. If the entry contains information about a scheduled actor, then the prefire(), fire() and postfire() methods of the actor are called. If the entry contains an event, then the event is processed (which means more events may be placed into the event queue, or existing ones may be cancelled). If the event has a refinement, the the refinement is also fired.
 * @param timedEvent The entry in the event queue.
 * @return True if an event is processed or an actor is fired, or false ifthe prefire() method of the actor returns false.
 * @exception IllegalActionException If firing the actor or processing theevent throws it, or if the contents of the given entry cannot be recognized.
 */
private boolean _fire(TimedEvent timedEvent) throws IllegalActionException {
  _eventQueue.remove(timedEvent);
  _refinementQueue.remove(timedEvent);
  ERGController controller=getController();
  Object contents=timedEvent.contents;
  if (contents instanceof Actor) {
    return _fireActor((Actor)contents,timedEvent);
  }
 else   if (contents instanceof Event) {
    Event event=(Event)contents;
    for (    Set<TimedEvent> set : _eventsListeningToPorts.values()) {
      set.remove(timedEvent);
    }
    for (    Set<TimedEvent> set : _eventsListeningToVariables.values()) {
      set.remove(timedEvent);
    }
    controller._setCurrentEvent(event);
    RefiringData data;
    if (timedEvent.data == null) {
      data=event.fire(timedEvent.arguments);
    }
 else {
      data=event.refire(timedEvent.arguments,timedEvent.data);
    }
    if (data != null) {
      _fireAt(event,getModelTime().add(data.getTimeAdvance()),timedEvent.arguments,null,data,timedEvent.priority,false);
    }
    boolean scheduled=false;
    if (timedEvent.data == null) {
      TypedActor[] refinements=event.getRefinement();
      if (refinements != null) {
        for (        TypedActor refinement : refinements) {
          if (!event._isActiveRefinement(refinement)) {
            continue;
          }
          if (timedEvent.reset || !_initializedRefinements.contains(refinement)) {
            refinement.initialize();
            _initializedRefinements.add(refinement);
            TimedEvent eventToFire=null;
            for (            TimedEvent refinementEvent : _refinementQueue) {
              if (refinementEvent.contents == refinement && refinementEvent.timeStamp.equals(getModelTime())) {
                eventToFire=refinementEvent;
                break;
              }
            }
            if (eventToFire == null) {
              _fireActor(refinement,null);
            }
 else {
              _fire(eventToFire);
            }
          }
 else {
            _fireActor(refinement,null);
          }
          scheduled=true;
        }
      }
    }
    boolean scheduleNext=!scheduled && data == null;
    if (scheduleNext) {
      if (event.isFinalEvent()) {
        for (        TimedEvent eventToCancel : _eventQueue) {
          eventToCancel.canceled=true;
        }
        _refinementQueue.clear();
      }
 else {
        event.scheduleEvents();
      }
    }
    return true;
  }
 else {
    throw new InternalErrorException(this,null,"String_Node_Str" + "String_Node_Str");
  }
}