Fixes UnsupportedOperationException when using readManyByPartitionKey for empty pages#49311
Merged
FabianMeiswinkel merged 8 commits intoJun 1, 2026
Conversation
Contributor
There was a problem hiding this comment.
Pull request overview
This PR fixes a Cosmos DB readManyByPartitionKey(s) failure where empty pages with immutable response headers could throw UnsupportedOperationException when stamping continuation tokens.
Changes:
- Detects known immutable header map shapes and defensively copies before mutating continuation headers.
- Adds unit tests for immutable-map detection and the customer-reported continuation-token stamping path.
- Preserves the no-op fast path for empty headers when no continuation header needs to be changed.
Show a summary per file
| File | Description |
|---|---|
sdk/cosmos/azure-cosmos/src/main/java/com/azure/cosmos/models/FeedResponse.java |
Copies known immutable header maps before setting/removing continuation tokens. |
sdk/cosmos/azure-cosmos/src/main/java/com/azure/cosmos/implementation/Utils.java |
Adds isImmutableMap helper for known immutable map implementations used by Cosmos internals. |
sdk/cosmos/azure-cosmos-tests/src/test/java/com/azure/cosmos/implementation/UtilsImmutableMapTests.java |
Adds unit coverage for immutable-map detection. |
sdk/cosmos/azure-cosmos-tests/src/test/java/com/azure/cosmos/implementation/ReadManyByPartitionKeyContinuationTokenTest.java |
Adds regression coverage for immutable non-empty headers in continuation-token stamping. |
Copilot's findings
- Files reviewed: 4/4 changed files
- Comments generated: 1
Member
Author
|
/azp run java - cosmos - spark |
Member
Author
|
/azp run java - cosmos - tests |
|
Azure Pipelines successfully started running 1 pipeline(s). |
1 similar comment
|
Azure Pipelines successfully started running 1 pipeline(s). |
ananth7592
reviewed
May 29, 2026
ananth7592
reviewed
May 29, 2026
ananth7592
approved these changes
May 29, 2026
Member
ananth7592
left a comment
There was a problem hiding this comment.
LGTM, Except for 2 minor comments
…202605 Update JarStorageAccountName from oltpsparkcijarstore0326 to oltpsparkcijarstore0529 to point to the new storage account provisioned in the current ephemeral tenant rotation. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Member
|
/azp run java - cosmos - spark |
Member
|
/azp run java - cosmos - tests |
|
Azure Pipelines successfully started running 1 pipeline(s). |
1 similar comment
|
Azure Pipelines successfully started running 1 pipeline(s). |
Member
|
@sdkReviewAgent |
xinlian12
reviewed
May 29, 2026
Member
|
✅ Review complete (54:17) Posted 1 inline comment(s). Steps: ✓ context, correctness, cross-sdk, design, history, past-prs, synthesis, test-coverage |
Member
Author
|
/azp run java - cosmos - spark |
|
Azure Pipelines successfully started running 1 pipeline(s). |
Member
Author
|
/azp run java - cosmos - tests |
|
Azure Pipelines successfully started running 1 pipeline(s). |
tvaron3
approved these changes
Jun 1, 2026
ananth7592
approved these changes
Jun 1, 2026
Member
Author
|
/check-enforcer override |
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.
Description
The driver stack trace when it fails is the following
26/05/29 08:30:24 WARN TaskSetManager: Lost task 3.0 in stage 42.0 (TID 108773) (10.181.218.61 executor 44): java.lang.UnsupportedOperationException
at java.util.Collections$UnmodifiableMap.put(Collections.java:1459)
at azure_cosmos_spark.com.azure.cosmos.models.FeedResponse.setContinuationTokenInternal(FeedResponse.java:453)
at azure_cosmos_spark.com.azure.cosmos.models.FeedResponse.setContinuationToken(FeedResponse.java:448)
at azure_cosmos_spark.com.azure.cosmos.models.ModelBridgeInternal.setFeedResponseContinuationToken(ModelBridgeInternal.java:605)
at azure_cosmos_spark.com.azure.cosmos.implementation.RxDocumentClientImpl.lambda$buildSequentialBatchFlux$132(RxDocumentClientImpl.java:4940)
at azure_cosmos_spark.reactor.core.publisher.FluxMap$MapSubscriber.onNext(FluxMap.java:106)
at azure_cosmos_spark.reactor.core.publisher.FluxFlatMap$FlatMapMain.tryEmit(FluxFlatMap.java:547)
at azure_cosmos_spark.reactor.core.publisher.FluxFlatMap$FlatMapInner.onNext(FluxFlatMap.java:988)
at azure_cosmos_spark.reactor.core.publisher.FluxOnErrorResume$ResumeSubscriber.onNext(FluxOnErrorResume.java:79)
This can happen when for a single physical partition the requested tuples don't have any matches - the empty page returned would have immutable headers.
All SDK Contribution checklist:
General Guidelines and Best Practices
Testing Guidelines