#91 Lost and Duplicated Objects

closed
None
5
2007-05-21
2007-05-09
No

When mapping many objects (with one recursion), some can get lost and others duplicated.
This arises from the use of system.identityHashCode for identifying already mapped fields. (Bugfix 1596766)
This Hashcode is not unique, see
http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=6321873

The attached files demonstrate the issue with an array of 20000 beans where 5 (in my environment) are lost after the mapping because they have identical hascodes to already mapped ones.

Perhaps you should use a HashSet for remembering the already mapped fields:

MappingProcessor.java
line 97:
private final Set mappedFields = new HashSet();

line 204:
mappedFields.add(sourceObj);

line 408:
// 1596766 - Recursive object mapping issue. Prevent recursive mapping infinite loop
if (mappedFields.contains(sourceFieldValue)) {
if (sourceFieldValue.getClass().equals(destFieldType)) {
// Source value has already been mapped to the required destFieldType.
return sourceFieldValue;
}

// 1658168 - Recursive mapping issue for interfaces
if (destFieldType.isInterface() && destFieldType.isAssignableFrom(sourceFieldValue.getClass())) {
// Source value has already been mapped to the required destFieldType.
return sourceFieldValue;
}
}

Please check if this works or find another solution.

Discussion

  • Joachim Korittky

    Logged In: YES
    user_id=1788058
    Originator: YES

    Oh, I was too fast without thingking enough.
    My suggestion with HashSet is nonsense, but using the source object as key for mappefFields should work (but prevent the source objects from being garbage collected).

     
  • Matt Tierney

    Matt Tierney - 2007-05-10

    Logged In: YES
    user_id=1236069
    Originator: NO

    Thanks for submitting this bug and the excellent test case. I have added the test case to the src and was able to reproduce the issue. I will work on fixing this and do the best I can to get this in the next release.

    FYI.....

    I quickly tried to apply your suggest patch and it resolved your test case. But it broke an existing test for infinite loop mappings. Any ideas on what the best solution to this issue would be?

     
  • Matt Tierney

    Matt Tierney - 2007-05-11
    • assigned_to: nobody --> mhtierney
    • status: open --> pending
     
  • Matt Tierney

    Matt Tierney - 2007-05-11

    Logged In: YES
    user_id=1236069
    Originator: NO

    The patch has been applied to the 3.4 code base. The underlying implementation to prevent infinite loops for bi-directional mappings was modified to resolve this issue. Thanks!

     
  • Franz Garsombke

    Franz Garsombke - 2007-05-21
    • status: pending --> closed
     

Log in to post a comment.

Get latest updates about Open Source Projects, Conferences and News.

Sign up for the SourceForge newsletter:





No, thanks