code: private void setState(final EvaluatorState toState) {
      while (true) {
  
        final EvaluatorState fromState = this.state.get();
        if (fromState == toState) {
          break;
        }
  
        if (!fromState.isLegalTransition(toState)) {
          LOG.log(Level.WARNING, "Illegal state transition: {0} -> {1}", new Object[] {fromState, toState});
          throw new IllegalStateException("Illegal state transition: " + fromState + " -> " + toState);
        }
  
        if (this.state.compareAndSet(fromState, toState)) {
          break;
        }
      }
    }
docs: Transition to the new state of the evaluator, if possible.
  @param toState New state of the evaluator.
  @throws IllegalStateException if state transition is not valid.