Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

"description" fails for NSURLConnection

I have a class that is derived from NSURLConnection. Curiously, description and dealloc fail when directed to the NSURLConnection (even though the actual data transfer operation succeeds).

Here is the init method of my class:

-(id) init {
    self = [super init];
    NSLog(@"%s -- self description is %@", __PRETTY_FUNCTION__, [self description]);
    NSLog(@"%s -- super description is %@", __PRETTY_FUNCTION__, [super description]);
    return self;
}

Here is the log output from executing this code (I implemented description for my class):

2011-08-24 10:41:40.493 SleepyHead[77578:207] -[BinaryExchange init] -- self description is <BinaryExchange>
(gdb) continue
Program received signal:  “EXC_BAD_ACCESS”.

When this happens the debugger is stopped on the [super description] line, and in the call to NSURLConnection description.

What the heck is going on?

(I tried allocating and not initing another copy of the class before this one, on the off-chance that there was a piece of bogus heap getting used, but I still get the same failure.)

Added:

Even this sequence fails:

NSURLConnection* dummy = [[NSURLConnection alloc] init];
NSLog(@"%s -- dummy NSURLConnection description is %@", __PRETTY_FUNCTION__, [dummy description]);
like image 399
Hot Licks Avatar asked Aug 24 '11 15:08

Hot Licks


1 Answers

If there is a crash, there is a backtrace. Post it.

Odd crash, though.

[super description] is pretty close to nonsense. The description method is not intended to ever be used in a production environment; is a development-only method.

Did you override description in your subclass, perchance?

Also allocating and not initing another doesn't really do anything. It may not even allocate anything. Most class clusters and many other classes (as implementation details) will return a singleton on alloc and it isn't until the initialization that a particular subclass is instantiated.


Oh -- NSURLConnection doesn't use init as the designated initializer. It needs a request. More likely than not, by calling init, you aren't actually initializing the class and it crashes rather spectacularly as a result of undefined internal state.

Use initWithRequest:....

like image 126
bbum Avatar answered Sep 23 '22 13:09

bbum