jetty.project icon indicating copy to clipboard operation
jetty.project copied to clipboard

Fallback to server-level ErrorHandler broken for EE8-9 apps

Open twbecker opened this issue 2 months ago • 0 comments

Jetty version(s) 12.1.3

Jetty Environment ee8, ee9

Java version/vendor (use: java -version) 21

Description The ability to set a single ErrorHandler on the Server and have it work for ee8 and ee9 applications doesn't work. There are 2 reasons for this:

  1. The WebAppContext tries hard to make sure an ErrorHandler is set at the context level, even if you don't specify one. You can set it to null post-construction but...
  2. The code that tries to fallback to the Server-level handler in ErrorHandler.getErrorHandler() doesn't work because it tries to get an ee8 ErrorHandler from the server:
    public static ErrorHandler getErrorHandler(Server server, ContextHandler context) {
        ErrorHandler errorHandler = null;
        if (context != null)
            errorHandler = context.getErrorHandler();
        if (errorHandler == null && server != null)
            errorHandler = server.getBean(ErrorHandler.class); // <- EE8 ErrorHandler
        return errorHandler;
    }

Also, it's worth pointing out that the ee8-9 versions of ErrorHandler do not extend the core one like the ee10-11 do. The net effect of this is that we have to have 2 separate implementations of our custom handler to make sure it's used in all cases. Relevant mailing list thread: https://www.eclipse.org/lists/jetty-users/msg10938.html

twbecker avatar Oct 29 '25 12:10 twbecker