chesnokoff commented on code in PR #12917:
URL: https://github.com/apache/ignite/pull/12917#discussion_r2986166987
##########
modules/core/src/main/java/org/apache/ignite/internal/direct/stream/DirectByteBufferStream.java:
##########
Review Comment:
### Details of bug
Let’s assume we want to serialize a message that has a field of type
`Map<Integer, Map<Integer, Long>>` (see the `nestedMap` field in
`TestNestedContainersMessage` in this PR as an example).
The message serializer uses `DirectMessageWriter#writeMap` ->
`DirectBufferStream#writeMap` to write the map and stores its iterator
(`mapIt`).
After that, it calls `write(type.valueType(), e.getValue(), writer)` to
write the nested `Map<Integer, Long>`, which leads to:
```
case MAP:
writeMap((Map<K, V>)val, (MessageMapType)type, writer);
```
So we enter `DirectBufferStream#writeMap` again. However, `mapIt` is already
not null and still points to the iterator of the top-level map, not the nested
one.
As a result, instead of writing the nested map, the code continues iterating
over the top-level map and writes the wrong data.
### Root cause
We need to use a new stream for each nested container. This is already
implemented for message (`MSG`) types:
`writer.beforeInnerMessageWrite` creates a new level in the stack with a new
stream.
So we need to apply the same approach for nested containers.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]