Skip to content

[Cosmos] Fix ClassCastException when building CosmosException from an empty error response body#49323

Open
marcellustavares wants to merge 2 commits into
Azure:mainfrom
marcellustavares:fix/cosmoserror-empty-body-classcastexception
Open

[Cosmos] Fix ClassCastException when building CosmosException from an empty error response body#49323
marcellustavares wants to merge 2 commits into
Azure:mainfrom
marcellustavares:fix/cosmoserror-empty-body-classcastexception

Conversation

@marcellustavares
Copy link
Copy Markdown

Description

JsonSerializable.fromJson(String, ObjectMapper) performs an unchecked cast of the parsed tree to ObjectNode:

return (ObjectNode) objectMapper.readTree(json);

When json is empty or blank, ObjectMapper.readTree(...) returns a MissingNode (not an ObjectNode), so the cast throws ClassCastException: class ...MissingNode cannot be cast to class ...ObjectNode.

fixes #49322

All SDK Contribution checklist:

  • The pull request does not introduce [breaking changes]
  • CHANGELOG is updated for new features, bug fixes or other significant changes.
  • I have read the contribution guidelines.

General Guidelines and Best Practices

  • Title of the pull request is clear and informative.
  • There are a small number of commits, each of which have an informative message. This means that previously merged commits do not appear in the history of the PR. For more information on cleaning up the commits in your PR, see this page.

Testing Guidelines

  • Pull request includes test coverage for the included changes.

Copilot AI review requested due to automatic review settings May 29, 2026 23:56
@marcellustavares marcellustavares requested review from a team and kirankumarkolli as code owners May 29, 2026 23:56
@github-actions github-actions Bot added Community Contribution Community members are working on the issue Cosmos customer-reported Issues that are reported by GitHub users external to the Azure organization. labels May 29, 2026
@github-actions
Copy link
Copy Markdown
Contributor

Thank you for your contribution @marcellustavares! We will review the pull request and get back to you soon.

@marcellustavares
Copy link
Copy Markdown
Author

@microsoft-github-policy-service agree company="Elastic"

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

Labels

Community Contribution Community members are working on the issue Cosmos customer-reported Issues that are reported by GitHub users external to the Azure organization.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Cosmos] Fix ClassCastException when building CosmosException from an empty error response body

1 participant