Program: 74447
Project: 74447
Buggy source:
/** 
 * Dequeue the events that have the smallest tag from the event queue. Return their destination actor. Advance the model tag to their tag. If the timestamp of the smallest tag is greater than the stop time then return null. If there are no events in the event queue, and the stopWhenQueueIsEmpty parameter is set to true, then return null. Both cases will have the effect of stopping the simulation. <p> If the stopWhenQueueIsEmpty parameter is false and the queue is empty, then stall the current thread by calling wait() on the _eventQueue until there are new events available.  If the synchronizeToRealTime parameter is true, then this method may suspend the calling thread by using Object.wait(long) to let elapsed real time catch up with the current model time.</p>
 * @return The next actor to be fired, which can be null.
 * @exception IllegalActionException If event queue is not ready, oran event is missed, or time is set backwards.
 */
private Actor _getNextActorToFire() throws IllegalActionException {
  if (_eventQueue == null) {
    throw new IllegalActionException("String_Node_Str");
  }
  Actor actorToFire=null;
  DEEvent lastFoundEvent=null;
  DEEvent nextEvent=null;
  while (!_stopRequested) {
    if (_stopWhenQueueIsEmpty) {
      if (_eventQueue.isEmpty()) {
        break;
      }
    }
    if (!_isTopLevel()) {
      if (_eventQueue.isEmpty()) {
        break;
      }
 else {
        nextEvent=_eventQueue.get();
        if ((nextEvent.timeStamp().compareTo(getModelTime()) < 0)) {
          throw new IllegalActionException("String_Node_Str" + nextEvent.timeStamp() + "String_Node_Str"+ nextEvent.microstep()+ "String_Node_Str"+ getModelTime()+ "String_Node_Str"+ _microstep+ "String_Node_Str");
        }
        if ((nextEvent.timeStamp().compareTo(getModelTime()) > 0)) {
          nextEvent=null;
          break;
        }
      }
    }
 else {
      if (_eventQueue.isEmpty()) {
        if ((actorToFire != null) || (getModelTime().equals(getModelStopTime()))) {
          break;
        }
      }
      while (_eventQueue.isEmpty() && !_stopRequested && !_stopFireRequested) {
        if (_debugging) {
          _debug("String_Node_Str");
        }
        Thread.yield();
synchronized (_eventQueue) {
          if (_eventQueue.isEmpty() && !_stopFireRequested) {
            try {
              workspace().wait(_eventQueue);
            }
 catch (            InterruptedException e) {
              break;
            }
          }
        }
      }
      if (_eventQueue.isEmpty()) {
        break;
      }
 else {
        nextEvent=_eventQueue.get();
      }
    }
    if (nextEvent == null) {
      throw new IllegalActionException("String_Node_Str" + "String_Node_Str");
    }
    if (actorToFire == null) {
      Time currentTime;
      if (_synchronizeToRealTime) {
synchronized (_eventQueue) {
          while (!_stopRequested && !_stopFireRequested) {
            lastFoundEvent=_eventQueue.get();
            currentTime=lastFoundEvent.timeStamp();
            long elapsedTime=System.currentTimeMillis() - _realStartTime;
            double elapsedTimeInSeconds=elapsedTime / 1000.0;
            ptolemy.actor.util.Time elapsed=new ptolemy.actor.util.Time(this,elapsedTimeInSeconds);
            if (currentTime.compareTo(elapsed) <= 0) {
              break;
            }
            long timeToWait=(long)(currentTime.subtract(elapsed).getDoubleValue() * 1000.0);
            if (timeToWait > 0) {
              if (_debugging) {
                _debug("String_Node_Str" + timeToWait);
              }
              try {
                _workspace.wait(_eventQueue,timeToWait);
                if (_stopRequested || _stopFireRequested) {
                  return null;
                }
              }
 catch (              InterruptedException ex) {
              }
            }
          }
        }
      }
synchronized (_eventQueue) {
        lastFoundEvent=_eventQueue.take();
        currentTime=lastFoundEvent.timeStamp();
        actorToFire=lastFoundEvent.actor();
        if ((_disabledActors != null) && _disabledActors.contains(actorToFire)) {
          if (_debugging) {
            _debug("String_Node_Str",((Nameable)actorToFire).getFullName());
          }
          actorToFire=null;
          continue;
        }
        setModelTime(currentTime);
        _microstep=lastFoundEvent.microstep();
      }
      if (currentTime.compareTo(getModelStopTime()) > 0) {
        if (_debugging) {
          _debug("String_Node_Str");
        }
        _exceedStopTime=true;
        return null;
      }
    }
 else {
      if (nextEvent.hasTheSameTagAndDepthAs(lastFoundEvent)) {
        _eventQueue.take();
      }
 else       if (nextEvent.hasTheSameTagAs(lastFoundEvent)) {
        Actor actor=nextEvent.actor();
        if (actor == actorToFire) {
          _eventQueue.take();
        }
 else {
          break;
        }
      }
 else {
        break;
      }
    }
  }
  return actorToFire;
}

Fixed version (ground truth):
/** 
 * Dequeue the events that have the smallest tag from the event queue. Return their destination actor. Advance the model tag to their tag. If the timestamp of the smallest tag is greater than the stop time then return null. If there are no events in the event queue, and the stopWhenQueueIsEmpty parameter is set to true, then return null. Both cases will have the effect of stopping the simulation. <p> If the stopWhenQueueIsEmpty parameter is false and the queue is empty, then stall the current thread by calling wait() on the _eventQueue until there are new events available.  If the synchronizeToRealTime parameter is true, then this method may suspend the calling thread by using Object.wait(long) to let elapsed real time catch up with the current model time.</p>
 * @return The next actor to be fired, which can be null.
 * @exception IllegalActionException If event queue is not ready, oran event is missed, or time is set backwards.
 */
private Actor _getNextActorToFire() throws IllegalActionException {
  if (_eventQueue == null) {
    throw new IllegalActionException("String_Node_Str");
  }
  Actor actorToFire=null;
  DEEvent lastFoundEvent=null;
  DEEvent nextEvent=null;
  while (!_stopRequested) {
    if (_stopWhenQueueIsEmpty) {
      if (_eventQueue.isEmpty()) {
        break;
      }
    }
    if (!_isTopLevel()) {
      if (_eventQueue.isEmpty()) {
        break;
      }
 else {
        nextEvent=_eventQueue.get();
        if ((nextEvent.timeStamp().compareTo(getModelTime()) < 0)) {
          throw new IllegalActionException("String_Node_Str" + nextEvent.timeStamp() + "String_Node_Str"+ nextEvent.microstep()+ "String_Node_Str"+ getModelTime()+ "String_Node_Str"+ _microstep+ "String_Node_Str");
        }
        if ((nextEvent.timeStamp().compareTo(getModelTime()) > 0)) {
          nextEvent=null;
          break;
        }
      }
    }
 else {
      if (_eventQueue.isEmpty()) {
        if ((actorToFire != null) || (getModelTime().equals(getModelStopTime()))) {
          break;
        }
      }
      while (_eventQueue.isEmpty() && !_stopRequested && !_stopFireRequested) {
        if (_debugging) {
          _debug("String_Node_Str");
        }
        Thread.yield();
synchronized (_eventQueue) {
          if (_eventQueue.isEmpty() && !_stopRequested && !_stopFireRequested) {
            try {
              workspace().wait(_eventQueue);
            }
 catch (            InterruptedException e) {
              break;
            }
          }
        }
      }
      if (_eventQueue.isEmpty()) {
        return null;
      }
 else {
        nextEvent=_eventQueue.get();
      }
    }
    if (actorToFire == null) {
      Time currentTime;
      if (_synchronizeToRealTime) {
synchronized (_eventQueue) {
          while (!_stopRequested && !_stopFireRequested) {
            lastFoundEvent=_eventQueue.get();
            currentTime=lastFoundEvent.timeStamp();
            long elapsedTime=System.currentTimeMillis() - _realStartTime;
            double elapsedTimeInSeconds=elapsedTime / 1000.0;
            ptolemy.actor.util.Time elapsed=new ptolemy.actor.util.Time(this,elapsedTimeInSeconds);
            if (currentTime.compareTo(elapsed) <= 0) {
              break;
            }
            long timeToWait=(long)(currentTime.subtract(elapsed).getDoubleValue() * 1000.0);
            if (timeToWait > 0) {
              if (_debugging) {
                _debug("String_Node_Str" + timeToWait);
              }
              try {
                _workspace.wait(_eventQueue,timeToWait);
              }
 catch (              InterruptedException ex) {
                throw new IllegalActionException(this,ex,"String_Node_Str" + "String_Node_Str");
              }
            }
          }
          if (_stopRequested || _stopFireRequested) {
            return null;
          }
        }
      }
synchronized (_eventQueue) {
        lastFoundEvent=_eventQueue.take();
        currentTime=lastFoundEvent.timeStamp();
        actorToFire=lastFoundEvent.actor();
        if ((_disabledActors != null) && _disabledActors.contains(actorToFire)) {
          if (_debugging) {
            _debug("String_Node_Str",((Nameable)actorToFire).getFullName());
          }
          actorToFire=null;
          continue;
        }
        setModelTime(currentTime);
        _microstep=lastFoundEvent.microstep();
      }
      if (currentTime.compareTo(getModelStopTime()) > 0) {
        if (_debugging) {
          _debug("String_Node_Str");
        }
        _exceedStopTime=true;
        return null;
      }
    }
 else {
      if (nextEvent.hasTheSameTagAndDepthAs(lastFoundEvent)) {
        _eventQueue.take();
      }
 else       if (nextEvent.hasTheSameTagAs(lastFoundEvent)) {
        Actor actor=nextEvent.actor();
        if (actor == actorToFire) {
          _eventQueue.take();
        }
 else {
          break;
        }
      }
 else {
        break;
      }
    }
  }
  return actorToFire;
}