Skip to content

Conversation

infvg
Copy link

@infvg infvg commented Oct 16, 2025

Sometimes Presto can run into this error:

java.lang.NullPointerException: Cannot invoke "java.nio.ByteBuffer.remaining()" because "content" is null
	at com.facebook.airlift.http.server.HttpServerChannelListener.onResponseWrite(HttpServerChannelListener.java:77)
	at org.eclipse.jetty.server.handler.EventsHandler.notifyOnResponseWrite(EventsHandler.java:149)
	at org.eclipse.jetty.server.handler.EventsHandler$EventsResponse.write(EventsHandler.java:352)
	at org.eclipse.jetty.server.Response$Wrapper.write(Response.java:768)
	at org.eclipse.jetty.server.handler.EventsHandler$EventsResponse.write(EventsHandler.java:353)
	at org.eclipse.jetty.server.Response$Wrapper.write(Response.java:768)
	at org.eclipse.jetty.server.handler.ContextResponse.write(ContextResponse.java:56)
	at org.eclipse.jetty.ee10.servlet.ServletContextResponse.write(ServletContextResponse.java:288)
	at org.eclipse.jetty.server.Response$Wrapper.write(Response.java:768)
	at org.eclipse.jetty.server.handler.gzip.GzipResponseAndCallback.commit(GzipResponseAndCallback.java:191)
	at org.eclipse.jetty.server.handler.gzip.GzipResponseAndCallback.write(GzipResponseAndCallback.java:132)
	at org.eclipse.jetty.server.handler.gzip.GzipResponseAndCallback.succeeded(GzipResponseAndCallback.java:97)
	at org.eclipse.jetty.ee10.servlet.ServletChannel.onCompleted(ServletChannel.java:760)
	at org.eclipse.jetty.ee10.servlet.ServletChannel.handle(ServletChannel.java:426)
	at org.eclipse.jetty.ee10.servlet.ServletHandler.handle(ServletHandler.java:469)
	at org.eclipse.jetty.server.handler.gzip.GzipHandler.handle(GzipHandler.java:611)
	at org.eclipse.jetty.server.handler.ContextHandler.handle(ContextHandler.java:1064)
	at org.eclipse.jetty.server.Handler$Sequence.handle(Handler.java:805)
	at org.eclipse.jetty.server.Handler$Wrapper.handle(Handler.java:740)
	at org.eclipse.jetty.server.handler.EventsHandler.handle(EventsHandler.java:81)
	at org.eclipse.jetty.server.Handler$Wrapper.handle(Handler.java:740)
	at org.eclipse.jetty.server.handler.EventsHandler.handle(EventsHandler.java:81)
	at org.eclipse.jetty.server.handler.ContextHandlerCollection.handle(ContextHandlerCollection.java:151)
	at org.eclipse.jetty.server.Server.handle(Server.java:182)
	at org.eclipse.jetty.server.internal.HttpChannelState$HandlerInvoker.run(HttpChannelState.java:662)
	at org.eclipse.jetty.server.internal.HttpConnection.onFillable(HttpConnection.java:416)
	at org.eclipse.jetty.io.AbstractConnection$ReadCallback.succeeded(AbstractConnection.java:322)
	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:480)
	at org.eclipse.jetty.util.thread.strategy.AdaptiveExecutionStrategy.consumeTask(AdaptiveExecutionStrategy.java:443)
	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.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:833)

This PR will resolve it by adding a null check.

@infvg infvg requested a review from a team as a code owner October 16, 2025 11:04
Copy link

sourcery-ai bot commented Oct 16, 2025

Reviewer's guide (collapsed on small PRs)

Reviewer's Guide

This PR adds a null check for the ByteBuffer content in HttpServerChannelListener.onResponseWrite to prevent NullPointerExceptions when content is null, ensuring response size metrics are only updated when content exists.

Sequence diagram for updated response size update in onResponseWrite

sequenceDiagram
participant Listener as HttpServerChannelListener
participant Req as Request
participant Size as AtomicLong
participant Content as ByteBuffer
Listener->>Req: getAttribute(RESPONSE_CONTENT_SIZES_ATTRIBUTE)
alt RESPONSE_CONTENT_SIZES_ATTRIBUTE is null
    Listener->>Req: setAttribute(RESPONSE_CONTENT_SIZES_ATTRIBUTE, new AtomicLong(0L))
end
alt content != null
    Listener->>Req: getAttribute(RESPONSE_CONTENT_SIZES_ATTRIBUTE)
    Listener->>Size: addAndGet(content.remaining())
else content == null
    Note over Listener: skips response size update
end
Loading

Class diagram for updated HttpServerChannelListener.onResponseWrite method

classDiagram
class HttpServerChannelListener {
    +onResponseWrite(Request request, boolean last, ByteBuffer content)
}
class Request {
    +getAttribute(String key)
    +setAttribute(String key, Object value)
}
class AtomicLong {
    +addAndGet(long delta)
}
HttpServerChannelListener --> Request
Request --> AtomicLong

%% Highlight: onResponseWrite now checks if content != null before updating response size
Loading

File-Level Changes

Change Details Files
Add null guard around content-based size update to prevent NPE
  • Wrap responseSize update logic in an if (content != null) check
  • Retrieve and update AtomicLong inside the null check
  • Cast content.remaining() to long for addAndGet
http-server/src/main/java/com/facebook/airlift/http/server/HttpServerChannelListener.java

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

Copy link

@sourcery-ai sourcery-ai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey there - I've reviewed your changes and they look great!


Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

Copy link

@pratyakshsharma pratyakshsharma left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for the fix

@pratyakshsharma
Copy link

I have never seen this error anytime before. Wondering if this is a byproduct of upgrading to java 17

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants