Error while using putAll on a previously deleted collection #73

Closed
ghost opened this Issue Apr 25, 2012 · 3 comments

Projects

None yet

1 participant

@ghost
ghost commented Apr 25, 2012

Hi,
I have written a test case to show the issue.

package net.kotek.jdbm;

import org.junit.Test;

import java.io.IOException;
import java.util.HashMap;
import java.util.Map;

/**

  • Yoocos Sàrl

  • User: David

  • Date: 25.04.12

  • Time: 12:52
    */
    public class RootIsNullTest {
    public DB db;
    @Test
    public void test() throws IOException {
    db = DBMakerTest.newDBCache();
    Map<String,Object> toAdd = new HashMap<String, Object>() ;
    toAdd.put("description","test");
    toAdd.put("descriptio1","test");

    Map<String,Object> map = db.createHashMap("test");
    map.putAll(toAdd);
    db.commit();
    db.deleteCollection("test");
    map = getOrCreate("test");
    map.putAll(toAdd);
    db.commit();
    

    }

    private Map<String,Object> getOrCreate(String name){
    Map<String,Object> result = db.getHashMap(name);
    return result == null ? db.<String,Object>createHashMap(name) : result;
    }
    }

When you run this test, you get a NullPointerException on line 437 because getRoot returns null.
Do I do something wrong or is it a bug?

Thank you in advance!

@ghost
ghost commented Apr 25, 2012

Ok it seems that when you delete a collection and then you get it, the collection is still returned even though it has been deleted.
It would be good to either having a method collectionExists(name) or that getHashMap(name) returns null if it has been deleted.

@ghost
ghost commented Apr 26, 2012

I found a way to remove this bug but I am not sure this is a good idea since I don't know JDBM's mechanics well enough.

What I did was simply to remove from the HashMap collections the collection I am deleting.
I added to the method deleteCollection(String name) the line collections.remove(name); at the end.

Please let me know if you think this fix is enough or is the issue more complexe than that ?

@jankotek
Owner

Fixed, old instance was cached using weak reference

@jankotek jankotek closed this Apr 29, 2012
@jankotek jankotek pushed a commit that referenced this issue Apr 29, 2012
@dan-g dan-g Fixed issue #73 10538e6
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment