Skip to content
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

HttpFields$Mutable$Wrapper.computeField() incorrectly calls onAddField() when null is returned by computeFn #11687

Closed
lorban opened this issue Apr 23, 2024 · 0 comments · Fixed by #11688
Assignees
Labels
Bug For general bugs on Jetty side Sponsored This issue affects a user with a commercial support agreement

Comments

@lorban
Copy link
Contributor

lorban commented Apr 23, 2024

Jetty version(s)
12.0.8

Jetty Environment
ee10

Description

The HttpFields$Mutable.computeField() contract explicitly specifies that if the computeFn returns null, this means the field should be removed. Unfortunately, the default implementation of computeField() calls put() which incorrectly calls Wrapper.onAddField() with a null value.

When the protocol is HTTP 1.0, ResponseUtils.ensureNotPersistent() uses computeField() to remove the connection header, so that triggers the following exception:

java.lang.IllegalStateException: java.lang.NullPointerException: Cannot invoke "org.eclipse.jetty.http.HttpField.getHeader()" because "field" is null
	at org.eclipse.jetty.ee10.servlet.ServletChannelState.onError(ServletChannelState.java:874)
	at org.eclipse.jetty.ee10.servlet.ServletChannel.handleException(ServletChannel.java:667)
	at org.eclipse.jetty.ee10.servlet.ServletChannel.handle(ServletChannel.java:584)
	at org.eclipse.jetty.ee10.servlet.AsyncContentProducer.lambda$isReady$0(AsyncContentProducer.java:260)
	at org.eclipse.jetty.server.handler.ContextHandler$ScopedContext.run(ContextHandler.java:1298)
	at org.eclipse.jetty.server.handler.ContextRequest$OnContextDemand.run(ContextRequest.java:74)
	at org.eclipse.jetty.util.thread.SerializedInvoker$Link.run(SerializedInvoker.java:191)
	at org.eclipse.jetty.server.internal.HttpConnection$DemandContentCallback.succeeded(HttpConnection.java:679)
	at org.eclipse.jetty.io.FillInterest.fillable(FillInterest.java:99)
	at org.eclipse.jetty.io.SelectableChannelEndPoint$1.run(SelectableChannelEndPoint.java:53)
	at org.eclipse.jetty.util.thread.strategy.AdaptiveExecutionStrategy.runTask(AdaptiveExecutionStrategy.java:478)
	at org.eclipse.jetty.util.thread.strategy.AdaptiveExecutionStrategy.consumeTask(AdaptiveExecutionStrategy.java:441)
	at org.eclipse.jetty.util.thread.strategy.AdaptiveExecutionStrategy.tryProduce(AdaptiveExecutionStrategy.java:293)
	at org.eclipse.jetty.util.thread.strategy.AdaptiveExecutionStrategy.run(AdaptiveExecutionStrategy.java:201)
	at org.eclipse.jetty.util.thread.ReservedThreadExecutor$ReservedThread.run(ReservedThreadExecutor.java:311)
	at org.eclipse.jetty.util.thread.MonitoredQueuedThreadPool$1.run(MonitoredQueuedThreadPool.java:73)
	at org.eclipse.jetty.util.thread.QueuedThreadPool.runJob(QueuedThreadPool.java:979)
	at org.eclipse.jetty.util.thread.QueuedThreadPool$Runner.doRunJob(QueuedThreadPool.java:1209)
	at org.eclipse.jetty.util.thread.QueuedThreadPool$Runner.run(QueuedThreadPool.java:1164)
	at java.base/java.lang.Thread.run(Thread.java:1570)
Caused by: java.lang.NullPointerException: Cannot invoke "org.eclipse.jetty.http.HttpField.getHeader()" because "field" is null
	at org.eclipse.jetty.ee10.servlet.ServletContextResponse$HttpFieldsWrapper.onAddField(ServletContextResponse.java:567)
	at org.eclipse.jetty.http.HttpFields$Mutable$Wrapper.put(HttpFields.java:1678)
	at org.eclipse.jetty.http.HttpFields$Mutable.computeField(HttpFields.java:1372)
	at org.eclipse.jetty.server.ResponseUtils.ensureNotPersistent(ResponseUtils.java:40)
	at org.eclipse.jetty.server.ResponseUtils.ensureConsumeAvailableOrNotPersistent(ResponseUtils.java:31)
	at org.eclipse.jetty.ee10.servlet.ServletChannel.handle(ServletChannel.java:554)
	... 17 more
@lorban lorban added Bug For general bugs on Jetty side Sponsored This issue affects a user with a commercial support agreement labels Apr 23, 2024
@lorban lorban changed the title NPE thrown by HttpFields$Mutable.computeField() when null is returned HttpFields$Mutable$Wrapper.computeField() incorrectly calls onAddField() when null is returned by computeFn Apr 23, 2024
@lorban lorban self-assigned this Apr 23, 2024
lorban added a commit that referenced this issue Apr 23, 2024
…eld() and remove the field when null is returned by computeFn

Signed-off-by: Ludovic Orban <[email protected]>
@lorban lorban moved this to 🏗 In progress in Jetty 12.0.9 - FROZEN Apr 23, 2024
lorban added a commit that referenced this issue Apr 23, 2024
Signed-off-by: Ludovic Orban <[email protected]>
lorban added a commit that referenced this issue Apr 23, 2024
Signed-off-by: Ludovic Orban <[email protected]>
lorban added a commit that referenced this issue Apr 23, 2024
joakime pushed a commit that referenced this issue Apr 23, 2024
* #11687 make HttpFields.Mutable.Wrapper.computeField() call onRemoveField() and remove the field when null is returned by computeFn
* #11687 replace IAE with NPE
* #11687 replace collect(Collectors.toList()) with toList()

---------

Signed-off-by: Ludovic Orban <[email protected]>
@github-project-automation github-project-automation bot moved this from 🏗 In progress to ✅ Done in Jetty 12.0.9 - FROZEN Apr 23, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug For general bugs on Jetty side Sponsored This issue affects a user with a commercial support agreement
Projects
No open projects
Status: ✅ Done
Development

Successfully merging a pull request may close this issue.

1 participant