NullPointerException while setting a new property value

#1

Hello,
we are using ObjectDB version 2.4.4 and we are unable to resolve following NPE on enhanced entity:

java.lang.NullPointerException
at com.objectdb.o.ENT.beforeModifyMember(ENT.java:1099)
at model.PluginMetaData.__odbSet_maxAllowedDownloads(PluginMetaData.java:1)
at model.PluginMetaData.setMaxAllowedDownloads(PluginMetaData.java:268)
at model.PluginMetaData.setPluginDescriptor(PluginMetaData.java:94)


PluginMetaData looks like this (nothing extraordinary, no relationship to other @entities):

@Entity
final public class PluginMetaData {

    @Id
    @GeneratedValue
    private Long dbId;

    //persisted info
    private String id;
    private boolean updatesEnabled;
    private boolean enabled;
    private int pluginPriority;
    private int maxAllowedDownloads;
    private boolean clipboardMonitored;
    private boolean removeCompleted;

    //some other @Transient properties
    // 2 constructors
    //..
  
}

Can somebody help me?


Thank you.

#2

Please check your ObjectDB log file (mainly on the client side, but server side as well) for more details. It should include a more complete stack trace.

The exception may indicate incomplete enhancement (i.e. rebuilding the project and enhancing all the classes may solve the problem), or changing schema without restarting the server - but more details are required.

ObjectDB Support
#3

I forgot to mention we are using ObjectDB in embedded mode.

Enhancing was made successfully without any error.

Here is the log file in DEBUG mode, but there is nothing special or detailed error description.

https://dl.dropbox.com/u/51625311/objectdb.log

(attaching files seems to be broken too...)

java version "1.7.0_09"
Java(TM) SE Runtime Environment (build 1.7.0_09-b05)
Java HotSpot(TM) Client VM (build 23.5-b02, mixed mode, sharing)

#4

I am trying to attach the log file.

ObjectDB Support
#5

Please try a new build - 2.4.4_02.

It will not solved the problem yet, but hopefully will generate a better stack trace.

ObjectDB Support
#6

Offtopic - upload file error screenshot (FF 16.0.1)

https://dl.dropbox.com/u/51625311/uploadfile_failed.png

#7

This was changed:

java.lang.NullPointerException
at com.objectdb.o.ENT.aa(ENT.java:1162)
at com.objectdb.o.ENT.beforeModifyMember(ENT.java:1096)
at cz.vity.freerapid.model.PluginMetaData.__odbSet_removeCompleted(PluginMetaData.java:1)
#8

OK. Please try now 2.4.4_03.

ObjectDB Support
#9

The ObjectDB code was changed, but NPE still persists.

Tue Oct 23 22:57:34 CEST 2012 SEVERE:
java.lang.NullPointerException
at com.objectdb.o.ENT.aa(ENT.java:1164)
at com.objectdb.o.ENT.beforeModifyMember(ENT.java:1096)
at cz.vity.freerapid.model.PluginMetaData.__odbSet_removeCompleted(PluginMetaData.java:1)
at cz.vity.freerapid.model.PluginMetaData.setRemoveCompleted(PluginMetaData.java:118)
#10

This is a strange issue. Please try build 2.4.4_04. Thank you for your patient.

ObjectDB Support
#11

No problem. We will try it tomorrow. Time to sleep for now :-).

Thank you for your support.

#12

We are back, here it is - 2.4.4_04

Just a note - it fails on another property in the Entity.

Wed Oct 24 17:30:44 CEST 2012 SEVERE:
java.lang.NullPointerException
at com.objectdb.o.ENT.aa(ENT.java:1165)
at com.objectdb.o.ENT.beforeModifyMember(ENT.java:1097)
at cz.vity.freerapid.model.PluginMetaData.__odbSet_maxAllowedDownloads(PluginMetaData.java:1)
at cz.vity.freerapid.model.PluginMetaData.setMaxAllowedDownloads(PluginMetaData.java:265)
at cz.vity.freerapid.model.PluginMetaData.setPluginDescriptor(PluginMetaData.java:94)
#13

If you can demonstrate the problem with a test case it would help, because somehow your application brings ObjectDB to an unexpected state, and it is unclear how.

Build 2.4.4_05 is another attempt to solve problem (but still without understanding the exact cause).

ObjectDB Support
#14

Thanks, we will check that and I will let you know ASAP.

I guess it's a thread issue, it's not easy to reproduce it in the small scale for a test case.

We got also another report from one of our tester today - we were also encountering NPE on another place (not sure on which ObjectDB version).

In my theory, this is a (possible) cause and what we are doing - concurrent access to entities from 2 threads:

1. Creating a list of entities, default values are set from imported file

2. "Sending" this list on the special thread (ThreadPoolExecution, 1 thread, LinkedBlockingQueue) to make database access for write.

Nothing special here I guess:

public synchronized void saveCollection(Collection<? extends Identifiable> entityCollection) {
        final EntityManager em = getEntityManager();
        try {
            em.getTransaction().begin();

            for (Identifiable o : entityCollection) {
                if (o.getIdentificator() == null) {
                    em.persist(o);
                } else {
                    em.merge(o);
                }
            }
            em.getTransaction().commit();
        } finally {
            if (em.getTransaction().isActive())
                em.getTransaction().rollback();
            em.close();
        }
    }

3. The code continues with a revalidation and re-setting some properties to entities from the collection. NPE is thrown at some point while database thread is writing new data. I guess that the enhanced code should handle it somehow.

 

#15

When using JPA with multi threads each thread should have its own EntityManager and entities.

According to the JPA specification: "An entity manager must not be shared among multiple concurrently executing threads, as the entity manager and persistence context are not required to be threadsafe. Entity managers must only be accessed in a single-threaded manner."

Actually there is an attempt to provide thread safe EntityManager and persistence context in ObjectDB, but since this is not the usual way of working with JPA, you may have some difficulties like this NullPointerException (that hopefully could be solved).

ObjectDB Support
#16

A friend of mine successfully tested 2.4.4_05 and the NPE is gone. We plan more testing.

We create new EntityManager for every operation on database , so it should be thread safe.

public EntityManager getEntityManager() {
        return factory.createEntityManager();
}

We just share the entities among threads, but database operation is always made in its own single thread only.

Thanks for the patch anyway.

 

 

#17

That is good, but be aware that entities (which are part of a persistence context) are also not expected to be shared by threads, except maybe after detachment.

ObjectDB Support

Reply