Hello again, After some further investigation, I could make a guess : does the problem comes from the fact that in the HashMap#rehash() method the keys list is not cleared ?
What do you think ? Simon On Fri, Mar 25, 2011 at 11:59 AM, Simon Chatelain <[email protected]>wrote: > Hello, > > I observed a really weird behavior when using a Pivot Map with a > comparator. By executing the code bellow, we can see that from 0 to 12 the > l_KeyCount == l_Map.getCount(). But when adding the 13th element in the map > the l_KeyCount become 26 when the l_Map.getCount() == 13. Then if I remove > one of the entry of the Map, the iterator on the map's key still return the > key corresponding to the removed entry, but the l_Map.containsKey() return > false. > > If I do not set a comparator on the map, I do not have this problem. > > I looked in the user mailing list for similar issue, but didn't find > anything. > > Sounds like a bug to me or am I missing something ? > > Simon > > Map<Integer, String> l_Map = new HashMap<Integer, String>(); > l_Map.setComparator(new Comparator<Integer>() { > > @Override > public int compare(Integer _arg0, Integer _arg1) { > return _arg0.compareTo(_arg1); > } > }); > > for (int i = 0; i < 100; i++) { > l_Map.put(i, UUID.randomUUID().toString()); > > int l_KeyCount = 0; > for (Integer l_Key : l_Map) { > l_KeyCount++; > } > if (l_KeyCount != l_Map.getCount()) { > Logger.getLogger(this.getClass().getName()).log(Level.INFO, > "l_KeyCount should be {0} but is {1}", > new Object[] { l_Map.getCount(), l_KeyCount }); > l_Map.remove(0); > } > for (Integer l_Key : l_Map) { > if (!l_Map.containsKey(l_Key)) { > Logger.getLogger(this.getClass().getName()).log(Level.INFO, > "WTF : {0}", > new Object[] { l_Key.toString()}); > } > } > } >
