pkt1583 / google-collections

Automatically exported from code.google.com/p/google-collections
Apache License 2.0
0 stars 0 forks source link

TreeMultimap returns wrong sizes and items after tailSet().clear() #258

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
google-collections: version 1.0-RC2
JRE: sun-jdk-1.5.0.18 (compiled also as java 1.5)
Linux 2.6.28-gentoo-r5 #1 SMP Mon Jun 1 17:08:13 EEST 2009 i686 Intel(R)
Core(TM)2 Duo CPU E4400 @ 2.00GHz GenuineIntel GNU/Linux

After filling up a TreeMultimap with certain data and invoking 
  tailSet().clear()  
the multimap ends up with conflicting sizes and containing-items.

The bug seems to appear only under specific entry items and tail-split
argument.

The following code (also attached as test-case) produces this erroneous output:
------------------
Entries: mm({1=[s], 3=[s], 4=[s]}), keys([1, 3, 4]), keysSet([1, 3, 4]),
values([s, s, s])
Sizes: mm(4), keys(4), keysSet(3), values(4)
------------------

void treeMultimapTailTest() {
        TreeMultimap<Integer, String> mm = TreeMultimap.create();
        String s = "s";
        mm.put(1, s);
        //mm.put(2, s); // Uncomment, and bug disappears.
        mm.put(3, s);
        mm.put(4, s);
        mm.put(5, s);
        mm.put(6, s); // If last 2 commented, bug disappears.

        mm.keySet().tailSet(5).clear();

        System.out.println(String.format("Entries: mm(%s), keys(%s),
keysSet(%s), values(%s)", mm, mm.keys(), mm.keySet(), mm.values()));        
        System.out.println(String.format("Sizes: mm(%s), keys(%s),
keysSet(%s), values(%s)", mm.size(), mm.keys().size(), mm.keySet().size(),
mm.values().size()));
        int i = 0;
        for(String v: mm.values())
            i++;
        assert i == mm.size();
    }

Original issue reported on code.google.com by ankos...@gmail.com on 16 Oct 2009 at 6:30

Attachments:

GoogleCodeExporter commented 9 years ago
It looks like you found a real bug. Thanks for reporting it.

Original comment by jared.l....@gmail.com on 16 Oct 2009 at 8:37

GoogleCodeExporter commented 9 years ago

Original comment by kevin...@gmail.com on 16 Oct 2009 at 9:06

GoogleCodeExporter commented 9 years ago
The problem was that the code accessed a Map.Entry after it was removed from a 
Map.
That led to erratic behavior.

The fix will be in the next release (RC4).

Original comment by jared.l....@gmail.com on 17 Oct 2009 at 12:47

GoogleCodeExporter commented 9 years ago
> It looks like you found a real bug. Thanks for reporting it.

It's been my pleasure.
(may i get this google-wave invitation now?)

Original comment by ankos...@gmail.com on 17 Oct 2009 at 1:15

GoogleCodeExporter commented 9 years ago
Would it be possible to have this fix pushed into source repository?

Original comment by ankos...@gmail.com on 20 Oct 2009 at 2:58

GoogleCodeExporter commented 9 years ago
Yes, I'm planning to try pushing code updates more frequently even when not 
building
a new rc.

Original comment by kevin...@gmail.com on 20 Oct 2009 at 3:06

GoogleCodeExporter commented 9 years ago
Thank you, keep up the excellent work!

Original comment by ankos...@gmail.com on 20 Oct 2009 at 3:24