Program: 73480
Project: 73480
Buggy source:
/** 
 * If the event's destination port does not have a delayOffset parameter, or if there doesn't exist a destination port (in case of pure event) then the event is always safe to process. Otherwise: If the current physical time has passed the timestamp of the event minus delayOffset of the port, then the event is safe to process. Otherwise the event is not safe to process, and we calculate the physical time when the event is safe to process and setup a timed interrupt. This method calls _setTimedInterrupt at the oracle time of the corresponding safe-to-process time.
 * @see #_setTimedInterrupt(Time)
 * @see #_getOraclePhysicalTagForPlatformPhysicalTag(Tag)
 * @param event The event checked for safe to process
 * @return True if the event is safe to process, otherwise return false.
 * @exception IllegalActionException If port is null and event is not a pureevent.
 * @see #_setTimedInterrupt(Time)
 */
protected boolean _safeToProcess(PtidesEvent event) throws IllegalActionException {
  IOPort port=event.ioPort();
  if (port == null) {
    assert(event.isPureEvent());
    return true;
  }
  assert(!port.isOutput());
  double delayOffset=_getMininumDelayOffset(port,((PtidesEvent)event).channel(),event.isPureEvent());
  Time waitUntilPhysicalTime=event.timeStamp().subtract(delayOffset);
  Tag platformPhysicalTag=getPlatformPhysicalTag(PLATFORM_TIMER);
  int compare=platformPhysicalTag.timestamp.subtract(waitUntilPhysicalTime).compareTo(_zero);
  int microstep=platformPhysicalTag.microstep;
  if ((compare > 0) || compare == 0 && (microstep >= event.microstep())) {
    return true;
  }
 else {
    if (!_eventTimedInterruptTimes.containsKey(event)) {
      _eventTimedInterruptTimes.put(event,waitUntilPhysicalTime);
      _timedInterruptWakeUpTimes.add(waitUntilPhysicalTime);
      Collections.sort(_timedInterruptWakeUpTimes);
      _fireAtPlatformTime(waitUntilPhysicalTime,PLATFORM_TIMER);
    }
    return false;
  }
}

Fixed version (ground truth):
/** 
 * If the event's destination port does not have a delayOffset parameter, or if there doesn't exist a destination port (in case of pure event) then the event is always safe to process. Otherwise: If the current physical time has passed the timestamp of the event minus delayOffset of the port, then the event is safe to process. Otherwise the event is not safe to process, and we calculate the physical time when the event is safe to process and setup a timed interrupt. This method calls _setTimedInterrupt at the oracle time of the corresponding safe-to-process time.
 * @see #_setTimedInterrupt(Time)
 * @see #_getOraclePhysicalTagForPlatformPhysicalTag(Tag)
 * @param event The event checked for safe to process
 * @return True if the event is safe to process, otherwise return false.
 * @exception IllegalActionException If port is null and event is not a pureevent.
 * @see #_setTimedInterrupt(Time)
 */
protected boolean _safeToProcess(PtidesEvent event) throws IllegalActionException {
  IOPort port=event.ioPort();
  if (port == null) {
    assert(event.isPureEvent());
    return true;
  }
  assert(!port.isOutput());
  double delayOffset=_getMininumDelayOffset(port,((PtidesEvent)event).channel(),event.isPureEvent());
  Time waitUntilPhysicalTime=event.timeStamp().subtract(delayOffset);
  Tag platformPhysicalTag=getPlatformPhysicalTag(PLATFORM_TIMER);
  int compare=platformPhysicalTag.timestamp.subtract(waitUntilPhysicalTime).compareTo(_zero);
  int microstep=platformPhysicalTag.microstep;
  if ((compare > 0) || compare == 0 && (microstep >= event.microstep())) {
    return true;
  }
 else {
    if (!_eventsWithTimedInterrupt.contains(event)) {
      _eventsWithTimedInterrupt.add(event);
      TimedEvent timedEvent=new TimedEvent(waitUntilPhysicalTime,event);
      _timedInterruptTimes.add(timedEvent);
      Collections.sort(_timedInterruptTimes);
      _fireAtPlatformTime(waitUntilPhysicalTime,PLATFORM_TIMER);
    }
    return false;
  }
}