Make sure that jaw_impl_get_instance does not get called from our loop thread,
since it may pose unexpected reentrance issue for the application

--- a/jni/src/AtkWrapper.c
+++ b/jni/src/AtkWrapper.c
@@ -60,6 +60,8 @@ static GMainContext *jni_main_context;
 
 static gboolean jaw_initialized = FALSE;
 
+GThread *jaw_thread;
+
 gboolean jaw_accessibility_init (void)
 {
   atk_bridge_adaptor_init (NULL, NULL);
@@ -132,7 +134,6 @@ JNICALL Java_org_GNOME_Accessibility_Atk
   // Enable ATK Bridge so we can load it now
   g_unsetenv ("NO_AT_BRIDGE");
 
-  GThread *thread;
   GError *err;
   char * message;
   message = "JNI main loop";
@@ -145,8 +146,8 @@ JNICALL Java_org_GNOME_Accessibility_Atk
   jni_main_context = g_main_context_new();
   jni_main_loop = g_main_loop_new (jni_main_context, FALSE); /*main loop NOT running*/
   atk_bridge_set_event_context(jni_main_context);
-  thread = g_thread_new(message, jni_loop_callback, (void *) jni_main_loop);
-  if(thread == NULL)
+  jaw_thread = g_thread_new(message, jni_loop_callback, (void *) jni_main_loop);
+  if(jaw_thread == NULL)
   {
     if (jaw_debug)
     {
--- a/jni/src/jawimpl.c
+++ b/jni/src/jawimpl.c
@@ -45,6 +45,8 @@ static AtkObject* jaw_impl_get_parent(At
 static AtkObject* jaw_impl_ref_child (AtkObject *atk_obj, gint i);
 static AtkRelationSet* jaw_impl_ref_relation_set(AtkObject *atk_obj);
 
+extern GThread *jaw_thread;
+
 extern void jaw_action_interface_init(AtkActionIface*);
 extern gpointer jaw_action_data_init(jobject);
 extern void jaw_action_data_finalize(gpointer);
@@ -291,6 +293,11 @@ jaw_impl_get_instance (JNIEnv *jniEnv, j
 
   if (jaw_impl == NULL)
   {
+    /* Accesses from the atk bridge are normally for objects we already have */
+    /* g_assert (jaw_thread != g_thread_self()); */
+    if (jaw_thread == g_thread_self())
+      g_warning("jaw_impl_get_instance called from jaw_thread. If you are running a screen reader, this is expected\nIf you are not running a screen reader, please report this warning to the java-atk-wrapper package, explaining how to reproduce this warning\n");
+
     jobject global_ac = (*jniEnv)->NewGlobalRef(jniEnv, ac);
     if (global_ac != NULL)
     {
