Program: 57324
Project: 57324
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 IntegratorException if the value of one event state cannot be evaluated
 */
protected double acceptStep(final AbstractStepInterpolator interpolator,final double[] y,final double[] yDot,final double tEnd) throws IntegratorException {
  try {
    double previousT=interpolator.getGlobalPreviousTime();
    final double currentT=interpolator.getGlobalCurrentTime();
    resetOccurred=false;
    if (!statesInitialized) {
      for (      EventState state : eventsStates) {
        state.reinitializeBegin(interpolator);
      }
      statesInitialized=true;
    }
    SortedSet<EventState> occuringEvents=new TreeSet<EventState>();
    for (    final EventState state : eventsStates) {
      if (state.evaluateStep(interpolator)) {
        occuringEvents.add(state);
      }
    }
    for (    final EventState state : occuringEvents) {
      final double eventT=state.getEventTime();
      interpolator.setSoftBounds(previousT,eventT);
      interpolator.setInterpolatedTime(eventT);
      final double[] eventY=interpolator.getInterpolatedState();
      state.stepAccepted(eventT,eventY);
      isLastStep=state.stop();
      for (      final StepHandler handler : stepHandlers) {
        handler.handleStep(interpolator,isLastStep);
      }
      if (isLastStep) {
        System.arraycopy(eventY,0,y,0,y.length);
        return eventT;
      }
      if (state.reset(eventT,eventY)) {
        System.arraycopy(eventY,0,y,0,y.length);
        computeDerivatives(eventT,y,yDot);
        resetOccurred=true;
        return eventT;
      }
      previousT=eventT;
      interpolator.setSoftBounds(eventT,currentT);
    }
    interpolator.setInterpolatedTime(currentT);
    final double[] currentY=interpolator.getInterpolatedState();
    for (    final EventState state : eventsStates) {
      state.stepAccepted(currentT,currentY);
      isLastStep=isLastStep || state.stop();
    }
    isLastStep=isLastStep || MathUtils.equals(currentT,tEnd,1);
    for (    StepHandler handler : stepHandlers) {
      handler.handleStep(interpolator,isLastStep);
    }
    return currentT;
  }
 catch (  EventException se) {
    final Throwable cause=se.getCause();
    if ((cause != null) && (cause instanceof MathUserException)) {
      throw (MathUserException)cause;
    }
    throw new IntegratorException(se);
  }
catch (  ConvergenceException ce) {
    throw new IntegratorException(ce);
  }
}

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 IntegratorException if the value of one event state cannot be evaluated
 */
protected double acceptStep(final AbstractStepInterpolator interpolator,final double[] y,final double[] yDot,final double tEnd) throws IntegratorException {
  try {
    double previousT=interpolator.getGlobalPreviousTime();
    final double currentT=interpolator.getGlobalCurrentTime();
    resetOccurred=false;
    if (!statesInitialized) {
      for (      EventState state : eventsStates) {
        state.reinitializeBegin(interpolator);
      }
      statesInitialized=true;
    }
    SortedSet<EventState> occuringEvents=new TreeSet<EventState>(new Comparator<EventState>(){
      /** 
 * {@inheritDoc} 
 */
      public int compare(      EventState es0,      EventState es1){
        return Double.compare(es0.getEventTime(),es1.getEventTime());
      }
    }
);
    for (    final EventState state : eventsStates) {
      if (state.evaluateStep(interpolator)) {
        occuringEvents.add(state);
      }
    }
    for (    final EventState state : occuringEvents) {
      final double eventT=state.getEventTime();
      interpolator.setSoftPreviousTime(previousT);
      interpolator.setSoftCurrentTime(eventT);
      interpolator.setInterpolatedTime(eventT);
      final double[] eventY=interpolator.getInterpolatedState();
      state.stepAccepted(eventT,eventY);
      isLastStep=state.stop();
      for (      final StepHandler handler : stepHandlers) {
        handler.handleStep(interpolator,isLastStep);
      }
      if (isLastStep) {
        System.arraycopy(eventY,0,y,0,y.length);
        return eventT;
      }
      if (state.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);
    }
    interpolator.setInterpolatedTime(currentT);
    final double[] currentY=interpolator.getInterpolatedState();
    for (    final EventState state : eventsStates) {
      state.stepAccepted(currentT,currentY);
      isLastStep=isLastStep || state.stop();
    }
    isLastStep=isLastStep || MathUtils.equals(currentT,tEnd,1);
    for (    StepHandler handler : stepHandlers) {
      handler.handleStep(interpolator,isLastStep);
    }
    return currentT;
  }
 catch (  EventException se) {
    final Throwable cause=se.getCause();
    if ((cause != null) && (cause instanceof MathUserException)) {
      throw (MathUserException)cause;
    }
    throw new IntegratorException(se);
  }
catch (  ConvergenceException ce) {
    throw new IntegratorException(ce);
  }
}