Tmr / h2database

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

[MVStore] When the param 'key' is null,MVMap.getMinMax does not return the correct value #460

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
H2 Version: svn trunk

Test:
==========================================
import org.h2.mvstore.MVMap;
import org.h2.mvstore.MVStore;
import org.junit.Assert;
import org.junit.Test;

public class TestGetMinMax {
    @Test
    public void testGetMinMax() throws Exception {
        MVStore store = MVStore.open(null);
        store.setPageSize(512);

        MVMap<Integer, String> map = store.openMap("MVMapTest");

        int n = 100;
        for (int i = 1; i <= n; i++) {
            map.put(i, "" + i);
        }

        Integer key = 3;

        Assert.assertEquals(4, map.higherKey(key).intValue()); //ok
        Assert.assertEquals(3, map.ceilingKey(key).intValue()); //ok

        Assert.assertEquals(2, map.lowerKey(key).intValue()); //ok
        Assert.assertEquals(3, map.floorKey(key).intValue()); //ok

        key = null;

        Assert.assertEquals(100, map.higherKey(key).intValue()); //failed
        Assert.assertEquals(100, map.ceilingKey(key).intValue()); //failed

        Assert.assertEquals(1, map.lowerKey(key).intValue()); //ok
        Assert.assertEquals(1, map.floorKey(key).intValue()); //ok
    }
}

Original issue reported on code.google.com by zhh200...@gmail.com on 12 May 2013 at 4:24

GoogleCodeExporter commented 9 years ago
Hi,

Thanks! There was an obvious problem with null handling, and I changed it (not 
yet committed): null is the lowest key. However, null key handling is not quite 
clear and consistent. I would like a solution that is consistent and doesn't 
require null checks everywhere, but it's not so easy. Right now, I will just 
make it work (so that null is the lowest possible key).

Regards,
Thomas

Original comment by thomas.t...@gmail.com on 14 May 2013 at 7:37

GoogleCodeExporter commented 9 years ago
Fixed in version 1.3.172.

Original comment by thomas.t...@gmail.com on 25 May 2013 at 1:48