Skip to content

Conversation

@sadeghpour
Copy link

@sadeghpour sadeghpour commented Mar 4, 2025

  • Added null checks for HitsMetadata in SearchResponse<T>.Documents
  • Ensured HitsMetadata and Hits are properly validated before accessing them
  • Prevented potential crashes when the response contains no hits

Closes #8340

@cla-checker-service
Copy link

cla-checker-service bot commented Mar 4, 2025

💚 CLA has been signed

@sadeghpour
Copy link
Author

Hi team, I have signed the CLA, but the check still seems to be failing. Could you please verify? Let me know if I need to take any further action. Thanks!

@pquentin
Copy link
Member

pquentin commented Mar 4, 2025

Hello, and thank you for your contribution! I have no idea about the code itself. I can confirm that you signed the CLA check correctly, but the issue is that your commit does not use an email address. See https://github.com/elastic/elasticsearch-net/commit/4a91b26f1095bd82681c825b441960f2dba0df07.patch.

- Added null checks for `HitsMetadata` in `SearchResponse<T>.Documents`
- Ensured `HitsMetadata` and `Hits` are properly validated before accessing them
- Prevented potential crashes when the response contains no hits
@flobernd
Copy link
Member

flobernd commented Mar 4, 2025

Thanks for the PR @sadeghpour !

Besides this fix, I would like to investigate the case a little bit more in depth. Would it be possible for you to send me the JSON request and response that triggers this behavior?

In our specification, both, ResponseBody<TDocument>.hits (this is HitsMetadata in the .NET client) and HitsMetadata<T>.hits are not marked as optional. I wonder if this should be changed cc @pquentin @l-trotta

@l-trotta
Copy link

l-trotta commented Mar 4, 2025

@flobernd never found any evidence that hits could be null, is there a special case where it happens?

@sadeghpour
Copy link
Author

@l-trotta You are right! After further investigation following @flobernd previous comment, I also couldn't find any evidence that hits could be null. It seems there's no special case where this happens.

@flobernd flobernd closed this Mar 16, 2025
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.

SearchResponse.Documents throws null reference exception on successful call

4 participants