Program: 57291
Project: 57291
Buggy source:
/** 
 * Accept a step, triggering events and step handlers.
 * @param interpolator step interpolator
 * @param y state vector at step end time, must be reset if an eventasks for resetting or if an events stops integration during the step
 * @param yDot placeholder array where to put the time derivative of the state vector
 * @param tEnd final integration time
 * @return time at end of step
 * @exception MathIllegalStateException if the value of one event state cannot be evaluated
 * @since 2.2
 */
protected double acceptStep(final AbstractStepInterpolator interpolator,final double[] y,final double[] yDot,final double tEnd) throws MathIllegalStateException {
  double previousT=interpolator.getGlobalPreviousTime();
  final double currentT=interpolator.getGlobalCurrentTime();
  resetOccurred=false;
  if (!statesInitialized) {
    for (    EventState state : eventsStates) {
      state.reinitializeBegin(interpolator);
    }
    statesInitialized=true;
  }
  final int orderingSign=interpolator.isForward() ? +1 : -1;
  SortedSet<EventState> occuringEvents=new TreeSet<EventState>(new Comparator<EventState>(){
    /** 
 * {@inheritDoc} 
 */
    public int compare(    EventState es0,    EventState es1){
      return orderingSign * Double.compare(es0.getEventTime(),es1.getEventTime());
    }
  }
);
  for (  final EventState state : eventsStates) {
    if (state.evaluateStep(interpolator)) {
      occuringEvents.add(state);
    }
  }
  while (!occuringEvents.isEmpty()) {
    final Iterator<EventState> iterator=occuringEvents.iterator();
    final EventState currentEvent=iterator.next();
    iterator.remove();
    final double eventT=currentEvent.getEventTime();
    interpolator.setSoftPreviousTime(previousT);
    interpolator.setSoftCurrentTime(eventT);
    interpolator.setInterpolatedTime(eventT);
    final double[] eventY=interpolator.getInterpolatedState();
    currentEvent.stepAccepted(eventT,eventY);
    isLastStep=currentEvent.stop();
    for (    final StepHandler handler : stepHandlers) {
      handler.handleStep(interpolator,isLastStep);
    }
    if (isLastStep) {
      System.arraycopy(eventY,0,y,0,y.length);
      return eventT;
    }
    if (currentEvent.reset(eventT,eventY)) {
      System.arraycopy(eventY,0,y,0,y.length);
      computeDerivatives(eventT,y,yDot);
      resetOccurred=true;
      return eventT;
    }
    previousT=eventT;
    interpolator.setSoftPreviousTime(eventT);
    interpolator.setSoftCurrentTime(currentT);
    if (currentEvent.evaluateStep(interpolator)) {
      occuringEvents.add(currentEvent);
    }
  }
  interpolator.setInterpolatedTime(currentT);
  final double[] currentY=interpolator.getInterpolatedState();
  for (  final EventState state : eventsStates) {
    state.stepAccepted(currentT,currentY);
    isLastStep=isLastStep || state.stop();
  }
  isLastStep=isLastStep || Precision.equals(currentT,tEnd,1);
  for (  StepHandler handler : stepHandlers) {
    handler.handleStep(interpolator,isLastStep);
  }
  return currentT;
}

Fixed version (ground truth):
/** 
 * Accept a step, triggering events and step handlers.
 * @param interpolator step interpolator
 * @param y state vector at step end time, must be reset if an eventasks for resetting or if an events stops integration during the step
 * @param yDot placeholder array where to put the time derivative of the state vector
 * @param tEnd final integration time
 * @return time at end of step
 * @exception MathIllegalStateException if the value of one event state cannot be evaluated
 * @since 2.2
 */
protected double acceptStep(final AbstractStepInterpolator interpolator,final double[] y,final double[] yDot,final double tEnd) throws MathIllegalStateException {
  double previousT=interpolator.getGlobalPreviousTime();
  final double currentT=interpolator.getGlobalCurrentTime();
  if (!statesInitialized) {
    for (    EventState state : eventsStates) {
      state.reinitializeBegin(interpolator);
    }
    statesInitialized=true;
  }
  final int orderingSign=interpolator.isForward() ? +1 : -1;
  SortedSet<EventState> occuringEvents=new TreeSet<EventState>(new Comparator<EventState>(){
    /** 
 * {@inheritDoc} 
 */
    public int compare(    EventState es0,    EventState es1){
      return orderingSign * Double.compare(es0.getEventTime(),es1.getEventTime());
    }
  }
);
  for (  final EventState state : eventsStates) {
    if (state.evaluateStep(interpolator)) {
      occuringEvents.add(state);
    }
  }
  while (!occuringEvents.isEmpty()) {
    final Iterator<EventState> iterator=occuringEvents.iterator();
    final EventState currentEvent=iterator.next();
    iterator.remove();
    final double eventT=currentEvent.getEventTime();
    interpolator.setSoftPreviousTime(previousT);
    interpolator.setSoftCurrentTime(eventT);
    interpolator.setInterpolatedTime(eventT);
    final double[] eventY=interpolator.getInterpolatedState();
    currentEvent.stepAccepted(eventT,eventY);
    isLastStep=currentEvent.stop();
    for (    final StepHandler handler : stepHandlers) {
      handler.handleStep(interpolator,isLastStep);
    }
    if (isLastStep) {
      System.arraycopy(eventY,0,y,0,y.length);
      for (      final EventState remaining : occuringEvents) {
        remaining.stepAccepted(eventT,eventY);
      }
      return eventT;
    }
    if (currentEvent.reset(eventT,eventY)) {
      System.arraycopy(eventY,0,y,0,y.length);
      computeDerivatives(eventT,y,yDot);
      resetOccurred=true;
      for (      final EventState remaining : occuringEvents) {
        remaining.stepAccepted(eventT,eventY);
      }
      return eventT;
    }
    previousT=eventT;
    interpolator.setSoftPreviousTime(eventT);
    interpolator.setSoftCurrentTime(currentT);
    if (currentEvent.evaluateStep(interpolator)) {
      occuringEvents.add(currentEvent);
    }
  }
  interpolator.setInterpolatedTime(currentT);
  final double[] currentY=interpolator.getInterpolatedState();
  for (  final EventState state : eventsStates) {
    state.stepAccepted(currentT,currentY);
    isLastStep=isLastStep || state.stop();
  }
  isLastStep=isLastStep || Precision.equals(currentT,tEnd,1);
  for (  StepHandler handler : stepHandlers) {
    handler.handleStep(interpolator,isLastStep);
  }
  return currentT;
}