+[NSURL fileURLPath:] has nonnull return type but can return nil
| Originator: | bewebste | ||
| Number: | rdar://24943348 | Date Originated: | 02-Mar-2016 04:29 PM |
| Status: | Open | Resolved: | |
| Product: | OS X | Product Version: | Mac OS X 10.11.4 (15E27e) |
| Classification: | Serious Bug | Reproducible: | Not Applicable |
Summary: The method +[NSURL fileURLWithPath:] is marked in the header as returning a non null value (i.e. a non-optional in Swift), but the documentation for the method claims that the method can return a nil value. Under “Return Value” in the documentation for the method, it reads that it returns: “An NSURL object initialized with path, or nil if path is zero-length.” It appears that in the current behavior of the class, the documentation is correct, and this method can return a nil value when passed an empty path. Steps to Reproduce: Type the following line into a Swift playground: var url = NSURL(fileURLWithPath: "") Expected Results: This should either: a) return an optional NSURL with a value of nil b) return an NSURL with an empty path Actual Results: The playground reports an error: “file:///Volumes/Ratbert/Users/bwebster/Desktop/MyPlayground.playground/: error: Playground execution aborted: Execution was interrupted, reason: EXC_BAD_ACCESS (code=1, address=0x0). The process has been left at the point where it was interrupted, use "thread return -x" to return to the state before expression evaluation.” This may also affect other NSURL initialization methods, but this is the only one I’ve tested directly
Comments
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!