kostaskougios / cloning

deep clone java objects
Other
591 stars 112 forks source link

Added FastClonerEnumMap and FastClonerLinkedHashSet #95

Closed tweimer closed 4 years ago

tweimer commented 4 years ago

Hi Konstantinos, I am using your Cloning library, and I found a bug with cloning of EnumMaps. If any key of an EnumMap is being mapped to null, the cloned EnumMap will not map it to null, but to a random instance of Object.

I tracked down that problem and the cause of the problem is that EnumMap is using a marker object java.util.EnumMap.NULL to distinguish enums mapped to null from objects not contained in the map at all. java.util.EnumMap.NULL is used in maskNull and unmaskNull by reference comparision, so after NULL is cloned, the reference comparision goes wrong.

You are able to reproduce that problem with the JUnit test included in my Pull Request.

In order to solve the problem, I have introduced FastClonerEnumMap. It is basically taken from FastClonerHashMap, with some modification for EnumMap. It is registered in com.rits.cloning.Cloner.registerFastCloners().

After that, the JUnit tests I added are working fine. Feel free to add additional ones.

I also added FastClonerLinkedhashSet, which will fix #46 (JUnit tests are included too).

I also updated pom.xml (fixes #66)

I hope you will merge this PR. If you have any objections, please let me know!

tweimer commented 4 years ago

Hi Tobias, thanks for the changes. My review comments follows. Please let me know if you want to change anything or you're happy for your code to be merged.

Thamks. I fixed/added all your remarks and added even more JUnit. :) Ready to be merged!

tweimer commented 4 years ago

Thank you! Could you make a new release soon? I really need that fix and I wouldn't want to use my own workaround.

kostaskougios commented 4 years ago

Hi, just deployed 1.10.2 with the fixes