NSBundle classNamed: causes an EXC_BAD_ACCESS error on iOS 11 devices instead of returning nil

Number:rdar://46654276 Date Originated:2018/11/12
Status:Closed Resolved:2019/02/27
Product:Xcode Product Version:10.1 (10B61)
Classification:Bug Reproducible:Always
The application crashes with an EXC_BAD_ACCESS exception when calling the following with an non-existing class name:
Class myClass = [[NSBundle mainBundle] classNamed:@"NonExistingClass"];

According to the documentation, it should return nil and should not cause an exception.
This happens with Swift application calling Objective-C framework.

Steps to Reproduce:
To reproduce it, the Swift application must call an Objective-C method that calls the following code where the given string represents a non-existing class.
See the configuration section below and see the attached demo application.
Class myClass = [[NSBundle mainBundle] classNamed:@"NonExistingClass"];

Expected Results:
The application should not crash. The method should return nil because the class does not exist in the Bundle.

Actual Results:
An EXC_BAD_ACCESS exception is raised

Xcode 10.1 (10B61)

It happens with the following configuration:
Xcode 10.1 (10B61), the error does not happen with Xcode 10.0.
iOS version: The application must be running on an iOS 11 device (tested on iPhone 6S iOS 11.4(15F79)). The problem does not occur on the simulator and it does not happen on iOS 12 devices.
The application project must be implemented in Swift.
The code calling the method classNamed on NSBundle must be written in Objective-C.



Apple has marked the bug as closed. I have not been able to test it yet with Xcode 10.2

By johan.leuenberger at April 10, 2019, 3:33 p.m. (reply...)

also reproduced on Xcode 10.1 iOS 10.3.1 project with mix of obj c and swift. Called method from Objc Class

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!