--- a/jni/src/AtkWrapper.c
+++ b/jni/src/AtkWrapper.c
@@ -1192,6 +1192,12 @@ JNICALL Java_org_GNOME_Accessibility_Atk
                                                                jobject jAccContext)
 {
   jobject global_ac = (*jniEnv)->NewGlobalRef(jniEnv, jAccContext);
+  if (global_ac == NULL)
+  {
+    if (jaw_debug)
+      g_warning("Java_org_GNOME_Accessibility_AtkWrapper_componentAdded: global_ac == NULL");
+    return FALSE;
+  }
   CallbackPara *para = alloc_callback_para(global_ac);
   g_idle_add(component_added_handler, para);
 }
@@ -1251,6 +1257,12 @@ JNICALL Java_org_GNOME_Accessibility_Atk
                                                                  jobject jAccContext)
 {
   jobject global_ac = (*jniEnv)->NewGlobalRef(jniEnv, jAccContext);
+  if (global_ac == NULL)
+  {
+    if (jaw_debug)
+      g_warning("Java_org_GNOME_Accessibility_AtkWrapper_componentAdded: global_ac == NULL");
+    return FALSE;
+  }
   CallbackPara *para = alloc_callback_para(global_ac);
   g_idle_add(component_removed_handler, para);
 }
