code: @java.lang.SuppressWarnings({"rawtypes", "unchecked"}) // public RequestImpl ctor requires List<AncestorImpl> yet AncestorImpl is not public! API design flaw
      private static RequestImpl createMockRequest() {
          RequestImpl currentRequest = (RequestImpl) Stapler.getCurrentRequest();
          HttpServletRequest original = (HttpServletRequest) currentRequest.getRequest();
          final Map<String,Object> getters = new HashMap<>();
          for (Method method : HttpServletRequest.class.getMethods()) {
              String m = method.getName();
              if ((m.startsWith("get") || m.startsWith("is")) && method.getParameterTypes().length == 0) {
                  Class<?> type = method.getReturnType();
                  // TODO could add other types which are known to be safe to copy: Cookie[], Principal, HttpSession, etc.
                  if (type.isPrimitive() || type == String.class || type == Locale.class) {
                      try {
                          getters.put(m, method.invoke(original));
                      } catch (Exception x) {
                          LOG.log(Level.WARNING, "cannot mock Stapler request " + method, x);
                      }
                  }
              }
          }
          List/*<AncestorImpl>*/ ancestors = currentRequest.ancestors;
          LOG.log(Level.FINER, "mocking ancestors {0} using {1}", new Object[] {ancestors, getters});
          TokenList tokens = currentRequest.tokens;
          return new RequestImpl(Stapler.getCurrent(), (HttpServletRequest) Proxy.newProxyInstance(ProgressiveRendering.class.getClassLoader(), new Class<?>[] {HttpServletRequest.class}, new InvocationHandler() {
              @Override public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
                  String m = method.getName();
                  if (getters.containsKey(m)) {
                      return getters.get(m);
                  } else { // TODO implement other methods as needed
                      throw new UnsupportedOperationException(m);
                  }
              }
          }), ancestors, tokens);
      }
docs: Copies important fields from the current HTTP request and makes them available during {@link #compute}.
  This is necessary because some model methods such as {@link AbstractItem#getUrl} behave differently when called from a request.