NSFileManager -replaceItemAtURL:... fails with no explanation

Number:rdar://9993350 Date Originated:8/21/2011
Status: Resolved:
Product:iPad SDK Product Version:4.3
Classification:Other Bug Reproducible:Always
When attempting to replace a file in an iPad app's Documents directory with another file using -[NSFileManager replaceItemAtURL:withItemAtURL:backupItemName:options:resultingItemURL:error:], the operation fails (returns NO), but does not set the error parameter to explain why.

Steps to Reproduce:
- Create a file in a subdirectory of Documents (e.g. Documents/Subdir/foo.txt)
- Create a file elsewhere (e.g. in the app's Caches directory, or NSTemporaryDirectory())
- Construct NSURL instances pointing to those files
- Call -[NSFileManager replaceItemAtURL:withItemAtURL:backupItemName:options:resultingItemURL:error:] to replace one file with the other

Expected Results:
The method either returns YES to indicate success, or sets the error parameter to an NSError instance that explains the cause of the failure.

Actual Results:
The method returns NO, and does not set the error parameter. (And if the pointer passed in is not initialized, it will still contain garbage upon return.)


Sample code attached. Results observed in 4.3 simulator both in Xcode 4.0.2 on Snow Leopard and 4.1 on Lion.


Please note: Reports posted here will not necessarily be seen by Apple. All problems should be submitted at bugreport.apple.com before they are posted here. Please only post information for Radars that you have filed yourself, and please do not include Apple confidential information in your posts. Thank you!