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

Issue with custom Serialization #7

Closed
Toilal opened this issue Feb 15, 2012 · 3 comments
Closed

Issue with custom Serialization #7

Toilal opened this issue Feb 15, 2012 · 3 comments

Comments

@Toilal
Copy link
Contributor

Toilal commented Feb 15, 2012

Some beans with many null values fields can't be deserialized by JDBM.

@see http://pastebin.com/RuXFsxD1 (Bean with some null values fields)
@see http://pastebin.com/v7LAaKCR (Unit test, crashing on second execution when database already exists)

@Toilal
Copy link
Contributor Author

Toilal commented Feb 15, 2012

Here is the trace

java.lang.Error: Could not instanciate class
at net.kotek.jdbm.SerialClassInfo.readObject(SerialClassInfo.java:312)
at net.kotek.jdbm.Serialization.deserialize(Serialization.java:881)
at net.kotek.jdbm.Serialization.deserialize(Serialization.java:597)
at net.kotek.jdbm.BTreeLazyRecord.fastDeser(BTreeLazyRecord.java:69)
at net.kotek.jdbm.HTreeBucket.readExternal(HTreeBucket.java:340)
at net.kotek.jdbm.HTree$1.deserialize(HTree.java:41)
at net.kotek.jdbm.DBStore.fetch2(DBStore.java:378)
at net.kotek.jdbm.DBStore.fetch(DBStore.java:348)
at net.kotek.jdbm.DBCache.fetch(DBCache.java:278)
at net.kotek.jdbm.HTreeDirectory.get(HTreeDirectory.java:148)
at net.kotek.jdbm.HTree.get(HTree.java:183)
at net.kotek.jdbm.HTree.put(HTree.java:161)
at JDBMSerializationTest.test2(JDBMSerializationTest.java:72)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:44)
at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:15)
at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:41)
at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:20)
at org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:28)
at org.junit.internal.runners.statements.RunAfters.evaluate(RunAfters.java:31)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:73)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:46)
at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:180)
at org.junit.runners.ParentRunner.access$000(ParentRunner.java:41)
at org.junit.runners.ParentRunner$1.evaluate(ParentRunner.java:173)
at org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:28)
at org.junit.internal.runners.statements.RunAfters.evaluate(RunAfters.java:31)
at org.junit.runners.ParentRunner.run(ParentRunner.java:220)
at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:50)
at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:467)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:683)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:390)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:197)
Caused by: java.lang.IndexOutOfBoundsException
at net.kotek.jdbm.Serialization$FastArrayList.get(Serialization.java:1234)
at net.kotek.jdbm.Serialization.deserialize(Serialization.java:884)
at net.kotek.jdbm.SerialClassInfo.readObject(SerialClassInfo.java:307)
... 36 more

@Toilal
Copy link
Contributor Author

Toilal commented Feb 15, 2012

I have fixed the problem, see below.

In file Serialization.java, on line 606 :

    /** first try to deserialize object without allocating object stack*/
    switch (head) {
        case NULL:
            return null;

the NULL case should be replaced by a break :

    /** first try to deserialize object without allocating object stack*/
    switch (head) {
        case NULL:
            break;

Then on line 868 :

    if (ret != null) {
        if (objectStack != null)
            objectStack.add(ret);
        return ret;
    }

should be replaced by:

    if (ret != null || head == NULL) {
        if (objectStack != null)
            objectStack.add(ret);
        return ret;
    }

@jankotek
Copy link
Owner

I used your fix, thanks

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