Skip to content

Null pointer exception thrown when calling floorKey method on BTreeMap with a key greater than the highest key stored in the Map #85

vimil opened this Issue Jun 21, 2012 · 1 comment

2 participants

vimil commented Jun 21, 2012

A null pointer exception is thrown when getFloorKey method of BTreeMap is called with a key that is greater than the highest key stored in the BTreeMap. the stacktrace and testcase are as follows.

public static void main(String[] args) {
    TreeMap<Long, String> treeMap = new TreeMap<Long, String>();
    treeMap.put(1L, "hello");
    System.out.println(treeMap.floorKey(2L)); // No exception thrown by TreeMap prints 1

    DB testDB = DBMaker.openFile("D:/temp/testData").disableTransactions().setMRUCacheSize(10000).make();
    NavigableMap<Long, String> testMap = testDB.<Long, String> createTreeMap("testMap");
    testMap.put(1L, "hello");
    System.out.println(testMap.floorKey(2L)); // throws Nullpointer exception, Stack trace is as follwos

Exception in thread "main" java.lang.NullPointerException
at org.apache.jdbm.Utils$
at org.apache.jdbm.Utils$
at org.apache.jdbm.BTreeMap.floorKey(
at MappedFileBufferTest.main(

vimil commented Jul 14, 2012

Patch to fix the issue

diff --git a/src/main/java/org/apache/jdbm/ b/src/main/java/org/apache/jdbm/
index de374bb..cb06352 100644
--- a/src/main/java/org/apache/jdbm/
+++ b/src/main/java/org/apache/jdbm/
@@ -47,7 +47,7 @@
static final Comparator COMPARABLE_COMPARATOR = new Comparator() {
public int compare(Comparable o1, Comparable o2) {

  • return o1.compareTo(o2);
  • return o1 == null && o2 != null ? -1 : (o1 != null && o2 == null ? 1 : o1.compareTo(o2)); } };
@jankotek jankotek added a commit that referenced this issue Aug 21, 2012
@jankotek Fix NPE in issue #85 f7de667
@jankotek jankotek closed this Aug 21, 2012
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.