• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Exception in NSPersistentStoreCoordinator addPersistentStoreWithType with html string data, sometimes
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Exception in NSPersistentStoreCoordinator addPersistentStoreWithType with html string data, sometimes


  • Subject: Exception in NSPersistentStoreCoordinator addPersistentStoreWithType with html string data, sometimes
  • From: Paul Collins <email@hidden>
  • Date: Mon, 22 Oct 2007 17:21:15 -0700

My Core Data app is throwing an exception when reading in the XML data store at launch. This exception only happens when a string attribute of one of my Core Data objects contains "&lt;" which is a legal XML entity AFAIK. This entity was created by Core Data when I stored an HTML string. If I edit the XML file and remove the XML entities, no exception.

When I created a test app using an identical model-defined Core Data Entity, the same HTML string containing the &lt;" XML entities loads with no exception. For some reason, the issue is not reproduced.

Any suggestions? I'm considering storing the HTML as NSData as a workaround, but it would be nice to make sense of this instead.

2007-10-22 16:57:52.378 Enclose[14387] NSExceptionHandler has recorded the following exception:
NSInvalidArgumentException -- Attempt to mutate immutable object with appendString:


(gdb) bt
#0 0x92bfe014 in -[NSException raise] ()
#1 0x92bfde68 in +[NSException raise:format:] ()
#2 0x92cc6364 in mutateError ()
#3 0x92bca20c in -[NSCFString appendString:] ()
#4 0x92c27c3c in -[NSXMLTreeReader processText:] ()
#5 0x92c24a04 in -[NSXMLTreeReader parse] ()
#6 0x92c240b8 in -[NSXMLDocument initWithData:options:error:] ()
#7 0x92d30858 in -[NSXMLDocument initWithContentsOfURL:options:error:] ()
#8 0x94181114 in -[NSXMLObjectStore initWithRootStore:configurationName:options:url:] ()
#9 0x941674d4 in -[NSPersistentStoreCoordinator addPersistentStoreWithType:configuration:URL:options:error:] ()
#10 0x00008320 in -[GSApp persistentStoreCoordinator] (self=0x16509b0, _cmd=0x90aa651c) at /Users/paul/Gray/Projects/ Enclose/dev/Enclose/GSApp.m:735
#11 0x00008418 in -[GSApp managedObjectContext] (self=0x16509b0, _cmd=0x90aa15d4) at /Users/paul/Gray/Projects/Enclose/dev/Enclose/ GSApp.m:751
#12 0x92c402ac in _NSGetUsingKeyValueGetter ()
#13 0x92bf2e6c in -[NSObject(NSKeyValueCoding) valueForKeyPath:] ()
#14 0x939cc0cc in -[NSBinder _valueForKeyPath:ofObject:mode:raisesForNotApplicableKeys:] ()
#15 0x939cbd68 in -[NSBinder valueForBinding:resolveMarkersToPlaceholders:] ()
#16 0x93c669a8 in -[NSObjectParameterBinder _updateObject:observedController:observedKeyPath:context:] ()
#17 0x939c3c44 in -[NSObject(NSKeyValueBindingCreation) bind:toObject:withKeyPath:options:] ()
#18 0x937bb9e8 in -[NSIBObjectData nibInstantiateWithOwner:topLevelObjects:] ()
#19 0x937a7c9c in loadNib ()
#20 0x937a76f4 in +[NSBundle(NSNibLoading) _loadNibFile:nameTable:withZone:ownerBundle:] ()
#21 0x937febc4 in +[NSBundle(NSNibLoading) loadNibFile:externalNameTable:withZone:] ()
#22 0x9388ea70 in +[NSBundle(NSNibLoading) loadNibNamed:owner:] ()
#23 0x9388e810 in NSApplicationMain ()
#24 0x00002b78 in main (argc=1, argv=0xbffff5dc) at /Users/paul/Gray/ Projects/Enclose/dev/Enclose/main.m:13


Here's my customized version of the Core Data (non-document) template method where the exception is thrown (near the end):

- (NSPersistentStoreCoordinator *) persistentStoreCoordinator {

    if (persistentStoreCoordinator != nil) {
        return persistentStoreCoordinator;
    }

    NSFileManager *fileManager;
    NSString *applicationSupportFolder = nil;
    NSURL *url;
    NSError *error;

fileManager = [NSFileManager defaultManager];
applicationSupportFolder = [self applicationSupportFolder];
if ( ![fileManager fileExistsAtPath:applicationSupportFolder isDirectory:NULL] ) {
[fileManager createDirectoryAtPath:applicationSupportFolder attributes:nil];
}


url = [NSURL fileURLWithPath: [applicationSupportFolder stringByAppendingPathComponent: GSCoreDataStoreFilename]];
// My custom first-run check
if ([fileManager fileExistsAtPath:[url path]]) {
NSDictionary *dict = [fileManager fileAttributesAtPath:[url path] traverseLink:YES];
if ([dict fileSize] > 0) {
iLaunchedWithDatafile = YES;
} else {
// file created but never saved. This should only happen in testing.
[fileManager removeFileAtPath:[url path] handler:nil];
iLaunchedWithDatafile = NO;
}
} else {
iLaunchedWithDatafile = NO;
}

persistentStoreCoordinator = [[NSPersistentStoreCoordinator alloc] initWithManagedObjectModel: [self managedObjectModel]];
// **** Exception thrown on next line ****
if (![persistentStoreCoordinator addPersistentStoreWithType:NSXMLStoreType configuration:@"Main" URL:url options:nil error:&error]){
[[NSApplication sharedApplication] presentError:error];
}
return persistentStoreCoordinator;
}


Best regards,

Paul Collins
Gracion Software
http://www.gracion.com/

_______________________________________________

Cocoa-dev mailing list (email@hidden)

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:
This email sent to email@hidden


  • Prev by Date: Re: telling when a directory is really a bundle
  • Next by Date: [Slightly OT] Origin of CGSPrivate.h?
  • Previous by thread: Re: Setting text color in a NSFormCell
  • Next by thread: [Slightly OT] Origin of CGSPrivate.h?
  • Index(es):
    • Date
    • Thread