When using asWChar() to return the string that backs the CacheableString as a wchar_t *, you may see the below IllegalStateException:
gemfire::IllegalStateException: CacheableString::asWChar: the string is not a wide character string; use asChar() to obtain it
The following code slice will produce the above exception:
try{ const wchar_t* str = L"TestString"; CacheableString::create(str,(wcslen(str)+1)*sizeof(wchar_t)); const wchar_t *lRtnCd = lCStringP->asWChar(); }catch(const Exception & gemfireExcp){ printf("%s: %s", gemfireExcp.getName(), gemfireExcp.getMessage()); }
This is a known issue in the GemFire Native Client product, which is triggered when the given String doesn't include any wide character. If the String includes any wide character like the below example, it will not trigger this exception.
const wchar_t* str = L"Native Clientテスト";
This issue is resolved in GemFire Native Client version 8.1.x and after. A quick workaround for this exception is to use CacheableString::createNoCopy() instead of CacheableString::create() like in the example below:
const wchar_t* str = L"TestString"; wchar_t* strtmp = new wchar_t[wcslen(str)+1]; wcscpy(strtmp, str); CacheableStringPtr lCStringP = CacheableString::createNoCopy(strtmp,(wcslen(str)+1)*sizeof(wchar_t)); const wchar_t *lRtnCd = lCStringP->asWChar();