if (!doc) {
if (!doc || !jtagName) {
JNIEXPORT jobject JNICALL Java_org_mozilla_dom_DocumentImpl_getElementsByTagName  (JNIEnv *env, jobject jthis, jstring jtagName){  nsIDOMDocument* doc = (nsIDOMDocument*)     env->GetLongField(jthis, JavaDOMGlobals::nodePtrFID);  if (!doc) {    JavaDOMGlobals::ThrowException(env,      "Document.getElementsByTagName: NULL pointer");    return NULL;  }  const char* tagName = NULL;  nsIDOMNodeList* elements = nsnull;  jboolean iscopy = JNI_FALSE;  if (jtagName) {      tagName = env->GetStringUTFChars(jtagName, &iscopy);      if (!tagName) {	  JavaDOMGlobals::ThrowException(env,            "Document.getElementsByTagName: GetStringUTFChars failed");	  return NULL;      }  }  nsresult rv = doc->GetElementsByTagName(tagName, &elements);  if (iscopy == JNI_TRUE)    env->ReleaseStringUTFChars(jtagName, tagName);  if (NS_FAILED(rv) || !elements) {    JavaDOMGlobals::ThrowException(env,      "Document.getElementsByTagName: failed", rv);    return NULL;  }  jobject jret = env->AllocObject(JavaDOMGlobals::nodeListClass);  if (!jret) {    JavaDOMGlobals::ThrowException(env,      "Document.getElementsByTagName: failed to allocate object");    return NULL;  }  env->SetLongField(jret, JavaDOMGlobals::nodePtrFID, (jlong) elements);  if (env->ExceptionOccurred()) {    JavaDOMGlobals::ThrowException(env,      "Document.getElementsByTagName: failed to set node ptr");    return NULL;  }  elements->AddRef();  return jret;}