|Re: [jgit-dev] fixing bug 321502 - lost in polymorphia|
On Fri, Aug 13, 2010 at 9:05 AM, Matthias Sohn <matthias.sohn@xxxxxxxxxxxxxx> wrote: > http://egit.eclipse.org/r/#change,1299 doesn't fix bug 321502 > (Shawn happened to accept the change when I concurrently tried to vote -1). Well, to be fair the change was still reasonable cleanup. It just didn't fix the bug like we expected it would. :-( > We found this doesn't work since looking up the list of Refs to be shown in > the > history view implemented in PlotWalk.getTags(AnyObjectId) fails. We found > that > the failing hashmap lookup ends up calling RevObject.equals() which does a > pointer comparison obviously failing to match the SWTCommit passed into > PlotWalk.getTags(AnyObjectId) with the keys of the hashmap returned by > Repository.getAllRefsByPeeledObjectId(). > > Any hints how to fix this ? We are lost in polymorphia ... Ooooh. This is a common problem for us. The objects coming back from Repository are straight-up ObjectId, but the HashMap is using the key that is passed to get() to implement equals(), which means the overridden equals() from RevObject wins here. Three solutions: 1) When looking up an object in the map, use .copy() to convert from RevObject to ObjectId. This actually works by allocating a new ObjectId with the same identity. So its somewhat inefficient due to the lookup cost. 2) Use an ObjectIdSubclassMap rather than straight Map for the returned map from the Repository. The ObjectIdSubclassMap knows how to use our own equality function for ObjectId without falling into the trap of the RevObject override of .equals(). 3) We admit that RevObject overridding .equals() is wrong and back out that implementation. -- Shawn.
Back to the top