NPE on commit when the new object was deleted before commit
-----------------------------------------------------------
Key: CAY-1044
URL: https://issues.apache.org/cayenne/browse/CAY-1044
Project: Cayenne
Issue Type: Bug
Components: Cayenne Core Library
Affects Versions: 3.0
Reporter: Andrus Adamchik
Assignee: Andrus Adamchik
Fix For: 3.0
Affects 3.0M3 and probably 2.0 as well. The following code causes the exception below:
Painting p1 = child.newObject(Painting.class);
p1.setPaintingTitle("P1");
a.addToPaintingArray(p1);
Painting p2 = child.newObject(Painting.class);
p2.setPaintingTitle("P2");
a.addToPaintingArray(p2);
a.removeFromPaintingArray(p2);
// this causes an error on commit
child.deleteObject(p2);
child.commitChangesToParent();
This is because artist -> painting diff is preserved for the deleted painting and parent context fails to process it. The fix is rather trivial
Caused by: java.lang.NullPointerException: Attempt to add null target DataObject.
at org.apache.cayenne.CayenneDataObject.addToManyTarget(CayenneDataObject.java:262)
at
org.apache.cayenne.reflect.generic.DataObjectToManyProperty.addTarget(DataObjectToManyProperty.java:72)
at org.apache.cayenne.access.ChildDiffLoader$1.visitToMany(ChildDiffLoader.java:131)
at
org.apache.cayenne.reflect.generic.DataObjectToManyProperty.visit(DataObjectToManyProperty.java:112)
at org.apache.cayenne.access.ChildDiffLoader.arcCreated(ChildDiffLoader.java:119)
at org.apache.cayenne.access.ObjectDiff$ArcOperation.apply(ObjectDiff.java:445)
at org.apache.cayenne.graph.CompoundDiff.apply(CompoundDiff.java:92)
at org.apache.cayenne.access.ObjectStoreGraphDiff.apply(ObjectStoreGraphDiff.java:135)
at org.apache.cayenne.access.DataContext.onContextFlush(DataContext.java:1135)
at org.apache.cayenne.access.DataContext.onSync(DataContext.java:1117)
at org.apache.cayenne.access.DataContext.flushToParent(DataContext.java:1175)
... 29 more
-- This message is automatically generated by JIRA. - You can reply to this email to add a comment to the issue online.
This archive was generated by hypermail 2.0.0 : Wed Apr 30 2008 - 08:56:38 EDT