Skip to content

Conversation

SylvainAssemat
Copy link

@SylvainAssemat SylvainAssemat commented Aug 6, 2025

Fixes #639

Hotfix to solve this exeception on count() method in SearchStreamImpl.java

java.lang.ClassCastException: class java.lang.String cannot be cast to class java.lang.Long (java.lang.String and java.lang.Long are in module java.base of loader 'bootstrap')
	at com.redis.om.spring.search.stream.SearchStreamImpl.count(SearchStreamImpl.java:499)
SearchStreamImpl.java:499

@bsbodden
Copy link
Collaborator

bsbodden commented Aug 9, 2025

@SylvainAssemat Thanks for the contribution. Unfortunately, I had already fixed it in the release 1.0.0 PR - it was broken in many places, so I wrote a helper function to deal with it. But please keep them coming! 🙏🏽

@bsbodden bsbodden closed this Aug 9, 2025
bsbodden added a commit to bsbodden/redis-om-spring that referenced this pull request Aug 9, 2025
Fix ClassCastException when retrieving document count from Redis index info.
Redis can return num_docs as either String or Long depending on version/config.

Applied robust type checking to all occurrences:
- RedisJSONKeyValueAdapter.count()
- RedisEnhancedKeyValueAdapter.count()
- RedisFluentQueryByExample (already fixed in SearchStreamImpl)

The fix handles:
- String values: parse to Long
- Number values: convert to long
- Null/unexpected: return 0L safely

This is more robust than PR redis#640's approach as it:
- Handles multiple Redis return types
- Avoids NullPointerException
- Prevents unnecessary String conversions
- Provides safe fallback for unexpected types
bsbodden added a commit that referenced this pull request Aug 9, 2025
Fix ClassCastException when retrieving document count from Redis index info.
Redis can return num_docs as either String or Long depending on version/config.

Applied robust type checking to all occurrences:
- RedisJSONKeyValueAdapter.count()
- RedisEnhancedKeyValueAdapter.count()
- RedisFluentQueryByExample (already fixed in SearchStreamImpl)

The fix handles:
- String values: parse to Long
- Number values: convert to long
- Null/unexpected: return 0L safely

This is more robust than PR #640's approach as it:
- Handles multiple Redis return types
- Avoids NullPointerException
- Prevents unnecessary String conversions
- Provides safe fallback for unexpected types
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.

COUNT Query - 1.0.0-RC4
2 participants