> On Dec 13, 2014, at 7:20 AM, Maxthon Chan <m...@maxchan.info> wrote:
> 
> This got me scratching my head, hard. Why would class_respondsToSelector() 
> crash? (BTW this is used in a class search loop so I cannot use [NSObject 
> respondsToSelector:] just yet.)
> 
> /Users/technix/Developer/Subtitler 
> Pro/Frameworks/SubtitleKit/SubtitleKitTests/SKSubripParseTest.m:33: error: 
> -[SKSubripParseTest testFileFormatSearch] : failed: caught 
> "NSRangeException", "*** -[__NSCFString substringFromIndex:]: Index 18 out of 
> bounds; string length 17"
> (
>       0   CoreFoundation                      0x00007fff9266666c 
> __exceptionPreprocess + 172
>       1   libobjc.A.dylib                     0x00007fff8725976e 
> objc_exception_throw + 43
>       2   CoreFoundation                      0x00007fff9266651d 
> +[NSException raise:format:] + 205
>       3   Foundation                          0x00007fff8f127b2e -[NSString 
> substringFromIndex:] + 118
>       4   AppKit                              0x00007fff8a4e1c49 
> +[_NSObjectAnimator _targetClass] + 92
>       5   AppKit                              0x00007fff8a4e1b79 
> +[_NSObjectAnimator resolveInstanceMethod:] + 34
>       6   libobjc.A.dylib                     0x00007fff8725c954 
> _ZL28_class_resolveInstanceMethodP10objc_classP13objc_selectorP11objc_object 
> + 80

From this call stack it looks like you are tripping over an internal 
implementation detail of AppKit in a way that is not expected. In particular, 
+[_NSObjectAnimator _targetClass] (an internal class) is calling -[NSString 
substringFromIndex:] and passing an invalid index, probably due to some 
implementation detail that your code is violating. Given you are inside 
+resolveInstanceMethod:, my guess would be that by trying to dynamically look 
up the instance method, you are tripping over code that determines where to get 
that instance method from that doesn’t expect to be called on the raw 
_NSObjectAnimator.

My minimal recommendation would be to filter out all classes that begin with an 
“_” prefix from your scan. But I would be curious as to why you need to know 
the subclass information up front and not just as you encounter particular 
classes (granted this is for a test it seems, but it seems like it would be 
prudent to reduce your test to a more reasonable scope).

>       7   libobjc.A.dylib                     0x00007fff87262799 
> lookUpImpOrForward + 356
>       8   libobjc.A.dylib                     0x00007fff87262617 
> lookUpImpOrNil + 20
>       9   libobjc.A.dylib                     0x00007fff872545ff 
> class_respondsToSelector + 37
>       10  SubtitleKit                         0x00000001000d02c8 +[SKFormat 
> formatEngineForExtension:] + 184
>       11  SubtitleKitTests                    0x000000010008551e 
> -[SKSubripParseTest testFileFormatSearch] + 142
>       12  CoreFoundation                      0x00007fff9253f3cc 
> __invoking___ + 140
>       13  CoreFoundation                      0x00007fff9253f222 
> -[NSInvocation invoke] + 290
>       14  XCTest                              0x0000000100097919 -[XCTestCase 
> invokeTest] + 253
>       15  XCTest                              0x0000000100097b1a -[XCTestCase 
> performTest:] + 150
>       16  XCTest                              0x00000001000a0700 -[XCTest 
> run] + 257
>       17  XCTest                              0x000000010009682b 
> -[XCTestSuite performTest:] + 379
>       18  XCTest                              0x00000001000a0700 -[XCTest 
> run] + 257
>       19  XCTest                              0x000000010009682b 
> -[XCTestSuite performTest:] + 379
>       20  XCTest                              0x00000001000a0700 -[XCTest 
> run] + 257
>       21  XCTest                              0x000000010009682b 
> -[XCTestSuite performTest:] + 379
>       22  XCTest                              0x00000001000a0700 -[XCTest 
> run] + 257
>       23  XCTest                              0x000000010009383c 
> __25-[XCTestDriver _runSuite]_block_invoke + 56
>       24  XCTest                              0x000000010009f36d 
> -[XCTestObservationCenter _observeTestExecutionForBlock:] + 162
>       25  XCTest                              0x0000000100093770 
> -[XCTestDriver _runSuite] + 269
>       26  XCTest                              0x0000000100094359 
> -[XCTestDriver _checkForTestManager] + 678
>       27  XCTest                              0x00000001000a35b0 
> +[XCTestProbe runTests:] + 182
>       28  xctest                              0x0000000100001256 xctest + 4694
>       29  xctest                              0x00000001000015d6 xctest + 5590
>       30  xctest                              0x0000000100000ed3 xctest + 3795
>       31  libdyld.dylib                       0x00007fff90e315c9 start + 1
> )
> 
> _______________________________________________
> 
> Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)
> 
> Please do not post admin requests or moderator comments to the list.
> Contact the moderators at cocoa-dev-admins(at)lists.apple.com
> 
> Help/Unsubscribe/Update your Subscription:
> https://lists.apple.com/mailman/options/cocoa-dev/david.duncan%40apple.com
> 
> This email sent to david.dun...@apple.com

--
David Duncan


_______________________________________________

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com

Reply via email to