Issue Details (XML | Word | Printable)

Key: NUCCORE-667
Type: Bug Bug
Status: Closed Closed
Resolution: Fixed
Priority: Minor Minor
Assignee: Unassigned
Reporter: Fiaz Hossain
Votes: 0
Watchers: 0

If you were logged in you would be able to see more operations.
DataNucleus Core

Calling detach on a persistent object leads to subsequent NullPointerException on commit

Created: 03/Mar/11 04:23 AM   Updated: 03/Oct/11 07:37 AM   Resolved: 03/Aug/11 03:10 PM
Component/s: Lifecycles
Affects Version/s: 2.2.3
Fix Version/s: 3.0.1

File Attachments: 1. Zip Archive (2 kB)

Environment: Ubuntu Linux

Severity: Development

 Description  « Hide
The following code hits an NPE
            A a = new A();
             * ERROR is here - calling commit() causes the detached entity to be flushed causing NPE.

Mar 2, 2011 7:08:06 PM org.datanucleus.test.Main main
INFO: >> Exception thrown retrieving objects
at org.datanucleus.jdo.state.JDOStateManagerImpl.flush(
at org.datanucleus.ObjectManagerImpl.flushInternal(
at org.datanucleus.ObjectManagerImpl.flush(
at org.datanucleus.ObjectManagerImpl.preCommit(
at org.datanucleus.ObjectManagerImpl$2.transactionPreCommit(
at org.datanucleus.TransactionImpl.internalPreCommit(
at org.datanucleus.TransactionImpl.commit(
at org.datanucleus.jpa.EntityTransactionImpl.commit(
at org.datanucleus.test.Main.main(

I am not sure why someone would detach a persisted entity before calling commit() but it seems like nothing prevents someone from doing so as well. I am attaching a test case to reproduce the error.

I added the following change to that seems to fix it. Not sure clearing dirty objects on detach is the functionally correct.

+++ src/java/org/datanucleus/ 2011-03-02 18:35:45.761863043 -0800
@@ -1981,6 +1981,7 @@
             throw new NucleusUserException(LOCALISER.msg("010007", getApiAdapter().getIdForObject(obj)));
+ clearDirty(sm);

Sort Order: Ascending order - Click to sort in descending order
Fiaz Hossain added a comment - 03/Mar/11 04:24 AM
Running the test will produce NPE

Andy Jefferson added a comment - 03/Aug/11 03:10 PM
SVN trunk runs fine on that case and logs a message about performing stupid operations; a detached object is as much use as a chocolate teapot without a persistent equivalent