[tck] httpupgradehandler does not make sure that a `HttpUpgradeHandler` can be initialized properly
Challenged tests https://github.com/jakartaee/servlet/blob/master/tck/tck-runtime/src/main/java/servlet/tck/api/jakarta_servlet_http/httpupgradehandler/HttpUpgradeHandlerTests.java
TCK Version Jakarta Servlet 6+
Description The spec says:
When an upgrade request is received, the servlet can invoke the HttpServletRequest.upgrade method, which starts the upgrade process. This method instantiates the given HttpUpgradeHandler class. The returned HttpUpgradeHandler instance may be further customized. After exiting the service method of the servlet, the servlet container completes the processing of all filters and marks the connection to be handled by the HttpUpgradeHandler. It then calls the HttpUpgradeHandler's init method, passing a WebConnection to allow the protocol handler access to the data streams.
This part of the specification is not correctly covered by the given TCK test:
In the TCKHttpUpgradeHandler the field delimiter is default initialized to the value /
https://github.com/jakartaee/servlet/blob/4e6a0b43f3c3b8bb77bb505c11c3cd154e5deaa1/tck/tck-runtime/src/main/java/servlet/tck/api/jakarta_servlet_http/httpupgradehandler/TCKHttpUpgradeHandler.java#L29
in the TestServlet the delimiter is set to the value /
https://github.com/jakartaee/servlet/blob/4e6a0b43f3c3b8bb77bb505c11c3cd154e5deaa1/tck/tck-runtime/src/main/java/servlet/tck/api/jakarta_servlet_http/httpupgradehandler/TestServlet.java#L42
So there is literally no way for the value to be any different than / at any time that can be observed from outside.
A much better way would be:
- Let the value keep the default without implicit initialization (resulting in
nullbeing the value at construction time) - Let TCKReadListener use
Objects.requireNonNull(delimiter)in the constructor to fail if the value failed to be initialized byTestServlet - Furthermore
TCKReadListenershould have a method that returns the used delimiter -
TCKHttpUpgradeHandler#getDelimitershould return the delimiter fromTCKReadListenerand assert it is nonnull.
That way the TCK would make sure:
- Instances of a
HttpUpgradeHandlercan be initialized -
init(WebConnection wc)is not called to early or called never
Additional context I noticed this here while testing the Jetty Implementation that passes the TCK:
- https://github.com/jetty/jetty.project/issues/13335#issuecomment-3049134947