New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[SR-9188] +[NSBundle bundleForClass:] swizzle crashes on nil argument #51679
Comments
The crashing method in question is |
In general, any swizzles performed by Swift should be written as defensively as possible, including not making any assumptions that the nullability annotations can be relied upon. The existing framework methods frequently actually handle null objects passed to nonnull parameters because these APIs were written long before nullability annotations were a thing. |
Oops indeed. My bad. |
Let's not encode any particular behavior for |
(You can see what era I learned Objective-C in from my use of |
Agreed. I think the proper solution is just replacing if (getImageNameFromSwiftClass(objcClass, &imageName)) { with if (objcClass != Nil && getImageNameFromSwiftClass(objcClass, &imageName)) { |
I think the check should go in |
For your viewing pleasure: #20608 |
Environment
Xcode 10.1 (10B61)
Apple Swift version 4.2.1 (swiftlang-1000.11.42 clang-1000.11.45.1)
Target: x86_64-apple-darwin18.2.0
Additional Detail from JIRA
md5: b3c7aea07f0f18ab24ef0c093ede11d2
Issue Description:
The Swift stdlib is swizzling
+[NSBundle bundleForClass:]
in order to handle Swift classes properly. Unfortunately it crashes if the passed class isnil
. The API itself is documented as taking anonnull
parameter, but the actual observed behavior at runtime of[NSBundle bundleForClass:nil]
without Swift is to return the same thing as[NSBundle mainBundle]
.Unfortunately, this crash is a showstopper for us for using Xcode 10.1 because a closed-source dependency of ours is apparently calling
[NSBundle bundleForClass:nil]
.The text was updated successfully, but these errors were encountered: