Re: Help with NPE in EOCustomObject.willReadRelationship()
Re: Help with NPE in EOCustomObject.willReadRelationship()
- Subject: Re: Help with NPE in EOCustomObject.willReadRelationship()
- From: Peter Vandoros <email@hidden>
- Date: Wed, 29 Apr 2009 16:34:06 +1000
Hi Chuck,
On 29/04/2009, at 4:16 PM, Chuck Hill wrote:
Just to be clear, I don't touch the deleted objects in this
notification, I simply had debugging enabled and started getting
errors :)
You did, albeit indirectly. See below.
Yes I know...
- The NPE occurs in a debug statement that prints the
NSNotification object passed to my
MyClass.editingContextDidSaveChanges() method before any
processing occurs.
That is not going to have happy results...
What I don't understand is why the deleted objects are part of the
notification if they're not meant to be used at all?
You can use them, just within very restricted conditions.
Conditions that I will agree may not be at all obvious.
So what are the conditions besides from this one? ... :-)
Obviously deleted EO's shouldn't have editingContext()'s, but I
believe that EOCustomObject.eoDescription() should not fire _any_
faults
I don't think that I would agree with that. The information from
firing faults can be very useful. You can certainly re-implement
it to not fire the faults or output something very limited if
editingContext() == null. That is a reasonable suggestion to make
in a bug report.
I should clarify:
EOCustomObject.eoDescription() should not fire _any_ faults _when_
the EO is in an invalid state (eg. editingContext() == null)
Or you should not call it when the object is in an invalid
state. :-) Design by Contract is your friend here.
I didn't think I was :-)
.. and yes, I agree with you that output much more limited should
be used instead.
or EOCustomObject.willReadRelationship() should check to see if
editingContext() is null when 'object' is a fault.
And throw an exception. That is a reasonable suggestion to make
in a bug report.
Technically, it is throwing an exception now :) ... so the only
reasonable exception to throw should again a NPE but with a reason
as to the cause
I was thinking more of an IllegalStateException:
"willReadRelationship() called and object has been deleted or not
yet inserted into an EOEditingContext".
That sounds better than my suggestion, will add it to the radar :-)
That would make me nervous. If this method is called when
editingContext() == null, that indicates to me a coding mistake.
An exception seems appropriate and the NPE is not exactly helpful.
I agree with you that it is a mistake when called and
editingContext() == null, but in my case, I am simply printing the
NSNotification object for debugging... that surely shouldn't cause
a NPE?
Part of the notification is the userInfo, which is a dictionary.
And dictionary.toString is implemented by calling toString on it's
keys and objects. IIRC, the objects are NSArray, and
NSArray.toString is implemented by calling toString on it's
objects. And EOCustomObject.toString() is implemented by calling
eoDescription(). So indirectly and inadvertently, you are calling
eoDescription()!
Yeah I know.... but I still believe that the toString() implementation
should check to see if the EO has been deleted/is in an invalid state,
and return some generic text like "object with entity <entity_name>
has been deleted or not yet inserted into an EOEditingContext".
No one ever said EOF was easy. ;-)
It ain't that hard, you just need to read the developers' minds ! :-P
Regards
Peter Vandoros
Software Engineer
Etech Group Pty Ltd
Level 3/21 Victoria St
Melbourne VIC 3000
Australia
Ph: +61 3 9639 9677
Fax: +61 3 9639 9577
----------------------------------
IMPORTANT: This e-mail message and any attachments are confidential
and may be privileged. If received in error, please reply to this
message and destroy all copies and any attachments. You should check
this message and any attachments for viruses or defects. Our liability
is limited to resupplying any affected message or attachments. For
more information about Etech Group, please visit us at http://www.etechgroup.com.au
.
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Webobjects-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden