Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

deserialization of HashSet fails #99

Open
tseytlin opened this issue Nov 20, 2012 · 2 comments
Open

deserialization of HashSet fails #99

tseytlin opened this issue Nov 20, 2012 · 2 comments

Comments

@tseytlin
Copy link

I have a program that uses the original JDBM and I am trying to port it to JDBM3.
My use case is to use String as a key and either HashSet of Strings or a custom Java object as a value.

When I substitute JDBM3 code I get an error related to object serealiation
Exception in thread "Thread-0" java.lang.InternalError: Unknown serialization header: 97
at org.apache.jdbm.Serialization.deserialize(Serialization.java:962)
at org.apache.jdbm.Serialization.deserializeArrayList(Serialization.java:1136)
at org.apache.jdbm.Serialization.deserialize(Serialization.java:919)
at org.apache.jdbm.Serialization.deserialize(Serialization.java:623)
at org.apache.jdbm.DBStore.fetch2(DBStore.java:400)
at org.apache.jdbm.DBStore.fetch(DBStore.java:366)
at org.apache.jdbm.DBCacheRef.fetch(DBCacheRef.java:213)
at org.apache.jdbm.BTreeLazyRecord.get(BTreeLazyRecord.java:28)
at org.apache.jdbm.HTreeBucket.getValue(HTreeBucket.java:219)
at org.apache.jdbm.HTreeDirectory.get(HTreeDirectory.java:160)
at org.apache.jdbm.HTree.get(HTree.java:199)
at org.apache.jdbm.HTree.containsKey(HTree.java:248)
at edu.pitt.terminology.util.JDBMMap.containsKey(JDBMMap.java:83)

Which looks like it is trying to deserealize HashSet as an ArrayList.

Here is my initialization code:

// init record manager
    DBMaker d = DBMaker.openFile(filename);
    // set options
    d.disableTransactions();
    d.closeOnExit();
    d.enableHardCache();
    d.disableLocking();

    db = d.make();

    // create or load hashtable from given file
    map = db.getTreeMap(tablename);
    if(map == null)
        map = db.createTreeMap(tablename);

Here is where I invoke a wrapper function
Set termList = new HashSet(filterTerms(word,terms));
if(wordMap.containsKey(word)){
termList.addAll(getWordTerms(word));
}
wordsMap.put(word,termList);

It fails on containsKey() line, however I have a hunch that the issue is with serializing HashSet incorrectly.

@tseytlin
Copy link
Author

Sorry for the post. I resolved this issue. It had to do with me wanting to use the same file for multiple tables, like I did it in JDBM v1. Once each table got its own file, it worked.

I did encounter issues though with serializing Objects that contained arrays of String. When I switched arrays to Lists it worked.

@jankotek
Copy link
Owner

I like problems which solve themselves :-)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants