Pivotal Knowledge Base

Follow

GemFire IllegalStateException Using CacheableString::asWChar

Environment

 Product  Version
 Pivotal GemFire Native Client  7.x - 8.0.x
 OS  All Supported OS

Symptom

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

Sample Problem Code

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()); 
} 

Root Cause

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テスト";

Resolution

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();

 

Comments

Powered by Zendesk