servlet-spec
  1. servlet-spec
  2. SERVLET_SPEC-35

Clarification on section 4.4 Servlet Context Configuration Methods

    Details

    • Type: Improvement Improvement
    • Status: Resolved
    • Priority: Major Major
    • Resolution: Fixed
    • Affects Version/s: None
    • Fix Version/s: None
    • Labels:
      None

      Description

      If the ServletContext passed to the ServletContextListener's
      contextInitialized method was neither declared in web.xml or
      webfragment.xml nor annotated with @WebListener then an
      UnsupportedOperationException MUST be thrown for all the
      methods defined for programmatic configuration of servlets,
      filters and listeners.

      This sentence is misleading; leaving out the relative clause gives:

      If the ServletContext was neither declared in web.xml or webfragment.xml nor annotated with @WebListener [...]

      The ServletContext is created by the Servlet container and can neither be declared in web.xml or webfragment nor annotated, but the ServletListenerContext can be. So, if

      neither declared in web.xml or webfragment.xml nor annotated with @WebListener

      refers to ServletContextListener, please make that clear.

      Still, I don't understand, why and when an UnsupportedOperationException must be thrown. Must it be thrown when that ServletContextListener is added via ServletContext#addListener? What sense would it make to throw an exception here? If that listener had been declared in web.xml or webfragment.xml or annotated, there would be no need to add it programmatically in the first place.

        Activity

          People

          • Assignee:
            Rajiv Mordani
            Reporter:
            Christian Ludt
          • Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved: