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

OCMPartialMock initialized with NSConstantArray is crashing on Xcode 14.0b3 #522

Open
rmaloney3 opened this issue Jul 20, 2022 · 3 comments

Comments

@rmaloney3
Copy link

OCMock 3.9.1
Xcode 14.0 beta 3 (14A5270f)

Using the above versions, when initializing an OCMPartialMock with an NSConstantArray, it results in an EXC_BAD_ACCESS crash in -[OCPartialMockObject prepareObjectForInstanceMethodMocking] on line 160 of OCPartialMockObject.m.

Here is an example that reproduces the crash:

- (void)testPartialMockWithArrayConstant {
    NSArray *identifiers = @[ @1, @2, @3 ];
    id mockIdentifiers = OCMPartialMock(identifiers);
}

Modifying the code to use an NSArray instead of an NSConstantArray does not crash:

- (void)testPartialMockWithArray {
    NSArray *identifiers = [NSArray arrayWithObjects:@1, @2, @3, nil];;
    id mockIdentifiers = OCMPartialMock(identifiers);
}
@dmaclach
Copy link
Contributor

Got any crash logs you could add? Be interested to know what OS you are running on as well.

@rmaloney3
Copy link
Author

rmaloney3 commented Jul 20, 2022

Crash report on macOS 12.4 (21F79): xctest-2022-07-20-102120.txt

@erikdoe
Copy link
Owner

erikdoe commented Sep 7, 2022

I can repreduce the crash, with a different stack trace. Not sure what to do here. It feels like another optimisation in the runtime, which makes immutable arrays somehow special so that the setup and clean up doesn't work as expected for them.

One option would be to add a check for immutable arrays and consider it an error when a test tries to create a partial mock for an immutable array (which is a questionable thing to do anyway).

By the way, to my knowledge there is no NSConstantArray. The only thing that's publicly visible is NSArray and NSMutableArray. At runtime you'll also see classes like __NSArrayI.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants