Skip to content

Fixes for transient NullPointerExceptions #87

Closed
wants to merge 1 commit into from

2 participants

@joval
joval commented Jun 27, 2012

Greetings,

I've started using JDBM in my jOVAL project, and have experienced some NullPointerExceptions that I am guessing must be the result of race conditions because they don't seem to happen very consistently. Anyway, for some reason my diffs look bad on Github, so here are the whitespace-ignoring diffs (below). The change to SerialClassInfo was inadvertent -- I just deleted a blank line after having temporarily inserted a printStackTrace statement.

One comment I would make is that it would be nice if the JDBM maps had the ability to detect when changes are made to a previously inserted object (without having to re-add it), so that changes would be serialized transparently -- in autocommit mode, anyway. This would square its behavior with the in-memory Hashtable class, for instance. This was causing me some grief that took a long time to figure out!

Please let me know if you have any questions or comments.

Best regards,
--David Solin

$ git diff -w 98b794c..
diff --git a/src/main/java/org/apache/jdbm/DBAbstract.java b/src/main/java/org/apache/jdbm/DBAbstract.java
index ca5e1ae..140f0b1 100644
--- a/src/main/java/org/apache/jdbm/DBAbstract.java
+++ b/src/main/java/org/apache/jdbm/DBAbstract.java
@@ -398,6 +398,9 @@ abstract class DBAbstract implements DB {
if(nameDirectory_recid==0)
return ret;
HTree m = fetch(nameDirectory_recid);

  • if (m == null) {
  • return null;
  •       }
    
         for(Map.Entry<String,Long> e:m.entrySet()){
             Object o = fetch(e.getValue());
    

    diff --git a/src/main/java/org/apache/jdbm/HTreeDirectory.java b/src/main/java/org/apache/jdbm/HTreeDirectory.java
    index 50cb20e..e882b4d 100644
    --- a/src/main/java/org/apache/jdbm/HTreeDirectory.java
    +++ b/src/main/java/org/apache/jdbm/HTreeDirectory.java
    @@ -154,6 +154,9 @@ final class HTreeDirectory {
    HTreeDirectory dir = (HTreeDirectory) node;
    dir.setPersistenceContext(child_recid);
    return dir.get(key);

  • } else if (node == null) {
  • putRecid(hash, 0L);
  •           return null;
         } else {
             // node is a bucket
             HTreeBucket<K, V> bucket = (HTreeBucket) node;
    

    diff --git a/src/main/java/org/apache/jdbm/SerialClassInfo.java b/src/main/java/org/apache/jdbm/SerialClassInfo.java
    index c586412..595576f 100644
    --- a/src/main/java/org/apache/jdbm/SerialClassInfo.java
    +++ b/src/main/java/org/apache/jdbm/SerialClassInfo.java
    @@ -349,7 +349,6 @@ abstract class SerialClassInfo {
    return f.get(object);
    }

    } catch (Exception e) {

            }
    
            throw new NoSuchFieldError(object.getClass() + "." + fieldInfo.getName());
    
@jankotek
Owner

Hi,

I dugout patch from your fork. Basically it prevents NPE in HashMap.
I am afraid that this would just mask deeper problem, HashMap does not seems to be thread-safe.

I believe it is better to fail, then save/return incorrect data.
So I am not going to integrate this patch. If you could help me to reproduce NPE we could probably fix original race condition.

@jankotek jankotek closed this Aug 21, 2012
@jankotek jankotek reopened this Aug 21, 2012
@jankotek
Owner

Reopening, patch was refused, but null pointers are still not fixed

@joval
joval commented Aug 21, 2012
@jankotek jankotek closed this Aug 21, 2012
@joval
joval commented Aug 23, 2012
@jankotek
Owner
@joval
joval commented Aug 24, 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.