tonellotto / jdbm2

Automatically exported from code.google.com/p/jdbm2
0 stars 0 forks source link

HTreeMap.clear() fails on maps with ConcurrentModificationException #2

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
Run the following test class:

    public static void main(final String[] args) throws IOException {
        final RecordManager recman = RecordManagerFactory.createRecordManager("d:/temp/jdbm-db/db1");
        final HTree tree = HTree.createInstance(recman);
        recman.setNamedObject("test", tree.getRecid());
        final HTreeMap<String,String> treeMap = tree.asMap();

        for (int i = 0; i < 100; i++) {
            treeMap.put(String.valueOf(i),String.valueOf(i));
        }
        recman.commit();
        System.out.println("finished adding");

        treeMap.clear();
        recman.commit();
        System.out.println("finished clearing");
    }

It fails with:

Exception in thread "main" java.util.ConcurrentModificationException
    at java.util.AbstractList$Itr.checkForComodification(AbstractList.java:372)
    at java.util.AbstractList$Itr.next(AbstractList.java:343)
    at jdbm.htree.HashDirectory$HDIterator.next2(HashDirectory.java:480)
    at jdbm.htree.HashDirectory$HDIterator.next(HashDirectory.java:565)
    at jdbm.htree.HTreeMap$1$2.ensureNext(HTreeMap.java:98)
    at jdbm.htree.HTreeMap$1$2.next(HTreeMap.java:122)
    at jdbm.htree.HTreeMap$1$2.next(HTreeMap.java:91)
    at java.util.AbstractCollection.clear(AbstractCollection.java:395)
    at java.util.AbstractMap.clear(AbstractMap.java:271)
    at LocalTester.main(LocalTester.java:43)

Oddly enough, it works if the iterator is 100.

Original issue reported on code.google.com by jrivard on 7 Jan 2011 at 3:36

GoogleCodeExporter commented 9 years ago
Issue fixed with commit r63 http://code.google.com/p/jdbm2/source/detail?r=63

New should be in a week.

Original comment by kja...@gmail.com on 22 Jan 2011 at 5:26