Skip to content

[tck] httpupgradehandler does not make sure that a HttpUpgradeHandler can be initialized properly #899

@laeubi

Description

@laeubi

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 /

in the TestServlet the delimiter is set to the value /

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 null being the value at construction time)
  • Let TCKReadListener use Objects.requireNonNull(delimiter) in the constructor to fail if the value failed to be initialized by TestServlet
  • Furthermore TCKReadListener should have a method that returns the used delimiter
  • TCKHttpUpgradeHandler#getDelimiter should return the delimiter from TCKReadListener and assert it is non null.

That way the TCK would make sure:

  1. Instances of a HttpUpgradeHandler can be initialized
  2. 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:

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions