-
Notifications
You must be signed in to change notification settings - Fork 1.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
UpgradeHttpServletRequest.setAttribute & UpgradeHttpServletRequest.removeAttribute can throw NullPointerException #7977
Comments
Can you show us a full stacktrace of your NullPointerException? |
I think we are just missing the else branch here as |
Signed-off-by: Lachlan Roberts <[email protected]>
Opened PR #7982 |
@joakime I don't think that will help you, but as @lachlan-roberts says, the "else" is missing
|
It may seem obvious, but how did his code even reach this point where request is null? The fact that there's a ServletRequestWrapper in the stacktrace is a red flag indicating bad usage of the APIs. The stacktrace also shows ...
Also, when you enter onWebSocketConnect there is are no longer any valid HttpServletRequest or HttpServletResponse objects (you left HTTP and are now WebSocket, which no longer has any HTTP facilities), you shouldn't be using those objects in any way from this point forward. This also hints at code that holds onto those objects improperly for both WebSocket and Servlet specs. The proposed fix in PR #7982 is just going to quietly break their usage of WebSocket resulting in a broken experience with no details on why. I feel the fix should go the other way entirely, and throw an exception if the HttpServletRequest (or HttpServletResponse) are wrapped, or not original Jetty request objects, or null. |
The original intention in this code was to copy the request attributes across to this But we have discouraged the reliance on this by having the @EricBlanquer How are you getting the |
I need to route client HTTP request and WebSocket based on informations that can be found into headers, cookie or path of the request now, I need to provide some metrics on each requests: time, user name found, etc... I've added a check to use this setAttribute only if the request is not a UpgradeHttpServletRequest request, that's OK for me but the UpgradeHttpServletRequest should not throw this NPE |
@EricBlanquer you need to go further. This is important. The only safe time to access the HttpServletRequest, HttpServletResponse, and HttpSession is during the negotiation of the upgrade (which is before onConnect). |
Issue #7977 - prevent possible NPE from UpgradeHttpServletRequest
Merged PR #7982 which prevents NPE when changing attributes after WS upgrade. These changes will be available in the next release ( |
if the "request" object is null
UpgradeHttpServletRequest.setAttribute:
https://github.com/eclipse/jetty.project/blob/2c812f631e3a5c2fd69147f34f5c65cd36dd2137/jetty-websocket/websocket-core-server/src/main/java/org/eclipse/jetty/websocket/core/server/internal/UpgradeHttpServletRequest.java#L433
and
UpgradeHttpServletRequest.removeAttribute:
https://github.com/eclipse/jetty.project/blob/2c812f631e3a5c2fd69147f34f5c65cd36dd2137/jetty-websocket/websocket-core-server/src/main/java/org/eclipse/jetty/websocket/core/server/internal/UpgradeHttpServletRequest.java#L441
can throw NullPointerException
The text was updated successfully, but these errors were encountered: