const char* name = env->GetStringUTFChars(jname, &iscopy); if (!name) { JavaDOMGlobals::ThrowException(env, "Document.createAttribute: GetStringUTFChars failed"); return NULL;
if (jname) { name = env->GetStringUTFChars(jname, &iscopy); if (!name) { JavaDOMGlobals::ThrowException(env, "Document.createAttribute: GetStringUTFChars failed"); return NULL; }
JNIEXPORT jobject JNICALL Java_org_mozilla_dom_DocumentImpl_createAttribute  (JNIEnv *env, jobject jthis, jstring jname){  nsIDOMDocument* doc = (nsIDOMDocument*)     env->GetLongField(jthis, JavaDOMGlobals::nodePtrFID);  if (!doc) {    JavaDOMGlobals::ThrowException(env,       "Document.createAttribute: NULL pointer");    return NULL;  }  nsIDOMAttr* ret = nsnull;  jboolean iscopy = JNI_FALSE;  const char* name = env->GetStringUTFChars(jname, &iscopy);  if (!name) {    JavaDOMGlobals::ThrowException(env,       "Document.createAttribute: GetStringUTFChars failed");    return NULL;  }  nsresult rv = doc->CreateAttribute(name, &ret);  if (iscopy == JNI_TRUE)    env->ReleaseStringUTFChars(jname, name);  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.createAttribute: failed", rv, exceptionType);    return NULL;  }  jobject jret = env->AllocObject(JavaDOMGlobals::attrClass);  if (!jret) {    JavaDOMGlobals::ThrowException(env,      "Document.createAttribute: failed to allocate object");    return NULL;  }  env->SetLongField(jret, JavaDOMGlobals::nodePtrFID, (jlong) ret);  if (env->ExceptionOccurred()) {    JavaDOMGlobals::ThrowException(env,      "Document.createAttribute: failed to set node ptr");    return NULL;  }  ret->AddRef();  return jret;}