Skip to content
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-12743] Crash in _bridgeCocoaString on Xcode 11.4.1 #55188

Open
swift-ci opened this issue May 6, 2020 · 0 comments
Open

[SR-12743] Crash in _bridgeCocoaString on Xcode 11.4.1 #55188

swift-ci opened this issue May 6, 2020 · 0 comments
Labels
bug A deviation from expected or documented behavior. Also: expected but undesirable behavior. standard library Area: Standard library umbrella

Comments

@swift-ci
Copy link
Collaborator

swift-ci commented May 6, 2020

Previous ID SR-12743
Radar https://feedbackassistant.apple.com/feedback/7690771
Original Reporter ldascalu (JIRA User)
Type Bug

Attachment: Download

Environment

Xcode 11.4.1, SWIFT_OPTIMIZATION_LEVEL -Osize

Additional Detail from JIRA
Votes 0
Component/s Standard Library
Labels Bug
Assignee None
Priority Medium

md5: 98162c71f67d2f58cf596947c9282e8c

Issue Description:

Hi,

I get a runtime error, EXC_BAD_ACCESS, when setting the title of a Swift UIViewController, after viewDidLoad is called. I can only reproduce in the specific environment described here.

I attached two screenshots that illustrate the stacktrace and show the retain / release sequence that's causing the crash.

Code snippet:

class MyUIViewController {
    private let viewModel: MyViewModel

    func someMethod() {
        title = viewModel.listName // Crash
    }
}

@objc(T1MyViewModel)
public final class MyViewModel : NSObject, T1MyAbstractViewModel {
    let list: MyModel

    public var listName: String {
        return list.displayName
    }
}

NS_ASSUME_NONNULL_BEGIN
@protocol T1MyAbstractViewModel <NSObject, NSCoding>
@property (nonatomic, readonly) NSString *listName;
@end
NS_ASSUME_NONNULL_END

@interface MyModel : NSObject <NSCoding, NSCopying>
@property (nonatomic, readonly) NSString *displayName;
@end

@implementation MyModel
- (NSString *)displayName
{
    if (!_displayName) {
        _displayName = [[NSString stringWithFormat:@"list-%@", [self.listIDNumber stringValue]] mutableCopy];
    }
    return _displayName;
}
@end

It seems to be related to NSMutableString, so my workaround in the real code, which uses a mutable string, was to copy the string before setting it to _displayName.

I am totally unfamiliar with StringBridge and I wonder why my view controller calls release on an object allocated by _bridgeCocoaString; I thought that would be transparent for the caller?

@swift-ci swift-ci transferred this issue from apple/swift-issues Apr 25, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug A deviation from expected or documented behavior. Also: expected but undesirable behavior. standard library Area: Standard library umbrella
Projects
None yet
Development

No branches or pull requests

1 participant