Fun Apple Bug of the Week

Just filed this as rdar://6612125 . Back up your Stickies database (in ~/Library/) and (in ~/Library/Preferences/) before attempting to reproduce this fun one.

1) Launch
2) Close all open notes. (If you start with no StickiesDatabase file, there will be two by default.) When prompted to save, don’t.
3) Choose “Use as Default” from the Note menu.
4) Try to create a new sticky note.

To fix the damage you just did, quit Stickies and throw out the new file as well as the new StickiesDatabase file. Restore your old files (I told you to make a backup!) and you’re back in business.

This is a great example of two key mistakes often made by developers: failure to validate UI items (enabling/disabling them as appropriate), and failure to validate input.

The “Use as Default” menu item should never have been enabled in the first place if there wasn’t anything to use as a template. It’s very easy to enable or disable a menu item programmatically, so there’s not really a good excuse for failing to do so. Well-behaved Mac OS X applications — at least, those written by developers who sweat the details — almost always do a very good job of this, and it’s probably a simple oversight on Apple’s part (and maybe Jens Alfke’s, though I don’t have a Classic Mac OS version of Stickies around to test).

Even assuming there was a good reason to have “Use as Default” enabled with no notes open, there’s no excuse for allowing dimensions of a window to be set to zero or negative values. A window is an on-screen analog of a physical object and, like its physical counterpart, cannot have zero or negative dimensions. On-screen objects are defined in pixels, and a pixel is the smallest entity that can be displayed on a screen. Fractions of a pixel, for these purposes, have no meaning. The application should check that the dimensions in the property list are integers greater than zero and, if they aren’t, should replace the obviously bad data. The most logical thing to do is probably to replace zero and negative values with the app defaults (in this case, 200 by 300 pixels), and to replace non-integer values with an integer, as would be achieved by the use of a floor() function or by casting the float (or other non-integer numeric data type) to an int.

Here endeth the week’s lesson.

posted by Chris on 23 February 2009 at 0244 in computing


TrackBack URL for this entry:

Post a Comment

Thanks for signing in, . Now you can comment. (sign out)

(If you haven't left a comment here before, you may need to be approved by the site owner before your comment will appear. Until then, it won't appear on the entry. Thanks for waiting.)

Remember me?