961 words

NullPointerException while setting a new property value

#1
2012-10-22 22:34

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.

Cabot
Cabot's picture
Joined on 2012-10-22
User Post #1
#2
2012-10-23 15:54

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
ObjectDB - Fast Object Database for Java (JPA/JDO)
support
support's picture
Joined on 2010-05-03
User Post #1,299
#3
2012-10-23 19:56

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)

Cabot
Cabot's picture
Joined on 2012-10-22
User Post #2
#4
2012-10-23 19:58

I am trying to attach the log file.

ObjectDB Support
ObjectDB - Fast Object Database for Java (JPA/JDO)
support
support's picture
Joined on 2010-05-03
User Post #1,301
#5
2012-10-23 20:02

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
ObjectDB - Fast Object Database for Java (JPA/JDO)
support
support's picture
Joined on 2010-05-03
User Post #1,302
#6
2012-10-23 20:13

Offtopic - upload file error screenshot (FF 16.0.1)

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

Cabot
Cabot's picture
Joined on 2012-10-22
User Post #3
#7
2012-10-23 20:37

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)
Cabot
Cabot's picture
Joined on 2012-10-22
User Post #4
#8
2012-10-23 20:39

OK. Please try now 2.4.4_03.

ObjectDB Support
ObjectDB - Fast Object Database for Java (JPA/JDO)
support
support's picture
Joined on 2010-05-03
User Post #1,303
#9
2012-10-23 20:57

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)
Cabot
Cabot's picture
Joined on 2012-10-22
User Post #5
#10
2012-10-23 21:16

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

ObjectDB Support
ObjectDB - Fast Object Database for Java (JPA/JDO)
support
support's picture
Joined on 2010-05-03
User Post #1,304
#11
2012-10-23 21:19

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

Thank you for your support.

Cabot
Cabot's picture
Joined on 2012-10-22
User Post #6
#12
2012-10-24 15:24

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)
Cabot
Cabot's picture
Joined on 2012-10-22
User Post #7
#13
2012-10-24 21:46

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
ObjectDB - Fast Object Database for Java (JPA/JDO)
support
support's picture
Joined on 2010-05-03
User Post #1,305
#14
2012-10-25 01:10

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.

 

Cabot
Cabot's picture
Joined on 2012-10-22
User Post #8
#15
2012-10-25 09:44

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
ObjectDB - Fast Object Database for Java (JPA/JDO)
support
support's picture
Joined on 2010-05-03
User Post #1,306
#16
2012-10-25 15:58

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.

 

 

Cabot
Cabot's picture
Joined on 2012-10-22
User Post #9
#17
2012-10-26 12:35

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
ObjectDB - Fast Object Database for Java (JPA/JDO)
support
support's picture
Joined on 2010-05-03
User Post #1,308

Post Reply

Please read carefully the posting instructions - before posting to the ObjectDB website.

  • You may have to disable pop up blocking in order to use the toolbar (e.g. in Chrome).
  • Use ctrl + right click to open the browser context menu in the editing area (e.g. for using a browser spell checker).
  • To insert formatted lines (e.g. Java code, stack trace) - select a style in the toolbar and then insert the text in the new created block.
  • Avoid overflow of published source code examples by breaking long lines.
  • You may mark in paragraph code words (e.g. class names) with the code style (can be applied by ctrl + D).
  • Long stack traces (> 50 lines) and complex source examples (> 100 lines) should be posted as attachments.
Attachments:
Maximum file size: 32 MB
Cancel