const char* tagName = env->GetStringUTFChars(jtagName, &iscopy); if (!tagName) { JavaDOMGlobals::ThrowException(env, "Document.createElement: GetStringUTFChars failed"); return NULL;
if (jtagName) { tagName = env->GetStringUTFChars(jtagName, &iscopy); if (!tagName) { JavaDOMGlobals::ThrowException(env, "Document.createElement: GetStringUTFChars failed"); return NULL; }
JNIEXPORT jobject JNICALL Java_org_mozilla_dom_DocumentImpl_createElement  (JNIEnv *env, jobject jthis, jstring jtagName){  nsIDOMDocument* doc = (nsIDOMDocument*)     env->GetLongField(jthis, JavaDOMGlobals::nodePtrFID);  if (!doc) {    JavaDOMGlobals::ThrowException(env,      "Document.createElement: NULL pointer");    return NULL;  }  nsIDOMElement* ret = nsnull;  jboolean iscopy = JNI_FALSE;  const char* tagName = env->GetStringUTFChars(jtagName, &iscopy);  if (!tagName) {    JavaDOMGlobals::ThrowException(env,      "Document.createElement: GetStringUTFChars failed");    return NULL;  }  nsresult rv = doc->CreateElement(tagName, &ret);  if (iscopy == JNI_TRUE)    env->ReleaseStringUTFChars(jtagName, tagName);  if (NS_FAILED(rv) || !ret) {    JavaDOMGlobals::ExceptionType exceptionType = JavaDOMGlobals::EXCEPTION_RUNTIME;    if (NS_ERROR_GET_MODULE(rv) == NS_ERROR_MODULE_DOM &&        NS_ERROR_GET_CODE(rv) == NS_ERROR_DOM_INVALID_CHARACTER_ERR) {      exceptionType = JavaDOMGlobals::EXCEPTION_DOM;    }    JavaDOMGlobals::ThrowException(env,      "Document.createElement: failed", rv, exceptionType);    return NULL;  }  jobject jret = env->AllocObject(JavaDOMGlobals::elementClass);  if (!jret) {    JavaDOMGlobals::ThrowException(env,      "Document.createElement: failed to allocate object");    return NULL;  }  env->SetLongField(jret, JavaDOMGlobals::nodePtrFID, (jlong) ret);  if (env->ExceptionOccurred()) {    JavaDOMGlobals::ThrowException(env,      "Document.createElement: failed to set node ptr");    return NULL;  }  ret->AddRef();  return jret;}