Hi Dirk,
after some investigation, I found put, that we cannot really do a lot about this case. You have a highly recursive structure. The XML lokks like (after using aliases for Item and ItemCategory and removing the irrelevant Date member):
"<item>\n" +
" <name>testItem</name>\n" +
" <itemCategorySet>\n" +
" <item-category>\n" +
" <item reference=\"../../..\"/>\n" +
" <category>\n" +
" <name>testCategory</name>\n" +
" <itemCategorySet>\n" +
" <item-category reference=\"../../..\"/>\n" +
" </itemCategorySet>\n" +
" </category>\n" +
" <name>testItemCategory</name>\n" +
" </item-category>\n" +
" </itemCategorySet>\n" +
"</item>";
XStream writes the field in the declaration order and must therefore initialize them in the same sequence. All your object have back-references (see the "reference" attributes). In your case the ItemCategory is added to the itemCategorySet of the Category, although the ItemCategory itself is not yet fully initialized. Unfortunately the HashSet implementation will use the object's hashCode() to add the element to its collection and your hashCode implementation makes usage of the not yet initialized "name" member in the ItemCatergory.
So you must indeed either declare the "name" field in the ItemCategory before the field "category" or you must use a collection implementation, that will not call any method, that uses the uninitialized members.
Hi Dirk,
I cannot reproduce this. Personally I think it is a follow-up for
XSTR-285. Can you verify this with the latest snapshot?