nsCString* str = (nsCString*) aVariant.ptr;
nsCString* str = NS_STATIC_CAST(nsCString*, aVariant.ptr);
SetRetval(JNIEnv *env, const nsXPTParamInfo &aParamInfo,          const nsXPTMethodInfo* aMethodInfo, nsIInterfaceInfo* aIInfo,          PRUint16 aMethodIndex, nsXPTCVariant* aDispatchParams,          nsXPTCVariant &aVariant, jobject* result){  nsresult rv = NS_OK;  const nsXPTType &type = aParamInfo.GetType();  switch (type.TagPart())  {    case nsXPTType::T_I8:    case nsXPTType::T_U8:      *result = env->NewObject(byteClass, byteInitMID, aVariant.val.u8);      break;    case nsXPTType::T_I16:    case nsXPTType::T_U16:      *result = env->NewObject(shortClass, shortInitMID, aVariant.val.u16);      break;    case nsXPTType::T_I32:    case nsXPTType::T_U32:      *result = env->NewObject(intClass, intInitMID, aVariant.val.u32);      break;    case nsXPTType::T_I64:    case nsXPTType::T_U64:      *result = env->NewObject(longClass, longInitMID, aVariant.val.u64);      break;    case nsXPTType::T_FLOAT:      *result = env->NewObject(floatClass, floatInitMID, aVariant.val.f);      break;    case nsXPTType::T_DOUBLE:      *result = env->NewObject(doubleClass, doubleInitMID, aVariant.val.d);      break;    case nsXPTType::T_BOOL:      *result = env->NewObject(booleanClass, booleanInitMID, aVariant.val.b);      break;    case nsXPTType::T_CHAR:      *result = env->NewObject(charClass, charInitMID, aVariant.val.c);      break;    case nsXPTType::T_WCHAR:      *result = env->NewObject(charClass, charInitMID, aVariant.val.wc);      break;    case nsXPTType::T_CHAR_STR:    {      if (aVariant.ptr) {        *result = env->NewStringUTF((const char*) aVariant.ptr);        if (*result == nsnull) {          rv = NS_ERROR_OUT_OF_MEMORY;          break;        }      }    }    break;    case nsXPTType::T_WCHAR_STR:    {      if (aVariant.ptr) {        PRUint32 length = nsCRT::strlen((const PRUnichar*) aVariant.ptr);        *result = env->NewString((const jchar*) aVariant.ptr, length);        if (*result == nsnull) {          rv = NS_ERROR_OUT_OF_MEMORY;          break;        }      }    }    break;    case nsXPTType::T_IID:    {      if (aVariant.ptr) {        nsID* iid = (nsID*) aVariant.ptr;        char* iid_str = iid->ToString();        if (iid_str) {          *result = env->NewStringUTF(iid_str);        }        if (iid_str == nsnull || *result == nsnull) {          rv = NS_ERROR_OUT_OF_MEMORY;          break;        }        PR_Free(iid_str);      }    }    break;    case nsXPTType::T_INTERFACE:    case nsXPTType::T_INTERFACE_IS:    {      nsISupports* xpcom_obj = NS_STATIC_CAST(nsISupports*, aVariant.val.p);      if (xpcom_obj) {        nsID iid;        rv = GetIIDForMethodParam(aIInfo, aMethodInfo, aParamInfo, aMethodIndex,                                  aDispatchParams, PR_TRUE, iid);        if (NS_FAILED(rv))          break;        // Get matching Java object for given xpcom object        jobject java_obj;        PRBool isNewProxy;        rv = GetNewOrUsedJavaObject(env, xpcom_obj, iid, &java_obj,                                    &isNewProxy);        if (NS_FAILED(rv))          break;        if (isNewProxy)          xpcom_obj->Release();   // Java proxy owns ref to object        // If returned object is an nsJavaXPTCStub, release it.        nsJavaXPTCStub* stub = nsnull;        xpcom_obj->QueryInterface(NS_GET_IID(nsJavaXPTCStub), (void**) &stub);        if (stub) {          NS_RELEASE(xpcom_obj);          NS_RELEASE(stub);        }        *result = java_obj;      }    }    break;    case nsXPTType::T_ASTRING:    case nsXPTType::T_DOMSTRING:    {      if (aVariant.ptr) {        nsString* str = (nsString*) aVariant.ptr;        *result = env->NewString(str->get(), str->Length());        if (*result == nsnull) {          rv = NS_ERROR_OUT_OF_MEMORY;          break;        }      }    }    break;    case nsXPTType::T_UTF8STRING:    case nsXPTType::T_CSTRING:    {      if (aVariant.ptr) {        nsCString* str = (nsCString*) aVariant.ptr;        *result = env->NewStringUTF(str->get());        if (*result == nsnull) {          rv = NS_ERROR_OUT_OF_MEMORY;          break;        }      }    }    break;    case nsXPTType::T_VOID:      // handle "void *" as an "int" in Java      LOG((" returns int (void*)"));      *result = env->NewObject(intClass, intInitMID, aVariant.val.p);      break;    case nsXPTType::T_ARRAY:      NS_WARNING("array types are not yet supported");      return NS_ERROR_NOT_IMPLEMENTED;    default:      NS_WARNING("unexpected parameter type");      return NS_ERROR_UNEXPECTED;  }  return rv;}