NSURL bookmark error return
NSURL bookmark error return
- Subject: NSURL bookmark error return
- From: Quincey Morris <email@hidden>
- Date: Tue, 18 Dec 2012 00:37:02 -0800
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.
_______________________________________________
Cocoa-dev mailing list (email@hidden)
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:
This email sent to email@hidden