NSCharacterSet is not immutable
| Originator: | remy.demarest | ||
| Number: | rdar://11825093 | Date Originated: | 07-Jul-2012 10:50 AM |
| Status: | Open | Resolved: | |
| Product: | Mac OS X SDK | Product Version: | 10.7 |
| Classification: | Serious Bug | Reproducible: | Always |
There seems to be a pretty big bug in NSCharacterSet, the class doesn't allocate immutable instances. Although [NSCharacterSet newlineCharacterSet] is excepted to return an immutable instance, the line [[NSCharacterSet newlineCharacterSet] addCharactersInString:@"'"]; does not throw an exception, and this modifies the object returned by that method which makes this set invalid. After such a line, every time you use it there will be this foreign character and any operations performed with this set will be wrong. The copy method behaves as expected, that is if the instance is considered immutable it will return self and just send retain to it, whereas if the instance is considered mutable it returns a new object. However, the fact that the object is immutable doesn't prevent it from being mutated which can trigger all kinds of bugs. After looking at the open source of Core Foundation I suspect that the issue is that the mutability of a set is not checked at all. Apparently the functions that are supposed to throw an exception in these cases can be annihilated with by #define CF_ENABLE_ASSERTIONS. If it was defined when CF was compiled it would explain why CFCharacterSet does not complain that an immutable set is mutated.
Comments
Please note: Reports posted here will not necessarily be seen by Apple. All problems should be submitted at bugreport.apple.com before they are posted here. Please only post information for Radars that you have filed yourself, and please do not include Apple confidential information in your posts. Thank you!