docs: public static ApplicationContext getWebApplicationContext(
              PortletRequest request, PortletContext portletContext) throws IllegalStateException {
  
          PortletApplicationContext portletApplicationContext = (PortletApplicationContext) request.getAttribute(
                  ContribDispatcherPortlet.PORTLET_APPLICATION_CONTEXT_ATTRIBUTE);
          if (portletApplicationContext != null) {
              return portletApplicationContext;
          }
          
          if (portletContext == null) {
              throw new IllegalStateException("No PortletApplicationContext found: not in a DispatcherPortlet request?");
          }
          portletApplicationContext = PortletApplicationContextUtils2.getPortletApplicationContext(portletContext);
          if (portletApplicationContext != null) {
              return portletApplicationContext;
          }
  
          return PortletApplicationContextUtils.getRequiredWebApplicationContext(portletContext);
      }