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

        Hide
        janbartel added a comment - - edited

        Can we please have some clarification on what this wording means prior to Public Final release?

        There was never any answer to Mark's question on the email thread about this issue "About SERVLET_SPEC_35" on the mailing list.

        thanks
        Jan

        Show
        janbartel added a comment - - edited Can we please have some clarification on what this wording means prior to Public Final release? There was never any answer to Mark's question on the email thread about this issue "About SERVLET_SPEC_35" on the mailing list. thanks Jan
        Hide
        Rajiv Mordani added a comment -

        Yes the reference is to the ServletContextListener and not the ServletContext.

        The case I believe we were trying to address with this in Servlet 3.0 time was that when ServletContextListener was created from a TLD, then those listeners should not be allowed to use the programmatic APIs.

        Show
        Rajiv Mordani added a comment - Yes the reference is to the ServletContextListener and not the ServletContext. The case I believe we were trying to address with this in Servlet 3.0 time was that when ServletContextListener was created from a TLD, then those listeners should not be allowed to use the programmatic APIs.
        Hide
        Rajiv Mordani added a comment -

        Yes in fact I did go back and look at the servlet 3.0 archives and we want to disallow the ServletContextListeners that were declared in TLDs. I have clarified the fact that it is the listener and not the ServletContext that needs to be declared and am marking this issue as fixed.

        Show
        Rajiv Mordani added a comment - Yes in fact I did go back and look at the servlet 3.0 archives and we want to disallow the ServletContextListeners that were declared in TLDs. I have clarified the fact that it is the listener and not the ServletContext that needs to be declared and am marking this issue as fixed.

          People

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

            Dates

            • Created:
              Updated:
              Resolved: