Chronicle-Map icon indicating copy to clipboard operation
Chronicle-Map copied to clipboard

size of ObjectOutputStream is not equal when two Maps are equal

Open mores opened this issue 2 years ago • 2 comments

In my use case my Map will contain a Map for both keys and values.

I have run into a weird case where I found two maps that are equal but the size of ObjectOutputStream are not. ( Which ChronicleMap uses under the covers ).

When using a java.util.HashMap my use case works as expected. When I substitute in ChronicleMap, my use case no longer works.

Here is a link to the code that shows the issue: https://github.com/mores/maven-examples/blob/ac6012ca1236ad460f3b3767037531fdb2e3dffd/offHeapMap/src/test/java/org/test/MapTest.java#L76

I am able to reproduce this bug on ubuntu using both 1.8.0_161 and 11.0.17

mores avatar Dec 24 '22 13:12 mores

Such is the limitation of ObjectOutputStream mechanism of the JVM - it will write repeating objects by handle. There is an unshared mechanism that could override that, but even if it was used it will break down on recursive data structures.

You can specify your own readers / data access for such maps of maps, by using ChronicleMapBuilder.keyReaderAndDataAccess().

alamar avatar Dec 26 '22 08:12 alamar

If that is the default behavior, should ChronicleMap throw an exception when a Map is used as a key..... "keyReaderAndDataAccess is required when using a Map as a key"

mores avatar Dec 26 '22 12:12 mores