Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

MappingRedisConverter.writeCollection breaks on NULL values and missing next elements [DATAREDIS-1076] #1648

Open
spring-projects-issues opened this issue Dec 9, 2019 · 0 comments
Assignees
Labels
in: core type: bug

Comments

@spring-projects-issues
Copy link

@spring-projects-issues spring-projects-issues commented Dec 9, 2019

binakot opened DATAREDIS-1076 and commented

Good day!

I'm using spring-data-redis to store some collections with nullable elements. There are cases when some elements may be null. I was surpriced when I found a losing of ending elements in my collections.

I did a search the reason, and I found it: 2492fbe#diff-b71f4f4366952781ed005f6224ff7d5dR511

This break is still in the project https://github.com/spring-projects/spring-data-redis/blob/master/src/main/java/org/springframework/data/redis/core/convert/MappingRedisConverter.java#L705

Why is it required to break the writing elements on the first null in MappingRedisConverter.writeCollection? And why it didn't required before this commit 2492fbe#diff-b71f4f4366952781ed005f6224ff7d5dR511?

I made a project with sample of the problem with different cases: leading/ending nulls and null in a middle of collections. https://github.com/binakot/spring-data-redis-null-elements/blob/master/src/test/java/com/baeldung/spring/data/redis/repo/NullableCollectionRepositoryIntegrationTest.java#L51

I'm using spring-boot version 1.5.22.RELEASE in my application, but this behaviour is repeatable with version 2.1.9.RELEASE

 

Redis stores the elements in separate values this way:

java:

Integer[] collection = {1,2,3,4,5};

redis:

collection.[0]: 1

collection.[1]: 2

collection.[2]: 3

collection.[3]: 4

collection.[4]: 5

 

When some element is null, Redis just skips the elements:

java:

Integer[] collection = {1,2,3,null,null};

redis:

collection.[0]: 1

collection.[1]: 2

collection.[2]: 3

 

But when nulls are not in the end:

java:

Integer[] collection = {1,2,null,4,5};

redis:

collection.[0]: 1

collection.[1]: 2

... lost 4 and 5

 

I'm using array, that's why I get null elements, if Redis cannot find value with certain index. And it's a behaviour which I excpect. At this moment I'm losing any values after the first null in an array. Behaviour of List and Array are similar, here is same tests for array of Integers https://github.com/binakot/spring-data-redis-null-elements/blob/master/src/test/java/com/baeldung/spring/data/redis/repo/NullableArrayRepositoryIntegrationTest.java#L50

 

What can I do? I cannot use some pseudo-null like Integer.MIN_VALUE or smth else.

 


Affects: 2.2.3 (Moore SR3)

Reference URL: https://github.com/binakot/spring-data-redis-null-elements/blob/master/src/test/java/com/baeldung/spring/data/redis/repo/NullableCollectionRepositoryIntegrationTest.java#L50

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
in: core type: bug
Projects
None yet
Development

No branches or pull requests

2 participants