Index: src/OFConstantString.m ================================================================== --- src/OFConstantString.m +++ src/OFConstantString.m @@ -144,33 +144,39 @@ #endif } - (void)finishInitialization { - struct of_string_utf8_ivars *ivars; - - if ((ivars = calloc(1, sizeof(*ivars))) == NULL) - @throw [OFOutOfMemoryException - exceptionWithClass: [self class] - requestedSize: sizeof(*ivars)]; - - ivars->cString = _cString; - ivars->cStringLength = _cStringLength; - - switch (of_string_utf8_check(ivars->cString, ivars->cStringLength, - &ivars->length)) { - case 1: - ivars->isUTF8 = true; - break; - case -1: - free(ivars); - @throw [OFInvalidEncodingException - exceptionWithClass: [self class]]; - } - - _cString = (char*)ivars; - object_setClass(self, [OFString_const class]); + @synchronized (self) { + struct of_string_utf8_ivars *ivars; + + if (object_getClass(self) == [OFString_const class]) + return; + + if ((ivars = calloc(1, sizeof(*ivars))) == NULL) + @throw [OFOutOfMemoryException + exceptionWithClass: [self class] + requestedSize: sizeof(*ivars)]; + + ivars->cString = _cString; + ivars->cStringLength = _cStringLength; + + switch (of_string_utf8_check(ivars->cString, + ivars->cStringLength, + &ivars->length)) { + case 1: + ivars->isUTF8 = true; + break; + case -1: + free(ivars); + @throw [OFInvalidEncodingException + exceptionWithClass: [self class]]; + } + + _cString = (char*)ivars; + object_setClass(self, [OFString_const class]); + } } + alloc { [self doesNotRecognizeSelector: _cmd];