Report-an-Apple-Bug Friday! 70

2007-09-14 17:20:27 UTC

This bug is Borken implementation of -setNilValueForKey: in Model Object Impl Guide. It was filed on 2007-09-14 at 12:24 PDT.


Summary:

The Model Object Implementation Guide presents an example implementation of -setNilValueForKey: that can hide bugs.

Steps to Reproduce:

  1. Copy the implementation of -setNilValueForKey: from page 16 of the MOIG into your custom model-object class.
  2. Attempt to set nil for any key other than bounds (bounds being the key handled by the implementation presented in the MOIG).

Expected Results:

You get an NSInvalidArgumentException from -[NSObject setNilValueForKey:].

Actual Results:

The program whistles innocently, the nil is dropped on the floor, and the model object’s value for the key remains unchanged.

Notes:

The correction is for the overriding setNilValueForKey: to pass the message up to super when it doesn’t recognize the key. Then, for all keys not recognized by the overriding implementation, an NSInvalidArgumentException will be raised, as expected.

4 Responses to “Report-an-Apple-Bug Friday! 70”

  1. Simone Manganelli Says:

    Do you have some unclosed tag somewhere in here? The text keeps getting smaller and smaller as you go down the entry page! The text is all diving into a black hole!

  2. Peter Hosey Says:

    Do you have some unclosed tag somewhere in here? The text keeps getting smaller and smaller as you go down the entry page! The text is all diving into a black hole!

    Oops, sorry. I had a couple of <code>s that I forgot to change to </code>s. Copy-and-paste error. They’re fixed now.

  3. Jordy/Jediknil Says:

    Clever doc bug. But, is it really “Borken”?

  4. Peter Hosey Says:

    A subclass method that, by omission of an important call to the superclass, hides bugs, itself contains a bug; thus, it is borken.

Leave a Reply

Do not delete the second sentence.