Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
[servlet-dev] Rationale for assertion Servlet:JAVADOC:668.6

Hi,

The following assertion states than an UnsupportedOperationException must be thrown if addFilter is called on a ServletContext passed to a ServletContextListener that wasn't declared by either annotation or xml:

<assertion required="true" impl-spec="false" status="active" testable="true">
        <id>Servlet:JAVADOC:668.6</id>
        <description>if this ServletContext was passed to the ServletContextListener.contextInitialized(jakarta.servlet.ServletContextEvent) method of a ServletContextListener that was neither declared in web.xml or web-fragment.xml, nor annotated with WebListener</description>
        <package>jakarta.servlet</package>
        <class-interface>ServletContext</class-interface>
        <method name="addFilter" return-type="jakarta.servlet.FilterRegistration.FilterRegistration.Dynamic">
            <parameters>
                <parameter>java.lang.String</parameter>
                <parameter>java.lang.String</parameter>
            </parameters>
            <throw>java.lang.UnsupportedOperationException</throw>
        </method>
    </assertion>

I wonder what's the exact reason for this.

In Piranha for example listeners are added from container initializers quite universally and the web.xml and annotation ones add listeners in the same way as other container initializers would:

public void configure(WebApplication webApplication) {
        webApplication.addInitializer(new WebXmlInitializer());
        webApplication.addInitializer(new WebAnnotationInitializer());
        webApplication.addInitializer(new JakartaSecurityAllInitializer());
        webApplication.addInitializer(new ServletContainerAllInitializer());
 }

Making a distinction from listeners that have been added by (in this case) the WebXmlInitializer and say the ServletContainerAllInitializer is therefore quite artificial.

Now I appreciate that other containers might work differently, but I still wonder; is there really a need for this exception in other containers? I'm probably missing something and assume some potential ordering issue, but at the moment I don't quite see it.

Kind regards,
Arjan







Back to the top