lionheart / openradar-mirror

A mirror of radars pulled from http://openradar.me/.
246 stars 17 forks source link

33773917: NSManagedObjectModel(contentsOf:) is incorrectly marked as returning non-optional #18139

Open openradar-mirror opened 7 years ago

openradar-mirror commented 7 years ago

Description

Summary: In iOS 11 Beta 5 there was a change in NSManagedObjectModel’s API:

From - (nullable instancetype)initWithContentsOfURL:(nonnull NSURL )url To - (nonnull instancetype)initWithContentsOfURL:(nonnull NSURL )url

This is incorrect - we can get a nil when we pass an incorrect URL. I noticed this because I’m observing issues with failures to load .omo file under iOS 11 (related radar: 33573724).

Steps to Reproduce:

  1. Create a new empty iOS project (e.g. from a “Single View App” template).
  2. Add this line somewhere let model = NSManagedObjectModel(contentsOf: URL(fileURLWithPath: "")) so that it executes when the app runs (e.g. in application(:didFinishLaunchingWithOptions:)).
  3. Run the app in Simulator or on a device.

Expected Results: According to the nullability annotation, model variable should never be nil.

Actual Results: model variable is actually nil, even though the API tells that it shouldn’t be. These messages are printed to the standard output:

2017-08-08 14:10:29.239494+0200 ManagedObjectModelRadar[3172:45012499] [error] error:  Failed to load NSManagedObjectModel with URL './ -- file:///'
CoreData: error:  Failed to load NSManagedObjectModel with URL './ -- file:///'

If the initializer can return nil, it should be annotated properly. If there are some errors, they should be returned by throwing (in Swift), not printing to the stdout.

Version: iOS 11 beta 5

Notes: Can be worked around by manually annotating the variable type as optional, e.g.:

let model: NSManagedObjectModel? = NSManagedObjectModel(contentsOf: url)

I haven’t looked into those but I think similar issues occur in other CD-related changes in iOS 11 beta 5: http://codeworkshop.net/objc-diff/sdkdiffs/ios/11.0b5/CoreData.html

- Product Version: iOS 11 beta 5 Created: 2017-08-08T12:27:30.586650 Originated: 2017-08-08T14:27:00 Open Radar Link: http://www.openradar.me/33773917

openradar-mirror commented 7 years ago

Modified: 2017-10-02T13:15:15.417380