You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cayenne.apache.org by "Mark Rigby-Jones (Created) (JIRA)" <ji...@apache.org> on 2011/11/01 18:21:32 UTC

[jira] [Created] (CAY-1636) NPE with commitChangesToParent() after deleting object with child and cascade delete rule

NPE with commitChangesToParent() after deleting object with child and cascade delete rule 
------------------------------------------------------------------------------------------

                 Key: CAY-1636
                 URL: https://issues.apache.org/jira/browse/CAY-1636
             Project: Cayenne
          Issue Type: Bug
          Components: Core Library
    Affects Versions: 3.0.2
            Reporter: Mark Rigby-Jones


Steps to reproduce:

1) Create object A
2) Add child object B (A has a cascade delete rule for B)
3) Create a child context
4) Delete A in the child context
5) commitChangesToParent in the child context
6) NPE:
java.lang.NullPointerException
	at org.apache.cayenne.access.DataContextDeleteAction.performDelete(DataContextDeleteAction.java:59)
	at org.apache.cayenne.access.DataContext.deleteObject(DataContext.java:946)
	at org.apache.cayenne.graph.ChildDiffLoader.nodeRemoved(ChildDiffLoader.java:127)
	at org.apache.cayenne.graph.NodeDeleteOperation.apply(NodeDeleteOperation.java:37)
	at org.apache.cayenne.graph.CompoundDiff.apply(CompoundDiff.java:91)
	at org.apache.cayenne.access.ObjectStoreGraphDiff.apply(ObjectStoreGraphDiff.java:134)
	at org.apache.cayenne.access.DataContext.onContextFlush(DataContext.java:1074)
	at org.apache.cayenne.BaseContext.onSync(BaseContext.java:298)
	at org.apache.cayenne.access.DataContext.flushToParent(DataContext.java:1121)
	at org.apache.cayenne.access.DataContext.commitChangesToParent(DataContext.java:1051)

Analysis:

The issue appears to be that the graph diff to be committed to the parent context records that both A and B are to be deleted, however the delete rules for A also cause B to deleted:

1) Child diff causes A to be deleted
2) A's delete rules cause B to deleted
3) Child diff causes B to be deleted, but B no longer exists

Possible fix (not tested in any way):

In ChildDiffLoader.nodeRemoved(), check if the result of findObject() is null before attempting to delete it.

Workaround (works for me):

In the child context, delete B before deleting A.

--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators: https://issues.apache.org/jira/secure/ContactAdministrators!default.jspa
For more information on JIRA, see: http://www.atlassian.com/software/jira

        

[jira] [Closed] (CAY-1636) NPE with commitChangesToParent() after deleting object with child and cascade delete rule

Posted by "Olga Tkacheva (Closed) (JIRA)" <ji...@apache.org>.
     [ https://issues.apache.org/jira/browse/CAY-1636?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Olga Tkacheva closed CAY-1636.
------------------------------

       Resolution: Cannot Reproduce
    Fix Version/s: 3.1M4

I added tests, but not reproduced this problem. In any case I added code for check if the result of findObject() is null before attempting to delete, In ChildDiffLoader.nodeRemoved().    
                
> NPE with commitChangesToParent() after deleting object with child and cascade delete rule 
> ------------------------------------------------------------------------------------------
>
>                 Key: CAY-1636
>                 URL: https://issues.apache.org/jira/browse/CAY-1636
>             Project: Cayenne
>          Issue Type: Bug
>          Components: Core Library
>    Affects Versions: 3.0.2
>            Reporter: Mark Rigby-Jones
>             Fix For: 3.1M4
>
>
> Steps to reproduce:
> 1) Create object A
> 2) Add child object B (A has a cascade delete rule for B)
> 3) Create a child context
> 4) Delete A in the child context
> 5) commitChangesToParent in the child context
> 6) NPE:
> java.lang.NullPointerException
> 	at org.apache.cayenne.access.DataContextDeleteAction.performDelete(DataContextDeleteAction.java:59)
> 	at org.apache.cayenne.access.DataContext.deleteObject(DataContext.java:946)
> 	at org.apache.cayenne.graph.ChildDiffLoader.nodeRemoved(ChildDiffLoader.java:127)
> 	at org.apache.cayenne.graph.NodeDeleteOperation.apply(NodeDeleteOperation.java:37)
> 	at org.apache.cayenne.graph.CompoundDiff.apply(CompoundDiff.java:91)
> 	at org.apache.cayenne.access.ObjectStoreGraphDiff.apply(ObjectStoreGraphDiff.java:134)
> 	at org.apache.cayenne.access.DataContext.onContextFlush(DataContext.java:1074)
> 	at org.apache.cayenne.BaseContext.onSync(BaseContext.java:298)
> 	at org.apache.cayenne.access.DataContext.flushToParent(DataContext.java:1121)
> 	at org.apache.cayenne.access.DataContext.commitChangesToParent(DataContext.java:1051)
> Analysis:
> The issue appears to be that the graph diff to be committed to the parent context records that both A and B are to be deleted, however the delete rules for A also cause B to deleted:
> 1) Child diff causes A to be deleted
> 2) A's delete rules cause B to deleted
> 3) Child diff causes B to be deleted, but B no longer exists
> Possible fix (not tested in any way):
> In ChildDiffLoader.nodeRemoved(), check if the result of findObject() is null before attempting to delete it.
> Workaround (works for me):
> In the child context, delete B before deleting A.

--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators: https://issues.apache.org/jira/secure/ContactAdministrators!default.jspa
For more information on JIRA, see: http://www.atlassian.com/software/jira