-
Notifications
You must be signed in to change notification settings - Fork 106
Description
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 /
Line 29 in 4e6a0b4
| private String delimiter = "/"; |
in the TestServlet the delimiter is set to the value /
Line 42 in 4e6a0b4
| handler.setDelimiter("/"); |
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: