On 18 Dec 2012, at 08:37, Quincey Morris <quinceymor...@rivergatesoftware.com> wrote:
> Was there a thread recently that listed a couple of Cocoa frameworks methods > that mis-handle the NSError** parameter? What were those methods? The reason > I ask is that the general file system documentation for dealing with > bookmarks: > >> https://developer.apple.com/library/mac/#documentation/FileManagement/Conceptual/FileSystemProgrammingGUide/AccessingFilesandDirectories/AccessingFilesandDirectories.html#//apple_ref/doc/uid/TP40010672-CH3-SW10 > > > gives this code fragment: > >> - (NSData*)bookmarkForURL:(NSURL*)url { >> NSError* theError = nil; >> NSData* bookmark = [url >> bookmarkDataWithOptions:NSURLBookmarkCreationSuitableForBookmarkFile >> includingResourceValuesForKeys:nil >> relativeToURL:nil >> error:&theError]; >> if (theError || (bookmark == nil)) { >> // Handle any errors. >> return nil; >> } >> return bookmark; >> } > > which doesn't follow the rules for testing for errors. The succeeding > fragment is even worse: > >> - (NSURL*)urlForBookmark:(NSData*)bookmark { >> BOOL bookmarkIsStale = NO; >> NSError* theError = nil; >> NSURL* bookmarkURL = [NSURL URLByResolvingBookmarkData:bookmark >> >> options:NSURLBookmarkResolutionWithoutUI >> relativeToURL:nil >> >> bookmarkDataIsStale:&bookmarkIsStale >> error:&theError]; >> >> if (bookmarkIsStale || (theError != nil)) { >> // Handle any errors >> return nil; >> } >> return bookmarkURL; >> } > > since it doesn't even check the returned value. > > Is this a documentation error, or is the documentation explaining how to code > around a frameworks deficiency? > > BTW the NSURL class reference documentation doesn't say anything about this. > It doesn't even mention nil return values. That sample code scares me. I wrote this recently, if it helps: http://www.mikeabdullah.net/nsurl-bookmark-error-handling.html _______________________________________________ Cocoa-dev mailing list (Cocoa-dev@lists.apple.com) Please do not post admin requests or moderator comments to the list. Contact the moderators at cocoa-dev-admins(at)lists.apple.com Help/Unsubscribe/Update your Subscription: https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com This email sent to arch...@mail-archive.com