stub = new nsJavaXPTCStub(env, aJavaObject, iinfo);
stub = new nsJavaXPTCStub(aJavaObject, iinfo);
GetNewOrUsedXPCOMObject(JNIEnv* env, jobject aJavaObject, const nsIID& aIID,                        nsISupports** aResult, PRBool* aIsXPTCStub){  NS_PRECONDITION(aResult != nsnull && aIsXPTCStub != nsnull, "null ptr");  if (!aResult || !aIsXPTCStub)    return NS_ERROR_NULL_POINTER;  nsresult rv;  *aResult = nsnull;  // Check if the given Java object is actually one of our Java proxies.  If so,  // then we query the associated XPCOM object directly from the proxy.  // If Java object is not a proxy, then we try to find associated XPCOM object  // in the mapping table.  jboolean isProxy = env->CallStaticBooleanMethod(xpcomJavaProxyClass,                                                  isXPCOMJavaProxyMID,                                                  aJavaObject);  if (env->ExceptionCheck())    return NS_ERROR_FAILURE;  if (isProxy) {    void* inst;    rv = GetXPCOMInstFromProxy(env, aJavaObject, &inst);    if (NS_SUCCEEDED(rv)) {      *aResult = NS_STATIC_CAST(JavaXPCOMInstance*, inst)->GetInstance();      NS_ADDREF(*aResult);      *aIsXPTCStub = PR_FALSE;      return NS_OK;    }  }  *aIsXPTCStub = PR_TRUE;  nsJavaXPTCStub* stub;  rv = gJavaToXPTCStubMap->Find(env, aJavaObject, aIID, &stub);  if (NS_FAILED(rv)) {    return rv;  }  if (stub) {    // stub is already AddRef'd    *aResult = NS_STATIC_CAST(nsISupports*,                              NS_STATIC_CAST(nsXPTCStubBase*, stub));    return NS_OK;  }  // If there is no corresponding XPCOM object, then that means that the  // parameter is a non-generated class (that is, it is not one of our  // Java stubs that represent an exising XPCOM object).  So we need to  // create an XPCOM stub, that can route any method calls to the class.  // Get interface info for class  nsCOMPtr<nsIInterfaceInfoManager> iim = XPTI_GetInterfaceInfoManager();  nsCOMPtr<nsIInterfaceInfo> iinfo;  rv = iim->GetInfoForIID(&aIID, getter_AddRefs(iinfo));  if (NS_FAILED(rv))    return rv;  // Create XPCOM stub  stub = new nsJavaXPTCStub(env, aJavaObject, iinfo);  if (!stub) {    return NS_ERROR_OUT_OF_MEMORY;  }  rv = gJavaToXPTCStubMap->Add(env, aJavaObject, stub);  if (NS_FAILED(rv)) {    delete stub;    return rv;  }  NS_ADDREF(stub);  *aResult = NS_STATIC_CAST(nsISupports*,                            NS_STATIC_CAST(nsXPTCStubBase*, stub));  return NS_OK;}