Affects Version/s: None
Fix Version/s: None
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.