• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: Help with NPE in EOCustomObject.willReadRelationship()
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Help with NPE in EOCustomObject.willReadRelationship()


  • Subject: Re: Help with NPE in EOCustomObject.willReadRelationship()
  • From: Chuck Hill <email@hidden>
  • Date: Tue, 28 Apr 2009 23:16:02 -0700

Hi Peter,


On Apr 28, 2009, at 9:57 PM, Peter Vandoros wrote:

Hi Chuck,

Thanks for responding Chuck :)

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.


On 29/04/2009, at 2:40 PM, Chuck Hill wrote:

- 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.



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.



.. 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 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()!


No one ever said EOF was easy. ;-)


Chuck

--
Chuck Hill             Senior Consultant / VP Development

Come to WOWODC'09 in San Fran this June!
http://www.wocommunity.org/wowodc09/

_______________________________________________
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


  • Follow-Ups:
    • Re: Help with NPE in EOCustomObject.willReadRelationship()
      • From: Peter Vandoros <email@hidden>
References: 
 >Help with NPE in EOCustomObject.willReadRelationship() (From: Peter Vandoros <email@hidden>)
 >Re: Help with NPE in EOCustomObject.willReadRelationship() (From: Chuck Hill <email@hidden>)
 >Re: Help with NPE in EOCustomObject.willReadRelationship() (From: Peter Vandoros <email@hidden>)

  • Prev by Date: Re: EOF issues
  • Next by Date: Re: Help with NPE in EOCustomObject.willReadRelationship()
  • Previous by thread: Re: Help with NPE in EOCustomObject.willReadRelationship()
  • Next by thread: Re: Help with NPE in EOCustomObject.willReadRelationship()
  • Index(es):
    • Date
    • Thread