Improve Misleading Error Message in ContentTooLongException#1239
Merged
Conversation
|
💚 CLA has been signed |
l-trotta
approved these changes
May 27, 2026
Contributor
l-trotta
left a comment
There was a problem hiding this comment.
nice catch, thank you! LGTM
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #1238
Context
Repository: elastic/elasticsearch-java
Pull Request: #1239
Component: Content validation / Buffer management
Description
When an incoming data stream exceeds the configured maximum buffer limit, the client throws a ContentTooLongException. However, the error message incorrectly reports the size of the current incoming data chunk (src.limit()) instead of the total accumulated content length.
This results in a highly confusing error message for users and developers, as the reported "too long" content size often appears to be significantly smaller than the configured buffer limit, masking the actual reason the request failed.
Example Scenario
Resulting Exception Message: > "entity content is too long [8192] for the configured buffer limit [1000000]"
This makes debugging difficult, as it implies a chunk of ~8KB somehow breached a ~1MB limit.
Expected Behavior
The exception message should report the total calculated content length that caused the threshold to be breached, making it entirely clear why the data stream was rejected.
Expected Exception Message:
Actual Behavior
The exception message only references the size of the final byte buffer chunk (src.limit()), completely failing to account for the data already stored in the buffer (buffer.length()).