code: @SuppressWarnings("null")
    protected final Resource getRootResource(SlingHttpServletRequest request) {
      String path = RequestParam.get(request, RP_PATH);
      if (StringUtils.isEmpty(path) && request.getResource() != null) {
        path = request.getResource().getPath();
      }
      if (StringUtils.isNotEmpty(path)) {
        path = StringUtils.removeEnd(path, "/" + JcrConstants.JCR_CONTENT);
        return request.getResourceResolver().getResource(path);
      }
      return null;
    }
docs: Determine root resource to list its children. (use resource for root page because root node does not have to be a
  page but can be e.g. a nt:folder node)
  @param request Request
  @return Root resource or null if invalid resource was referenced