You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Use of RewriteHandler.LastRuleHandler without a child handler should produce a clear error message. #12300
Description
If an instance of a Handler.Wrapper without a child is allowed to start and begin handling requests, the error message is unclear.
java.lang.NullPointerException: Cannot invoke "org.eclipse.jetty.server.Request$Handler.handle(org.eclipse.jetty.server.Request, org.eclipse.jetty.server.Response, org.eclipse.jetty.util.Callback)" because "this._handler" is null
We should make the start of this kind of handler fail the start and throw a meaningful message that the Handler.Wrapper is missing a child.
So we need a more meaningful message in RewriteHandler.LastRuleHandler if it starts with a null_handler.
It's possible to also put an IllegalStateException into Handler.Wrapper.doStart if the _handler is null but first we would have to check that the Handler.Wrapper instance is !dynamic (as if dynamic is true, starting without a handler set is allowed).
There is a use-case for optional handlers in Handler.Wrapper. The classic example is ServletHandler, which is a Wrapper, but typically does not have a nested Handler. This is only important for deployments without a default servlet.
changed the title [-]Use of Handler.Wrapper without a child handler should produce a clear error message.[/-][+]Use of RewriteHandler.LastRuleHandler without a child handler should produce a clear error message.[/+]on Sep 30, 2024
Hi,
First I'd like to thank you for all your work on Jetty.
I'm prepared do some work on this. I'd like to clarify an approach to the solution for this issue.
Starting off - Rule.Handler extends Request.Wrapper, and we can throw with a reasonable message from within LastRuleHandler or RewriteHandler.
LastRuleHandler is instantiated within RewriteHandler, and any exception can be handled along the same path as other Exceptions from handle().
We can add a throw(IllegalArgument) within the constructor for LastRuleHandler, or before LastRuleHandler _handler.handle(IllegalState or NullPointer). If we are ok with preventing the current rewrites if getHandler returns null, we can also perform the check within RewriteHandler's handler or by overriding its doStart().
Is the state legal if there's no downstream handler for a rewriteHandler ?
Can we add an exception within handler.wrapper.doStart() ? It may impact doStart() performance due to the exception check.
@codecrafter2017 I think the best approach is to override RewriteHandler.doStart() and there add a check about the child Handler: if null throw IllegalStateException.
The reason is that RewriteHandler is a non-dynamic Handler.Wrapper, so a child Handler cannot be added after it is started.
Activity
janbartel commentedon Sep 24, 2024
@joakime actually the issue is not coming from
Handler.Wrapper, this is a problem purely with theRewriteHandler.LastRuleHandler, which while it might be aHandler.Wrapperisn't using the inheritedhandler, but rather actually defines it's own_handlerhere: https://github.com/jetty/jetty.project/blob/jetty-12.0.x/jetty-core/jetty-rewrite/src/main/java/org/eclipse/jetty/rewrite/handler/RewriteHandler.java#L148.So we need a more meaningful message in
RewriteHandler.LastRuleHandlerif it starts with anull_handler.It's possible to also put an
IllegalStateExceptionintoHandler.Wrapper.doStartif the_handleris null but first we would have to check that theHandler.Wrapperinstance is!dynamic(as ifdynamicis true, starting without a handler set is allowed).gregw commentedon Sep 24, 2024
There is a use-case for optional handlers in Handler.Wrapper. The classic example is ServletHandler, which is a Wrapper, but typically does not have a nested Handler. This is only important for deployments without a default servlet.
[-]Use of Handler.Wrapper without a child handler should produce a clear error message.[/-][+]Use of RewriteHandler.LastRuleHandler without a child handler should produce a clear error message.[/+]sbordet commentedon Oct 21, 2024
@janbartel
LastRuleHandleris not aoej.server.Handler.Wrapper, but rather just aRequest.Wrapper.I agree that we might need a better error message, but it should not impact
oej.server.Handlerclasses.1 remaining item
codecrafter2017 commentedon Jun 25, 2025
Hi,
First I'd like to thank you for all your work on Jetty.
I'm prepared do some work on this. I'd like to clarify an approach to the solution for this issue.
Starting off - Rule.Handler extends Request.Wrapper, and we can throw with a reasonable message from within LastRuleHandler or RewriteHandler.
LastRuleHandler is instantiated within RewriteHandler, and any exception can be handled along the same path as other Exceptions from handle().
We can add a throw(IllegalArgument) within the constructor for LastRuleHandler, or before LastRuleHandler _handler.handle(IllegalState or NullPointer). If we are ok with preventing the current rewrites if getHandler returns null, we can also perform the check within RewriteHandler's handler or by overriding its doStart().
Is the state legal if there's no downstream handler for a rewriteHandler ?
Can we add an exception within handler.wrapper.doStart() ? It may impact doStart() performance due to the exception check.
sbordet commentedon Jul 4, 2025
@codecrafter2017 I think the best approach is to override
RewriteHandler.doStart()and there add a check about the childHandler: ifnullthrowIllegalStateException.The reason is that
RewriteHandleris a non-dynamicHandler.Wrapper, so a childHandlercannot be added after it is started.Please do this work in the
jetty-12.1.xbranch.Thanks!
Fixes jetty#12300: add null check in RewriteHandler.doStart() and uni…
Fixes jetty#12300: add null check in RewriteHandler.doStart() and uni…
Fixes #12300: add null check in RewriteHandler.doStart() and unit test (
sanjerai commentedon Aug 19, 2025
@sbordet i think this can be marked closed now as it has been merged.
sbordet commentedon Aug 19, 2025
Fixed by #13391.