From: SourceForge.net <no...@so...> - 2007-02-15 14:57:55
|
Bugs item #1501213, was opened at 2006-06-05 22:23 Message generated for change (Comment added) made by lheuer You can respond by visiting: https://sourceforge.net/tracker/?func=detail&atid=391879&aid=1501213&group_id=27895 Please note that this message will contain a full copy of the comment thread, including the initial issue submission, for this request, not just the latest update. Category: In-Memory Impl Group: CVS >Status: Closed Resolution: None Priority: 5 Private: No Submitted By: Xuan Baldauf (mediumnet) Assigned to: Nobody/Anonymous (nobody) Summary: MemberImpl.hashCode() is not consistent with equals() Initial Comment: When the constructor org.tm4j.topicmap.memory.MemberImpl( AssociationImpl parent, String id, Locator resourceLoc, Topic roleSpec, Collection players) is used, the to-be-constructed MemberImpl adds itself to each m_rolesPlayed field of every TopicImpl of the players collection. This field is a HashSet, and thus, hashCode() of the MemberImpl object is called. The method hashCode() (defined in org.tm4j.topicmap.memory.TopicMapObjectImpl) itself depends on the id of the MemberImpl object. However, the id is currently set ("setID(id);") _after_ the to-be-constructed MemberImpl adds itself to each m_rolesPlayed field of every TopicImpl of the players collection. Thus, hashCode() returns different values at different times (with a very high probability). In particular, hashCode() returns a different value before the call to setID(id) than after the call to setID(id). This, in turn, makes the call "m_rolesPlayed.contains(member)" in org.tm4j.topicmap.memory.TopicImpl.removeRolePlayed(Member member) return false, while it should return true. >From this on, the topic map data structure is inconsistent (and messed up). ---------------------------------------------------------------------- >Comment By: Lars Heuer (lheuer) Date: 2007-02-15 15:57 Message: Logged In: YES user_id=399396 Originator: NO Fixed in CVS. Thanks ---------------------------------------------------------------------- Comment By: Xuan Baldauf (mediumnet) Date: 2006-06-05 22:25 Message: Logged In: YES user_id=506885 This patch should fix the problem: Index: tm4j/src/org/tm4j/topicmap/memory/MemberImpl.java =================================================================== RCS file: /cvsroot/tm4j/tm4j/src/org/tm4j/topicmap/memory/MemberImpl.java,v retrieving revision 1.24 diff -u -r1.24 MemberImpl.java --- tm4j/src/org/tm4j/topicmap/memory/MemberImpl.java 7 Mar 2006 15:36:35 -0000 1.24 +++ tm4j/src/org/tm4j/topicmap/memory/MemberImpl.java 5 Jun 2006 20:08:49 -0000 @@ -56,14 +56,14 @@ m_roleSpec = roleSpec; m_players = new ArrayList(players); + if (resourceLoc != null) addSourceLocator(resourceLoc); + setID(id); for (Iterator it = m_players.iterator(); it.hasNext();) { TopicImpl t = (TopicImpl) it.next(); // TODO: Avoid the access of the Topic.m_rolesPlayed field t.m_rolesPlayed.add(this); } - if (resourceLoc != null) addSourceLocator(resourceLoc); - setID(id); parent.addMember(this); } ---------------------------------------------------------------------- You can respond by visiting: https://sourceforge.net/tracker/?func=detail&atid=391879&aid=1501213&group_id=27895 |