code: public <R> R doInContext(SearchContext context, Supplier<R> action) {
          R result;
          if (context == null) {
              result = action.get();
          } else {
              // store current context (without triggering exception if it was stale)
              SearchContext currentSearchContext = currentContext;
              boolean contextIsStale = currentContextIsStale;
  
              setCurrentContext(context);
              try {
                  result = action.get();
              } finally {
                  // make original current context active again
                  currentContext = currentSearchContext;
                  currentContextIsStale = contextIsStale;
              }
          }
          return result;
      }
docs: Perform action/supplier in context.
  @param context context to perfom action in.
  @param action action to perform.
  @param <R> type of action result.
  @return action result.