[java-atk-wrapper] Move ac weak references to the Java code



commit 9b975cb853476a71bcae6eb173646aa9bd117327
Author: Samuel Thibault <samuel thibault ens-lyon org>
Date:   Sat Jul 27 20:58:43 2019 +0200

    Move ac weak references to the Java code
    
    d4b439228d1c56fd9c71fa5783d09f600ee5ac6b ("Fix freeing objects") made jaw
    use weak references for all java objects. The org.GNOME.Accessibility.Atk*
    however then get released basically immediately, since nothing has a global
    reference on them. Taking a global reference on them from the JawObject
    however defeats the purpose of the commit: letting java release the awt
    objects. We thus have to additionally make the Atk* objects themselves use a
    weak reference on the Accessible contexts instead of a global reference. Jaw
    can then use Atk* objects without concerns, and those have to take care
    whether the awt objects have been dropped.

 jni/src/jawaction.c                                |  4 +-
 jni/src/jawcomponent.c                             |  4 +-
 jni/src/jaweditabletext.c                          |  4 +-
 jni/src/jawhyperlink.c                             |  4 +-
 jni/src/jawhypertext.c                             |  4 +-
 jni/src/jawimage.c                                 |  4 +-
 jni/src/jawselection.c                             |  4 +-
 jni/src/jawtable.c                                 |  4 +-
 jni/src/jawtablecell.c                             |  4 +-
 jni/src/jawtext.c                                  |  4 +-
 jni/src/jawvalue.c                                 |  4 +-
 wrapper/org/GNOME/Accessibility/AtkAction.java     | 35 ++++++--
 wrapper/org/GNOME/Accessibility/AtkComponent.java  | 33 +++++++-
 .../org/GNOME/Accessibility/AtkEditableText.java   | 33 +++++++-
 wrapper/org/GNOME/Accessibility/AtkHyperlink.java  | 29 ++++++-
 wrapper/org/GNOME/Accessibility/AtkHypertext.java  | 45 ++++++----
 wrapper/org/GNOME/Accessibility/AtkImage.java      | 26 ++++--
 wrapper/org/GNOME/Accessibility/AtkSelection.java  | 43 +++++++++-
 wrapper/org/GNOME/Accessibility/AtkTable.java      | 99 ++++++++++++++++++++--
 wrapper/org/GNOME/Accessibility/AtkTableCell.java  | 25 ++++--
 wrapper/org/GNOME/Accessibility/AtkText.java       | 78 +++++++++++++++--
 wrapper/org/GNOME/Accessibility/AtkValue.java      | 21 ++++-
 22 files changed, 429 insertions(+), 82 deletions(-)
---
diff --git a/jni/src/jawaction.c b/jni/src/jawaction.c
index 35585bf..bbe8dec 100644
--- a/jni/src/jawaction.c
+++ b/jni/src/jawaction.c
@@ -65,7 +65,7 @@ jaw_action_data_init (jobject ac)
                                           "createAtkAction",
                                           
"(Ljavax/accessibility/AccessibleContext;)Lorg/GNOME/Accessibility/AtkAction;");
   jobject jatk_action = (*jniEnv)->CallStaticObjectMethod(jniEnv, classAction, jmid, ac);
-  data->atk_action = (*jniEnv)->NewWeakGlobalRef(jniEnv, jatk_action);
+  data->atk_action = (*jniEnv)->NewGlobalRef(jniEnv, jatk_action);
 
   return data;
 }
@@ -103,7 +103,7 @@ jaw_action_data_finalize (gpointer p)
       data->action_keybinding = NULL;
     }
 
-    (*jniEnv)->DeleteWeakGlobalRef(jniEnv, data->atk_action);
+    (*jniEnv)->DeleteGlobalRef(jniEnv, data->atk_action);
     data->atk_action = NULL;
   }
 }
diff --git a/jni/src/jawcomponent.c b/jni/src/jawcomponent.c
index 8c490bf..e2c1025 100644
--- a/jni/src/jawcomponent.c
+++ b/jni/src/jawcomponent.c
@@ -84,7 +84,7 @@ jaw_component_data_init (jobject ac)
                                           
"(Ljavax/accessibility/AccessibleContext;)Lorg/GNOME/Accessibility/AtkComponent;");
 
   jobject jatk_component = (*jniEnv)->CallStaticObjectMethod(jniEnv, classComponent, jmid, ac);
-  data->atk_component = (*jniEnv)->NewWeakGlobalRef(jniEnv, jatk_component);
+  data->atk_component = (*jniEnv)->NewGlobalRef(jniEnv, jatk_component);
 
   return data;
 }
@@ -98,7 +98,7 @@ jaw_component_data_finalize (gpointer p)
 
   if (data && data->atk_component)
   {
-    (*jniEnv)->DeleteWeakGlobalRef(jniEnv, data->atk_component);
+    (*jniEnv)->DeleteGlobalRef(jniEnv, data->atk_component);
     data->atk_component = NULL;
   }
 }
diff --git a/jni/src/jaweditabletext.c b/jni/src/jaweditabletext.c
index 5457244..4415d17 100644
--- a/jni/src/jaweditabletext.c
+++ b/jni/src/jaweditabletext.c
@@ -80,7 +80,7 @@ jaw_editable_text_data_init (jobject ac)
                                                     classEditableText,
                                                     jmid,
                                                     ac);
-  data->atk_editable_text = (*jniEnv)->NewWeakGlobalRef(jniEnv,
+  data->atk_editable_text = (*jniEnv)->NewGlobalRef(jniEnv,
                                                     jatk_editable_text);
 
   return data;
@@ -95,7 +95,7 @@ jaw_editable_text_data_finalize (gpointer p)
 
   if (data && data->atk_editable_text)
   {
-    (*jniEnv)->DeleteWeakGlobalRef(jniEnv, data->atk_editable_text);
+    (*jniEnv)->DeleteGlobalRef(jniEnv, data->atk_editable_text);
     data->atk_editable_text = NULL;
   }
 }
diff --git a/jni/src/jawhyperlink.c b/jni/src/jawhyperlink.c
index 6c2bb20..68cfb02 100644
--- a/jni/src/jawhyperlink.c
+++ b/jni/src/jawhyperlink.c
@@ -43,7 +43,7 @@ jaw_hyperlink_new (jobject jhyperlink)
        JAW_DEBUG_ALL("%p", jhyperlink);
        JawHyperlink* jaw_hyperlink = g_object_new(JAW_TYPE_HYPERLINK, NULL);
        JNIEnv *jniEnv = jaw_util_get_jni_env();
-       jaw_hyperlink->jhyperlink = (*jniEnv)->NewWeakGlobalRef(jniEnv, jhyperlink);
+       jaw_hyperlink->jhyperlink = (*jniEnv)->NewGlobalRef(jniEnv, jhyperlink);
 
        return jaw_hyperlink;
 }
@@ -86,7 +86,7 @@ jaw_hyperlink_finalize(GObject *gobject)
        JawHyperlink *jaw_hyperlink = JAW_HYPERLINK(gobject);
 
        JNIEnv *jniEnv = jaw_util_get_jni_env();
-       (*jniEnv)->DeleteWeakGlobalRef(jniEnv, jaw_hyperlink->jhyperlink);
+       (*jniEnv)->DeleteGlobalRef(jniEnv, jaw_hyperlink->jhyperlink);
        jaw_hyperlink->jhyperlink = NULL;
 
        /* Chain up to parent's finalize */
diff --git a/jni/src/jawhypertext.c b/jni/src/jawhypertext.c
index 211666e..0ecc979 100644
--- a/jni/src/jawhypertext.c
+++ b/jni/src/jawhypertext.c
@@ -61,7 +61,7 @@ jaw_hypertext_data_init (jobject ac)
        jclass classHypertext = (*jniEnv)->FindClass(jniEnv, "org/GNOME/Accessibility/AtkHypertext");
        jmethodID jmid = (*jniEnv)->GetStaticMethodID(jniEnv, classHypertext, "createAtkHypertext", 
"(Ljavax/accessibility/AccessibleContext;)Lorg/GNOME/Accessibility/AtkHypertext;");
        jobject jatk_hypertext = (*jniEnv)->CallStaticObjectMethod(jniEnv, classHypertext, jmid, ac);
-       data->atk_hypertext = (*jniEnv)->NewWeakGlobalRef(jniEnv, jatk_hypertext);
+       data->atk_hypertext = (*jniEnv)->NewGlobalRef(jniEnv, jatk_hypertext);
 
        data->link_table = g_hash_table_new_full(NULL, NULL, NULL, link_destroy_notify);
 
@@ -78,7 +78,7 @@ jaw_hypertext_data_finalize (gpointer p)
        if (data && data->atk_hypertext) {
                g_hash_table_remove_all(data->link_table);
 
-               (*jniEnv)->DeleteWeakGlobalRef(jniEnv, data->atk_hypertext);
+               (*jniEnv)->DeleteGlobalRef(jniEnv, data->atk_hypertext);
                data->atk_hypertext = NULL;
        }
 }
diff --git a/jni/src/jawimage.c b/jni/src/jawimage.c
index 7c4f023..f6c7237 100644
--- a/jni/src/jawimage.c
+++ b/jni/src/jawimage.c
@@ -57,7 +57,7 @@ jaw_image_data_init (jobject ac)
        jclass classImage = (*jniEnv)->FindClass(jniEnv, "org/GNOME/Accessibility/AtkImage");
        jmethodID jmid = (*jniEnv)->GetStaticMethodID(jniEnv, classImage, "createAtkImage", 
"(Ljavax/accessibility/AccessibleContext;)Lorg/GNOME/Accessibility/AtkImage;");
        jobject jatk_image = (*jniEnv)->CallStaticObjectMethod(jniEnv, classImage, jmid, ac);
-       data->atk_image = (*jniEnv)->NewWeakGlobalRef(jniEnv, jatk_image);
+       data->atk_image = (*jniEnv)->NewGlobalRef(jniEnv, jatk_image);
 
        return data;
 }
@@ -78,7 +78,7 @@ jaw_image_data_finalize (gpointer p)
                }
 
 
-               (*jniEnv)->DeleteWeakGlobalRef(jniEnv, data->atk_image);
+               (*jniEnv)->DeleteGlobalRef(jniEnv, data->atk_image);
                data->atk_image = NULL;
        }
 }
diff --git a/jni/src/jawselection.c b/jni/src/jawselection.c
index 68ae816..d85d583 100644
--- a/jni/src/jawselection.c
+++ b/jni/src/jawselection.c
@@ -61,7 +61,7 @@ jaw_selection_data_init (jobject ac)
        jclass classSelection = (*jniEnv)->FindClass(jniEnv, "org/GNOME/Accessibility/AtkSelection");
        jmethodID jmid = (*jniEnv)->GetStaticMethodID(jniEnv, classSelection, "createAtkSelection", 
"(Ljavax/accessibility/AccessibleContext;)Lorg/GNOME/Accessibility/AtkSelection;");
        jobject jatk_selection = (*jniEnv)->CallStaticObjectMethod(jniEnv, classSelection, jmid, ac);
-       data->atk_selection = (*jniEnv)->NewWeakGlobalRef(jniEnv, jatk_selection);
+       data->atk_selection = (*jniEnv)->NewGlobalRef(jniEnv, jatk_selection);
 
        return data;
 }
@@ -74,7 +74,7 @@ jaw_selection_data_finalize (gpointer p)
        JNIEnv *jniEnv = jaw_util_get_jni_env();
 
        if (data && data->atk_selection) {
-               (*jniEnv)->DeleteWeakGlobalRef(jniEnv, data->atk_selection);
+               (*jniEnv)->DeleteGlobalRef(jniEnv, data->atk_selection);
                data->atk_selection = NULL;
        }
 }
diff --git a/jni/src/jawtable.c b/jni/src/jawtable.c
index 8756444..9c2cabf 100644
--- a/jni/src/jawtable.c
+++ b/jni/src/jawtable.c
@@ -110,7 +110,7 @@ jaw_table_data_init (jobject ac)
                                        
"(Ljavax/accessibility/AccessibleContext;)Lorg/GNOME/Accessibility/AtkTable;");
 
   jobject jatk_table = (*env)->CallStaticObjectMethod(env, classTable, jmid, ac);
-  data->atk_table = (*env)->NewWeakGlobalRef(env, jatk_table);
+  data->atk_table = (*env)->NewGlobalRef(env, jatk_table);
 
   return data;
 }
@@ -132,7 +132,7 @@ jaw_table_data_finalize (gpointer p)
       data->description = NULL;
     }
 
-    (*env)->DeleteWeakGlobalRef(env, data->atk_table);
+    (*env)->DeleteGlobalRef(env, data->atk_table);
     data->atk_table = NULL;
   }
 }
diff --git a/jni/src/jawtablecell.c b/jni/src/jawtablecell.c
index 0dda75d..cce442f 100644
--- a/jni/src/jawtablecell.c
+++ b/jni/src/jawtablecell.c
@@ -59,7 +59,7 @@ jaw_table_cell_data_init (jobject ac)
   jclass classTableCell = (*jniEnv)->FindClass(jniEnv, "org/GNOME/Accessibility/AtkTableCell");
   jmethodID jmid = (*jniEnv)->GetStaticMethodID(jniEnv, classTableCell, "createAtkTableCell", 
"(Ljavax/accessibility/AccessibleContext;)Lorg/GNOME/Accessibility/AtkTableCell;");
   jobject jatk_table_cell = (*jniEnv)->CallStaticObjectMethod(jniEnv, classTableCell, jmid, ac);
-  data->atk_table_cell = (*jniEnv)->NewWeakGlobalRef(jniEnv, jatk_table_cell);
+  data->atk_table_cell = (*jniEnv)->NewGlobalRef(jniEnv, jatk_table_cell);
 
   return data;
 }
@@ -81,7 +81,7 @@ jaw_table_cell_data_finalize (gpointer p)
       data->description = NULL;
     }
 
-    (*jniEnv)->DeleteWeakGlobalRef(jniEnv, data->atk_table_cell);
+    (*jniEnv)->DeleteGlobalRef(jniEnv, data->atk_table_cell);
     data->atk_table_cell = NULL;
   }
 }
diff --git a/jni/src/jawtext.c b/jni/src/jawtext.c
index 3c8eae3..260903f 100644
--- a/jni/src/jawtext.c
+++ b/jni/src/jawtext.c
@@ -117,7 +117,7 @@ jaw_text_data_init (jobject ac)
                                           "createAtkText",
                                           
"(Ljavax/accessibility/AccessibleContext;)Lorg/GNOME/Accessibility/AtkText;");
   jobject jatk_text = (*jniEnv)->CallStaticObjectMethod(jniEnv, classText, jmid, ac);
-  data->atk_text = (*jniEnv)->NewWeakGlobalRef(jniEnv, jatk_text);
+  data->atk_text = (*jniEnv)->NewGlobalRef(jniEnv, jatk_text);
 
   return data;
 }
@@ -139,7 +139,7 @@ jaw_text_data_finalize (gpointer p)
       data->text = NULL;
     }
 
-    (*jniEnv)->DeleteWeakGlobalRef(jniEnv, data->atk_text);
+    (*jniEnv)->DeleteGlobalRef(jniEnv, data->atk_text);
     data->atk_text = NULL;
   }
 }
diff --git a/jni/src/jawvalue.c b/jni/src/jawvalue.c
index efe96a7..c95a9d2 100644
--- a/jni/src/jawvalue.c
+++ b/jni/src/jawvalue.c
@@ -60,7 +60,7 @@ jaw_value_data_init (jobject ac)
                                           "createAtkValue",
                                           
"(Ljavax/accessibility/AccessibleContext;)Lorg/GNOME/Accessibility/AtkValue;");
   jobject jatk_value = (*jniEnv)->CallStaticObjectMethod(jniEnv, classValue, jmid, ac);
-  data->atk_value = (*jniEnv)->NewWeakGlobalRef(jniEnv, jatk_value);
+  data->atk_value = (*jniEnv)->NewGlobalRef(jniEnv, jatk_value);
 
   return data;
 }
@@ -74,7 +74,7 @@ jaw_value_data_finalize (gpointer p)
 
   if (data && data->atk_value)
   {
-    (*jniEnv)->DeleteWeakGlobalRef(jniEnv, data->atk_value);
+    (*jniEnv)->DeleteGlobalRef(jniEnv, data->atk_value);
     data->atk_value = NULL;
   }
 }
diff --git a/wrapper/org/GNOME/Accessibility/AtkAction.java b/wrapper/org/GNOME/Accessibility/AtkAction.java
index 246fd34..1d01e70 100644
--- a/wrapper/org/GNOME/Accessibility/AtkAction.java
+++ b/wrapper/org/GNOME/Accessibility/AtkAction.java
@@ -21,27 +21,29 @@ package org.GNOME.Accessibility;
 
 import javax.accessibility.*;
 import javax.swing.*;
+import java.lang.ref.WeakReference;
 
 import java.awt.event.InputEvent;
 import java.awt.event.KeyEvent;
 
 public class AtkAction {
 
-       AccessibleContext ac;
-       AccessibleAction acc_action;
-       AccessibleExtendedComponent acc_ext_component;
+       WeakReference<AccessibleContext> _ac;
+       WeakReference<AccessibleAction> _acc_action;
+       WeakReference<AccessibleExtendedComponent> _acc_ext_component;
        String[] descriptions;
        int nactions;
 
        public AtkAction (AccessibleContext ac) {
                super();
-               this.ac = ac;
-               this.acc_action = ac.getAccessibleAction();
-               this.nactions = this.acc_action.getAccessibleActionCount();
+               this._ac = new WeakReference<AccessibleContext>(ac);
+               AccessibleAction acc_action = ac.getAccessibleAction();
+               this._acc_action = new WeakReference<AccessibleAction>(acc_action);
+               this.nactions = acc_action.getAccessibleActionCount();
                this.descriptions = new String[nactions];
                AccessibleComponent acc_component = ac.getAccessibleComponent();
                if (acc_component instanceof AccessibleExtendedComponent) {
-                       this.acc_ext_component = (AccessibleExtendedComponent)acc_component;
+                       this._acc_ext_component = new 
WeakReference<AccessibleExtendedComponent>((AccessibleExtendedComponent)acc_component);
                }
        }
 
@@ -50,6 +52,10 @@ public class AtkAction {
        }
 
        public boolean do_action (int i) {
+               AccessibleAction acc_action = _acc_action.get();
+               if (acc_action == null)
+                       return false;
+
                AtkUtil.invokeInSwing( () -> { acc_action.doAccessibleAction(i); });
                return true;
        }
@@ -57,6 +63,10 @@ public class AtkAction {
        public int get_n_actions () { return this.nactions; }
 
        public String get_description (int i) {
+               AccessibleAction acc_action = _acc_action.get();
+               if (acc_action == null)
+                       return null;
+
                if (i >= nactions){
                        return null;
                }
@@ -87,6 +97,13 @@ public class AtkAction {
   *          class is one way to work around that)
   */
        public String getLocalizedName (int i) {
+               AccessibleContext ac = _ac.get();
+               if (ac == null)
+                       return null;
+               AccessibleAction acc_action = _acc_action.get();
+               if (acc_action == null)
+                       return null;
+
                if (i >= nactions){
                        return null;
                }
@@ -120,6 +137,10 @@ public class AtkAction {
        }
 
        public String get_keybinding (int index) {
+               AccessibleExtendedComponent acc_ext_component = _acc_ext_component.get();
+               if (_acc_ext_component == null)
+                       return "";
+
                // TODO: improve/fix conversion to strings, concatenate,
                //       and follow our formatting convention for the role of
                //       various keybindings (i.e. global, transient, etc.)
diff --git a/wrapper/org/GNOME/Accessibility/AtkComponent.java 
b/wrapper/org/GNOME/Accessibility/AtkComponent.java
index 7e8ca83..010e130 100644
--- a/wrapper/org/GNOME/Accessibility/AtkComponent.java
+++ b/wrapper/org/GNOME/Accessibility/AtkComponent.java
@@ -23,16 +23,17 @@ package org.GNOME.Accessibility;
 import javax.accessibility.*;
 import java.awt.Point;
 import java.awt.Rectangle;
+import java.lang.ref.WeakReference;
 
 public class AtkComponent {
 
-  AccessibleContext ac;
-  AccessibleComponent acc_component;
+  WeakReference<AccessibleContext> _ac;
+  WeakReference<AccessibleComponent> _acc_component;
 
   public AtkComponent (AccessibleContext ac) {
     super();
-    this.ac = ac;
-    this.acc_component = ac.getAccessibleComponent();
+    this._ac = new WeakReference<AccessibleContext>(ac);
+    this._acc_component = new WeakReference<AccessibleComponent>(ac.getAccessibleComponent());
   }
 
   public static AtkComponent createAtkComponent(AccessibleContext ac){
@@ -40,6 +41,10 @@ public class AtkComponent {
   }
 
   public boolean contains (int x, int y, int coord_type) {
+      AccessibleComponent acc_component = _acc_component.get();
+      if (acc_component == null)
+          return false;
+
       return AtkUtil.invokeInSwing ( () -> {
           if(!acc_component.isVisible()){
               final int rightX;
@@ -60,6 +65,10 @@ public class AtkComponent {
   }
 
   public AccessibleContext get_accessible_at_point (int x, int y, int coord_type) {
+      AccessibleComponent acc_component = _acc_component.get();
+      if (acc_component == null)
+          return null;
+
       return AtkUtil.invokeInSwing ( () -> {
            if(acc_component.isVisible()){
               final int rightX;
@@ -83,6 +92,10 @@ public class AtkComponent {
   }
 
     public boolean grab_focus () {
+        AccessibleComponent acc_component = _acc_component.get();
+        if (acc_component == null)
+            return false;
+
         return AtkUtil.invokeInSwing ( () -> {
             if (!acc_component.isFocusTraversable())
                 return false;
@@ -92,6 +105,10 @@ public class AtkComponent {
     }
 
     public boolean set_extents(int x, int y, int width, int height, int coord_type) {
+        AccessibleComponent acc_component = _acc_component.get();
+        if (acc_component == null)
+            return false;
+
         return AtkUtil.invokeInSwing( () -> {
             if(acc_component.isVisible()){
                 final int rightX;
@@ -113,6 +130,10 @@ public class AtkComponent {
     }
 
     public Rectangle get_extents() {
+        AccessibleComponent acc_component = _acc_component.get();
+        if (acc_component == null)
+            return null;
+
         return AtkUtil.invokeInSwing ( () -> {
             if(acc_component.isVisible()){
                 Rectangle rect = acc_component.getBounds();
@@ -126,6 +147,10 @@ public class AtkComponent {
     }
 
     public int get_layer () {
+        AccessibleContext ac = _ac.get();
+        if (ac == null)
+            return AtkLayer.INVALID;
+
         return AtkUtil.invokeInSwing ( () -> {
             AccessibleRole role = ac.getAccessibleRole();
             if (role == AccessibleRole.MENU ||
diff --git a/wrapper/org/GNOME/Accessibility/AtkEditableText.java 
b/wrapper/org/GNOME/Accessibility/AtkEditableText.java
index 273c633..5220c27 100644
--- a/wrapper/org/GNOME/Accessibility/AtkEditableText.java
+++ b/wrapper/org/GNOME/Accessibility/AtkEditableText.java
@@ -23,14 +23,15 @@ import javax.accessibility.*;
 import java.awt.Toolkit;
 import java.awt.datatransfer.StringSelection;
 import javax.swing.text.*;
+import java.lang.ref.WeakReference;
 
 public class AtkEditableText extends AtkText {
 
-  AccessibleEditableText acc_edt_text;
+  WeakReference<AccessibleEditableText> _acc_edt_text;
 
   public AtkEditableText (AccessibleContext ac) {
     super(ac);
-    acc_edt_text = ac.getAccessibleEditableText();
+    _acc_edt_text = new WeakReference<AccessibleEditableText>(ac.getAccessibleEditableText());
   }
 
   public static AtkEditableText createAtkEditableText(AccessibleContext ac){
@@ -38,6 +39,10 @@ public class AtkEditableText extends AtkText {
   }
 
   public void set_text_contents (String s) {
+      AccessibleEditableText acc_edt_text = _acc_edt_text.get();
+      if (acc_edt_text == null)
+          return;
+
       if (!javax.swing.SwingUtilities.isEventDispatchThread())
         System.out.println("It would be unsafe to call setTextContents here");
       AtkUtil.invokeInSwing( () -> {
@@ -46,6 +51,10 @@ public class AtkEditableText extends AtkText {
   }
 
     public void insert_text (String s, int position) {
+        AccessibleEditableText acc_edt_text = _acc_edt_text.get();
+        if (acc_edt_text == null)
+            return;
+
         if (position < 0)
             position = 0;
         final int rightPosition = position;
@@ -53,6 +62,10 @@ public class AtkEditableText extends AtkText {
     }
 
     public void copy_text (int start, int end) {
+        AccessibleEditableText acc_edt_text = _acc_edt_text.get();
+        if (acc_edt_text == null)
+            return;
+
         int n = acc_edt_text.getCharCount();
         if (start < 0) {
             start = 0;
@@ -74,14 +87,26 @@ public class AtkEditableText extends AtkText {
     }
 
     public void cut_text (int start, int end) {
+        AccessibleEditableText acc_edt_text = _acc_edt_text.get();
+        if (acc_edt_text == null)
+            return;
+
         AtkUtil.invokeInSwing( () -> { acc_edt_text.cut(start, end); });
     }
 
     public void delete_text (int start, int end) {
+        AccessibleEditableText acc_edt_text = _acc_edt_text.get();
+        if (acc_edt_text == null)
+            return;
+
         AtkUtil.invokeInSwing( () -> { acc_edt_text.delete(start, end); });
     }
 
     public void paste_text (int position) {
+        AccessibleEditableText acc_edt_text = _acc_edt_text.get();
+        if (acc_edt_text == null)
+            return;
+
         AtkUtil.invokeInSwing( () -> { acc_edt_text.paste(position); });
     }
 
@@ -96,6 +121,10 @@ public class AtkEditableText extends AtkText {
     *      attributes were set.
     */
     public boolean setRunAttributes(AttributeSet as, int start, int end) {
+        AccessibleEditableText acc_edt_text = _acc_edt_text.get();
+        if (acc_edt_text == null)
+            return false;
+
         return AtkUtil.invokeInSwing( () -> {
             acc_edt_text.setAttributes(start, end, as);
             return true;
diff --git a/wrapper/org/GNOME/Accessibility/AtkHyperlink.java 
b/wrapper/org/GNOME/Accessibility/AtkHyperlink.java
index baa7479..0e39957 100644
--- a/wrapper/org/GNOME/Accessibility/AtkHyperlink.java
+++ b/wrapper/org/GNOME/Accessibility/AtkHyperlink.java
@@ -20,14 +20,15 @@
 package org.GNOME.Accessibility;
 
 import javax.accessibility.*;
+import java.lang.ref.WeakReference;
 
 public class AtkHyperlink {
 
-       AccessibleHyperlink acc_hyperlink;
+       WeakReference<AccessibleHyperlink> _acc_hyperlink;
 
        public AtkHyperlink (AccessibleHyperlink hl) {
                super();
-               acc_hyperlink = hl;
+               _acc_hyperlink = new WeakReference<AccessibleHyperlink>(hl);
        }
 
        public static AtkHyperlink createAtkHyperlink(AccessibleHyperlink hl){
@@ -35,6 +36,10 @@ public class AtkHyperlink {
        }
 
        public String get_uri (int i) {
+               AccessibleHyperlink acc_hyperlink = _acc_hyperlink.get();
+               if (acc_hyperlink == null)
+                       return "";
+
                return AtkUtil.invokeInSwing ( () -> {
                        Object o = acc_hyperlink.getAccessibleActionObject(i);
                        if (o != null)
@@ -44,6 +49,10 @@ public class AtkHyperlink {
        }
 
        public AccessibleContext get_object (int i) {
+               AccessibleHyperlink acc_hyperlink = _acc_hyperlink.get();
+               if (acc_hyperlink == null)
+                       return null;
+
                return AtkUtil.invokeInSwing ( () -> {
                        Object anchor = acc_hyperlink.getAccessibleActionAnchor(i);
                        if (anchor instanceof Accessible)
@@ -53,18 +62,34 @@ public class AtkHyperlink {
        }
 
        public int get_end_index () {
+               AccessibleHyperlink acc_hyperlink = _acc_hyperlink.get();
+               if (acc_hyperlink == null)
+                       return 0;
+
                return AtkUtil.invokeInSwing ( () -> { return acc_hyperlink.getEndIndex(); }, 0);
        }
 
        public int get_start_index () {
+               AccessibleHyperlink acc_hyperlink = _acc_hyperlink.get();
+               if (acc_hyperlink == null)
+                       return 0;
+
                return AtkUtil.invokeInSwing ( () -> { return acc_hyperlink.getStartIndex(); }, 0);
        }
 
        public boolean is_valid () {
+               AccessibleHyperlink acc_hyperlink = _acc_hyperlink.get();
+               if (acc_hyperlink == null)
+                       return false;
+
                return AtkUtil.invokeInSwing ( () -> { return acc_hyperlink.isValid(); }, false);
        }
 
        public int get_n_anchors () {
+               AccessibleHyperlink acc_hyperlink = _acc_hyperlink.get();
+               if (acc_hyperlink == null)
+                       return 0;
+
                return AtkUtil.invokeInSwing ( () -> { return acc_hyperlink.getAccessibleActionCount(); }, 0);
        }
 }
diff --git a/wrapper/org/GNOME/Accessibility/AtkHypertext.java 
b/wrapper/org/GNOME/Accessibility/AtkHypertext.java
index 98b6055..07024dd 100644
--- a/wrapper/org/GNOME/Accessibility/AtkHypertext.java
+++ b/wrapper/org/GNOME/Accessibility/AtkHypertext.java
@@ -20,50 +20,63 @@
 package org.GNOME.Accessibility;
 
 import javax.accessibility.*;
+import java.lang.ref.WeakReference;
 
 public class AtkHypertext extends AtkText {
 
-       AccessibleHypertext acc_hyper_text;
+       WeakReference<AccessibleHypertext> _acc_hyper_text;
 
        public AtkHypertext (AccessibleContext ac) {
                super(ac);
 
                AccessibleText ac_text = ac.getAccessibleText();
                if (ac_text instanceof AccessibleHypertext) {
-                       acc_hyper_text = (AccessibleHypertext)ac_text;
+                       _acc_hyper_text = new 
WeakReference<AccessibleHypertext>((AccessibleHypertext)ac_text);
                } else {
-                       acc_hyper_text = null;
+                       _acc_hyper_text = null;
                }
        }
 
        public static AtkHypertext createAtkHypertext(AccessibleContext ac){
-        return AtkUtil.invokeInSwing ( () -> { return new AtkHypertext(ac); }, null);
-    }
+               return AtkUtil.invokeInSwing ( () -> { return new AtkHypertext(ac); }, null);
+       }
 
        public AtkHyperlink get_link (int link_index) {
+               if (_acc_hyper_text == null)
+                       return null;
+               AccessibleHypertext acc_hyper_text = _acc_hyper_text.get();
+               if (acc_hyper_text == null)
+                       return null;
+
                return AtkUtil.invokeInSwing ( () -> {
-                       if (acc_hyper_text != null) {
-                               AccessibleHyperlink link = acc_hyper_text.getLink(link_index);
-                               if (link != null)
-                                       return new AtkHyperlink(link);
-                       }
+                       AccessibleHyperlink link = acc_hyper_text.getLink(link_index);
+                       if (link != null)
+                               return new AtkHyperlink(link);
                        return null;
                }, null);
        }
 
        public int get_n_links () {
-               return AtkUtil.invokeInSwing ( () -> {
-                       if (acc_hyper_text != null)
-                               return acc_hyper_text.getLinkCount();
+               if (_acc_hyper_text == null)
+                       return 0;
+               AccessibleHypertext acc_hyper_text = _acc_hyper_text.get();
+               if (acc_hyper_text == null)
                        return 0;
+
+               return AtkUtil.invokeInSwing ( () -> {
+                       return acc_hyper_text.getLinkCount();
                }, 0);
        }
 
        public int get_link_index (int char_index) {
-               return AtkUtil.invokeInSwing ( () -> {
-                       if (acc_hyper_text != null)
-                               return acc_hyper_text.getLinkIndex(char_index);
+               if (_acc_hyper_text == null)
                        return 0;
+               AccessibleHypertext acc_hyper_text = _acc_hyper_text.get();
+               if (acc_hyper_text == null)
+                       return 0;
+
+               return AtkUtil.invokeInSwing ( () -> {
+                       return acc_hyper_text.getLinkIndex(char_index);
                }, 0);
        }
 }
diff --git a/wrapper/org/GNOME/Accessibility/AtkImage.java b/wrapper/org/GNOME/Accessibility/AtkImage.java
index 4325849..bc3c549 100644
--- a/wrapper/org/GNOME/Accessibility/AtkImage.java
+++ b/wrapper/org/GNOME/Accessibility/AtkImage.java
@@ -22,23 +22,28 @@ package org.GNOME.Accessibility;
 import javax.accessibility.*;
 import java.awt.Point;
 import java.awt.Dimension;
+import java.lang.ref.WeakReference;
 
 public class AtkImage {
 
-       AccessibleContext ac;
-       AccessibleIcon[] acc_icons;
+       WeakReference<AccessibleContext> _ac;
+       WeakReference<AccessibleIcon[]> _acc_icons;
 
        public AtkImage (AccessibleContext ac) {
                super();
-               this.ac = ac;
-               this.acc_icons = ac.getAccessibleIcon();
+               this._ac = new WeakReference<AccessibleContext>(ac);
+               this._acc_icons = new WeakReference<AccessibleIcon[]>(ac.getAccessibleIcon());
        }
 
        public static AtkImage createAtkImage(AccessibleContext ac){
-        return AtkUtil.invokeInSwing ( () -> { return new AtkImage(ac); }, null);
-    }
+               return AtkUtil.invokeInSwing ( () -> { return new AtkImage(ac); }, null);
+       }
 
        public Point get_image_position (int coord_type) {
+               AccessibleContext ac = _ac.get();
+               if (ac == null)
+                       return null;
+
                return AtkUtil.invokeInSwing ( () -> {
                        AccessibleComponent acc_component = ac.getAccessibleComponent();
                        if (acc_component == null)
@@ -50,6 +55,10 @@ public class AtkImage {
        }
 
        public String get_image_description () {
+               AccessibleIcon[] acc_icons = _acc_icons.get();
+               if (acc_icons == null)
+                       return "";
+
                return AtkUtil.invokeInSwing ( () -> {
                        String desc = "";
                        if (acc_icons != null && acc_icons.length > 0) {
@@ -63,6 +72,11 @@ public class AtkImage {
 
        public Dimension get_image_size () {
                Dimension d = new Dimension(0, 0);
+
+               AccessibleIcon[] acc_icons = _acc_icons.get();
+               if (acc_icons == null)
+                       return d;
+
                return AtkUtil.invokeInSwing ( () -> {
                        if (acc_icons != null && acc_icons.length > 0) {
                                d.height = acc_icons[0].getAccessibleIconHeight();
diff --git a/wrapper/org/GNOME/Accessibility/AtkSelection.java 
b/wrapper/org/GNOME/Accessibility/AtkSelection.java
index bff1aac..bd4844c 100644
--- a/wrapper/org/GNOME/Accessibility/AtkSelection.java
+++ b/wrapper/org/GNOME/Accessibility/AtkSelection.java
@@ -20,16 +20,17 @@
 package org.GNOME.Accessibility;
 
 import javax.accessibility.*;
+import java.lang.ref.WeakReference;
 
 public class AtkSelection {
 
-       AccessibleContext ac;
-       AccessibleSelection acc_selection;
+       WeakReference<AccessibleContext> _ac;
+       WeakReference<AccessibleSelection> _acc_selection;
 
        public AtkSelection (AccessibleContext ac) {
                super();
-               this.ac = ac;
-               this.acc_selection = ac.getAccessibleSelection();
+               this._ac = new WeakReference<AccessibleContext>(ac);
+               this._acc_selection = new WeakReference<AccessibleSelection>(ac.getAccessibleSelection());
        }
 
        public static AtkSelection createAtkSelection(AccessibleContext ac){
@@ -37,6 +38,10 @@ public class AtkSelection {
        }
 
        public boolean add_selection (int i) {
+               AccessibleSelection acc_selection = _acc_selection.get();
+               if (acc_selection == null)
+                       return false;
+
                return AtkUtil.invokeInSwing( () -> {
                        acc_selection.addAccessibleSelection(i);
                        return is_child_selected(i);
@@ -44,15 +49,30 @@ public class AtkSelection {
        }
 
        public boolean clear_selection () {
+               AccessibleSelection acc_selection = _acc_selection.get();
+               if (acc_selection == null)
+                       return false;
+
                AtkUtil.invokeInSwing( () -> { acc_selection.clearAccessibleSelection(); });
                return true;
        }
 
        public AccessibleContext ref_selection (int i) {
+               AccessibleSelection acc_selection = _acc_selection.get();
+               if (acc_selection == null)
+                       return null;
+
                return AtkUtil.invokeInSwing ( () -> { return 
acc_selection.getAccessibleSelection(i).getAccessibleContext(); }, null);
        }
 
        public int get_selection_count () {
+               AccessibleContext ac = _ac.get();
+               if (ac == null)
+                       return 0;
+               AccessibleSelection acc_selection = _acc_selection.get();
+               if (acc_selection == null)
+                       return 0;
+
                return AtkUtil.invokeInSwing ( () -> {
                        int count = 0;
                        for(int i = 0; i < ac.getAccessibleChildrenCount(); i++) {
@@ -66,10 +86,18 @@ public class AtkSelection {
        }
 
        public boolean is_child_selected (int i) {
+               AccessibleSelection acc_selection = _acc_selection.get();
+               if (acc_selection == null)
+                       return false;
+
                return AtkUtil.invokeInSwing ( () -> { return acc_selection.isAccessibleChildSelected(i); }, 
false);
        }
 
        public boolean remove_selection (int i) {
+               AccessibleSelection acc_selection = _acc_selection.get();
+               if (acc_selection == null)
+                       return false;
+
                return AtkUtil.invokeInSwing( () -> {
                        acc_selection.removeAccessibleSelection(i);
                        return !is_child_selected(i);
@@ -77,6 +105,13 @@ public class AtkSelection {
        }
 
        public boolean select_all_selection () {
+               AccessibleContext ac = _ac.get();
+               if (ac == null)
+                       return false;
+               AccessibleSelection acc_selection = _acc_selection.get();
+               if (acc_selection == null)
+                       return false;
+
                AccessibleStateSet stateSet = ac.getAccessibleStateSet();
                return AtkUtil.invokeInSwing ( () -> {
                        if (stateSet.contains(AccessibleState.MULTISELECTABLE)) {
diff --git a/wrapper/org/GNOME/Accessibility/AtkTable.java b/wrapper/org/GNOME/Accessibility/AtkTable.java
index 32094ee..1af00f4 100644
--- a/wrapper/org/GNOME/Accessibility/AtkTable.java
+++ b/wrapper/org/GNOME/Accessibility/AtkTable.java
@@ -21,15 +21,16 @@
 package org.GNOME.Accessibility;
 
 import javax.accessibility.*;
+import java.lang.ref.WeakReference;
 
 public class AtkTable {
 
-       AccessibleContext ac;
-       AccessibleTable acc_table;
+       WeakReference<AccessibleContext> _ac;
+       WeakReference<AccessibleTable> _acc_table;
 
        public AtkTable (AccessibleContext ac) {
-               this.ac = ac;
-               this.acc_table = ac.getAccessibleTable();
+               this._ac = new WeakReference<AccessibleContext>(ac);
+               this._acc_table = new WeakReference<AccessibleTable>(ac.getAccessibleTable());
        }
 
        public static AtkTable createAtkTable(AccessibleContext ac){
@@ -37,6 +38,10 @@ public class AtkTable {
        }
 
        public AccessibleContext ref_at (int row, int column) {
+               AccessibleTable acc_table = _acc_table.get();
+               if (acc_table == null)
+                       return null;
+
                return AtkUtil.invokeInSwing ( () -> {
                        Accessible accessible = acc_table.getAccessibleAt(row, column);
                        if (accessible != null)
@@ -46,6 +51,10 @@ public class AtkTable {
        }
 
        public int get_column_at_index (int index) {
+               AccessibleTable acc_table = _acc_table.get();
+               if (acc_table == null)
+                       return -1;
+
                return AtkUtil.invokeInSwing ( () -> {
                        int column = -1;
                        if (acc_table instanceof AccessibleExtendedTable)
@@ -55,6 +64,10 @@ public class AtkTable {
        }
 
        public int get_row_at_index (int index) {
+               AccessibleTable acc_table = _acc_table.get();
+               if (acc_table == null)
+                       return -1;
+
                return AtkUtil.invokeInSwing ( () -> {
                        int row = -1;
                        if (acc_table instanceof AccessibleExtendedTable)
@@ -64,22 +77,42 @@ public class AtkTable {
        }
 
        public int get_n_columns () {
+               AccessibleTable acc_table = _acc_table.get();
+               if (acc_table == null)
+                       return 0;
+
                return AtkUtil.invokeInSwing ( () -> { return acc_table.getAccessibleColumnCount(); }, 0);
        }
 
        public int get_n_rows () {
+               AccessibleTable acc_table = _acc_table.get();
+               if (acc_table == null)
+                       return 0;
+
                return AtkUtil.invokeInSwing ( () -> { return acc_table.getAccessibleRowCount(); }, 0);
        }
 
        public int get_column_extent_at (int row, int column) {
+               AccessibleTable acc_table = _acc_table.get();
+               if (acc_table == null)
+                       return 0;
+
                return AtkUtil.invokeInSwing ( () -> { return acc_table.getAccessibleColumnExtentAt(row, 
column); }, 0);
        }
 
        public int get_row_extent_at (int row, int column) {
+               AccessibleTable acc_table = _acc_table.get();
+               if (acc_table == null)
+                       return 0;
+
                return AtkUtil.invokeInSwing ( () -> { return acc_table.getAccessibleRowExtentAt(row, 
column); }, 0);
        }
 
        public AccessibleContext get_caption () {
+               AccessibleTable acc_table = _acc_table.get();
+               if (acc_table == null)
+                       return null;
+
                return AtkUtil.invokeInSwing ( () -> {
                        Accessible accessible = acc_table.getAccessibleCaption();
                        if (accessible != null)
@@ -93,10 +126,18 @@ public class AtkTable {
         * @param a an Accessible object
         */
        public void setCaption(Accessible a) {
-           AtkUtil.invokeInSwing( () -> { acc_table.setAccessibleCaption(a); });
+               AccessibleTable acc_table = _acc_table.get();
+               if (acc_table == null)
+                       return;
+
+               AtkUtil.invokeInSwing( () -> { acc_table.setAccessibleCaption(a); });
        }
 
        public String get_column_description (int column) {
+               AccessibleTable acc_table = _acc_table.get();
+               if (acc_table == null)
+                       return "";
+
                return AtkUtil.invokeInSwing ( () -> {
                        Accessible accessible = acc_table.getAccessibleColumnDescription(column);
                        if (accessible != null) {
@@ -115,6 +156,10 @@ public class AtkTable {
        *                    specified column of the table
        */
        public void setColumnDescription(int column, String description) {
+               AccessibleTable acc_table = _acc_table.get();
+               if (acc_table == null)
+                       return;
+
                AtkUtil.invokeInSwing( () -> {
                        Accessible accessible = acc_table.getAccessibleColumnDescription(column);
                        if (description.equals(accessible.toString()) && accessible != null)
@@ -123,6 +168,10 @@ public class AtkTable {
        }
 
        public String get_row_description (int row) {
+               AccessibleTable acc_table = _acc_table.get();
+               if (acc_table == null)
+                       return "";
+
                return AtkUtil.invokeInSwing ( () -> {
                        Accessible accessible = acc_table.getAccessibleRowDescription(row);
                        if (accessible != null) {
@@ -141,6 +190,10 @@ public class AtkTable {
        *                    specified row of the table
        */
        public void setRowDescription(int row, String description) {
+               AccessibleTable acc_table = _acc_table.get();
+               if (acc_table == null)
+                       return;
+
                AtkUtil.invokeInSwing( () -> {
                        Accessible accessible = acc_table.getAccessibleRowDescription(row);
                        if (description.equals(accessible.toString()) && accessible != null)
@@ -149,6 +202,10 @@ public class AtkTable {
        }
 
        public AccessibleContext get_column_header (int column) {
+               AccessibleTable acc_table = _acc_table.get();
+               if (acc_table == null)
+                       return null;
+
                return AtkUtil.invokeInSwing ( () -> {
                        AccessibleTable accessibleTable = acc_table.getAccessibleColumnHeader();
                        if (accessibleTable != null) {
@@ -161,6 +218,10 @@ public class AtkTable {
        }
 
        public AccessibleContext get_row_header (int row) {
+               AccessibleTable acc_table = _acc_table.get();
+               if (acc_table == null)
+                       return null;
+
                return AtkUtil.invokeInSwing ( () -> {
                        AccessibleTable accessibleTable = acc_table.getAccessibleRowHeader();
                        if (accessibleTable != null) {
@@ -173,6 +234,10 @@ public class AtkTable {
        }
 
        public AccessibleContext get_summary () {
+               AccessibleTable acc_table = _acc_table.get();
+               if (acc_table == null)
+                       return null;
+
                return AtkUtil.invokeInSwing ( () -> {
                        Accessible accessible = acc_table.getAccessibleSummary();
                        if (accessible != null)
@@ -186,28 +251,52 @@ public class AtkTable {
         * @param a the Accessible object to set summary for
         */
        public void setSummary(Accessible a) {
+               AccessibleTable acc_table = _acc_table.get();
+               if (acc_table == null)
+                       return;
+
                AtkUtil.invokeInSwing( () -> { acc_table.setAccessibleSummary(a); });
        }
 
        public int[] get_selected_columns () {
                int[] d = new int[0];
+               AccessibleTable acc_table = _acc_table.get();
+               if (acc_table == null)
+                       return d;
+
                return AtkUtil.invokeInSwing ( () -> { return acc_table.getSelectedAccessibleColumns(); }, d);
        }
 
        public int[] get_selected_rows () {
                int[] d = new int[0];
+               AccessibleTable acc_table = _acc_table.get();
+               if (acc_table == null)
+                       return d;
+
                return AtkUtil.invokeInSwing ( () -> { return acc_table.getSelectedAccessibleRows(); }, d);
        }
 
        public boolean is_column_selected (int column) {
+               AccessibleTable acc_table = _acc_table.get();
+               if (acc_table == null)
+                       return false;
+
                return AtkUtil.invokeInSwing ( () -> { return acc_table.isAccessibleColumnSelected(column); 
}, false);
        }
 
        public boolean is_row_selected (int row) {
+               AccessibleTable acc_table = _acc_table.get();
+               if (acc_table == null)
+                       return false;
+
                return AtkUtil.invokeInSwing ( () -> { return acc_table.isAccessibleRowSelected(row); }, 
false);
        }
 
        public boolean is_selected (int row, int column) {
+               AccessibleTable acc_table = _acc_table.get();
+               if (acc_table == null)
+                       return false;
+
                return AtkUtil.invokeInSwing ( () -> { return acc_table.isAccessibleSelected(row, column); } 
,false);
        }
 }
diff --git a/wrapper/org/GNOME/Accessibility/AtkTableCell.java 
b/wrapper/org/GNOME/Accessibility/AtkTableCell.java
index fc83e06..0c0c5dd 100644
--- a/wrapper/org/GNOME/Accessibility/AtkTableCell.java
+++ b/wrapper/org/GNOME/Accessibility/AtkTableCell.java
@@ -20,23 +20,24 @@
 package org.GNOME.Accessibility;
 
 import javax.accessibility.*;
+import java.lang.ref.WeakReference;
 
 public class AtkTableCell extends AtkTable {
 
-    AccessibleContext ac;
+    WeakReference<AccessibleContext> _ac;
 
-    AccessibleExtendedTable acc_table_cell;
+    WeakReference<AccessibleExtendedTable> _acc_table_cell;
     private int rowSpan, columnSpan;
 
     public AtkTableCell (AccessibleContext ac) {
         super(ac);
-        this.ac = ac;
+        this._ac = new WeakReference<AccessibleContext>(ac);
         AccessibleTable acc_table = ac.getAccessibleTable();
 
         if (acc_table instanceof AccessibleExtendedTable) {
-            acc_table_cell = (AccessibleExtendedTable)acc_table;
+            _acc_table_cell = new WeakReference<AccessibleExtendedTable>((AccessibleExtendedTable)acc_table);
         } else {
-            acc_table_cell = null;
+            _acc_table_cell = null;
         }
         rowSpan = 0;
         columnSpan = 0;
@@ -52,7 +53,9 @@ public class AtkTableCell extends AtkTable {
     *          AccessibleTable instance.
     */
     public AccessibleTable getTable() {
-        return AtkUtil.invokeInSwing ( () -> { return acc_table_cell; }, null);
+        if (_acc_table_cell == null)
+            return null;
+        return _acc_table_cell.get();
     }
 
     /**
@@ -61,6 +64,12 @@ public class AtkTableCell extends AtkTable {
     * @return: whether the accessible index of the table cell is found
     */
     public boolean getPosition(int row, int column) {
+        if (_acc_table_cell == null)
+            return false;
+        AccessibleExtendedTable acc_table_cell = _acc_table_cell.get();
+        if (acc_table_cell == null)
+            return false;
+
         return AtkUtil.invokeInSwing ( () -> {
             int index = acc_table_cell.getAccessibleIndex(row, column);
             if (index < 0)
@@ -77,6 +86,10 @@ public class AtkTableCell extends AtkTable {
     * @return: whether the column and row span was retrieved
     */
     public boolean getRowColumnSpan(int row, int column, int rowSpan, int columnSpan) {
+        AccessibleTable acc_table = _acc_table.get();
+        if (acc_table == null)
+            return false;
+
         return AtkUtil.invokeInSwing ( () -> {
             this.rowSpan = rowSpan;
             this.columnSpan = columnSpan;
diff --git a/wrapper/org/GNOME/Accessibility/AtkText.java b/wrapper/org/GNOME/Accessibility/AtkText.java
index a4d2d56..c3da7d8 100644
--- a/wrapper/org/GNOME/Accessibility/AtkText.java
+++ b/wrapper/org/GNOME/Accessibility/AtkText.java
@@ -23,12 +23,13 @@ import javax.accessibility.*;
 import java.text.*;
 import java.awt.Rectangle;
 import java.awt.Point;
+import java.lang.ref.WeakReference;
 
 public class AtkText {
 
-       AccessibleContext ac;
-       AccessibleText acc_text;
-       AccessibleEditableText acc_edt_text;
+       WeakReference<AccessibleContext> _ac;
+       WeakReference<AccessibleText> _acc_text;
+       WeakReference<AccessibleEditableText> _acc_edt_text;
 
        public class StringSequence {
 
@@ -44,9 +45,9 @@ public class AtkText {
 
        public AtkText (AccessibleContext ac) {
                super();
-               this.ac = ac;
-               this.acc_text = ac.getAccessibleText();
-               this.acc_edt_text = ac.getAccessibleEditableText();
+               this._ac = new WeakReference<AccessibleContext>(ac);
+               this._acc_text = new WeakReference<AccessibleText>(ac.getAccessibleText());
+               this._acc_edt_text = new 
WeakReference<AccessibleEditableText>(ac.getAccessibleEditableText());
        }
 
        public static AtkText createAtkText(AccessibleContext ac){
@@ -55,6 +56,10 @@ public class AtkText {
 
        /* Return string from start, up to, but not including end */
        public String get_text (int start, int end) {
+               AccessibleText acc_text = _acc_text.get();
+               if (acc_text == null)
+                       return null;
+
                return AtkUtil.invokeInSwing ( () -> {
                        int count = acc_text.getCharCount();
                        final int rightStart;
@@ -84,6 +89,10 @@ public class AtkText {
        }
 
        public char get_character_at_offset (int offset) {
+               AccessibleText acc_text = _acc_text.get();
+               if (acc_text == null)
+                       return ' ';
+
                return AtkUtil.invokeInSwing ( () -> {
                        String str =  acc_text.getAtIndex(AccessibleText.CHARACTER, offset);
                        if (str == null || str.length() == 0)
@@ -93,6 +102,10 @@ public class AtkText {
        }
 
        public StringSequence get_text_at_offset (int offset,int boundary_type) {
+               AccessibleText acc_text = _acc_text.get();
+               if (acc_text == null)
+                       return null;
+
                return AtkUtil.invokeInSwing ( () -> {
                        if (acc_text instanceof AccessibleExtendedText) {
                                AccessibleExtendedText acc_ext_text = (AccessibleExtendedText)acc_text;
@@ -108,10 +121,21 @@ public class AtkText {
        }
 
        public int get_caret_offset () {
+               AccessibleText acc_text = _acc_text.get();
+               if (acc_text == null)
+                       return 0;
+
                return AtkUtil.invokeInSwing ( () -> { return acc_text.getCaretPosition(); }, 0);
        }
 
        public Rectangle get_character_extents (int offset, int coord_type) {
+               AccessibleContext ac = _ac.get();
+               if (ac == null)
+                       return null;
+               AccessibleText acc_text = _acc_text.get();
+               if (acc_text == null)
+                       return null;
+
                return AtkUtil.invokeInSwing ( () -> {
                        Rectangle rect = acc_text.getCharacterBounds(offset);
                        if (rect == null)
@@ -129,10 +153,21 @@ public class AtkText {
        }
 
        public int get_character_count () {
+               AccessibleText acc_text = _acc_text.get();
+               if (acc_text == null)
+                       return 0;
+
                return AtkUtil.invokeInSwing ( () -> { return acc_text.getCharCount(); }, 0);
        }
 
        public int get_offset_at_point (int x, int y, int coord_type) {
+               AccessibleContext ac = _ac.get();
+               if (ac == null)
+                       return -1;
+               AccessibleText acc_text = _acc_text.get();
+               if (acc_text == null)
+                       return -1;
+
                return AtkUtil.invokeInSwing ( () -> {
                        if (coord_type == AtkCoordType.SCREEN) {
                                AccessibleComponent component = ac.getAccessibleComponent();
@@ -146,6 +181,13 @@ public class AtkText {
        }
 
        public Rectangle get_range_extents (int start, int end, int coord_type) {
+               AccessibleContext ac = _ac.get();
+               if (ac == null)
+                       return null;
+               AccessibleText acc_text = _acc_text.get();
+               if (acc_text == null)
+                       return null;
+
                return AtkUtil.invokeInSwing ( () -> {
                        if (acc_text instanceof AccessibleExtendedText) {
                                AccessibleExtendedText acc_ext_text = (AccessibleExtendedText)acc_text;
@@ -167,6 +209,10 @@ public class AtkText {
        }
 
        public int get_n_selections () {
+               AccessibleText acc_text = _acc_text.get();
+               if (acc_text == null)
+                       return 0;
+
                return AtkUtil.invokeInSwing ( () -> {
                        String str = acc_text.getSelectedText();
                        if (str != null && str.length() > 0)
@@ -176,6 +222,10 @@ public class AtkText {
        }
 
        public StringSequence get_selection () {
+               AccessibleText acc_text = _acc_text.get();
+               if (acc_text == null)
+                       return null;
+
                return AtkUtil.invokeInSwing ( () -> {
                        int start = acc_text.getSelectionStart();
                        int end = acc_text.getSelectionEnd() + 1;
@@ -187,6 +237,10 @@ public class AtkText {
        }
 
        public boolean add_selection (int start, int end) {
+               AccessibleEditableText acc_edt_text = _acc_edt_text.get();
+               if (acc_edt_text == null)
+                       return false;
+
                return AtkUtil.invokeInSwing ( () -> {
                        if (acc_edt_text == null || get_n_selections() > 0)
                                return false;
@@ -195,6 +249,10 @@ public class AtkText {
        }
 
        public boolean remove_selection(int selection_num) {
+               AccessibleEditableText acc_edt_text = _acc_edt_text.get();
+               if (acc_edt_text == null)
+                       return false;
+
                return AtkUtil.invokeInSwing ( () -> {
                        if (acc_edt_text == null || selection_num > 0)
                                return false;
@@ -204,6 +262,10 @@ public class AtkText {
        }
 
        public boolean set_selection (int selection_num, int start, int end) {
+               AccessibleEditableText acc_edt_text = _acc_edt_text.get();
+               if (acc_edt_text == null)
+                       return false;
+
                return AtkUtil.invokeInSwing ( () -> {
                        if (acc_edt_text == null || selection_num > 0)
                                return false;
@@ -213,6 +275,10 @@ public class AtkText {
        }
 
        public boolean set_caret_offset (int offset) {
+               AccessibleEditableText acc_edt_text = _acc_edt_text.get();
+               if (acc_edt_text == null)
+                       return false;
+
                return AtkUtil.invokeInSwing ( () -> {
                        if (acc_edt_text != null) {
                                acc_edt_text.selectText(offset, offset);
diff --git a/wrapper/org/GNOME/Accessibility/AtkValue.java b/wrapper/org/GNOME/Accessibility/AtkValue.java
index d18eddd..9b57e44 100644
--- a/wrapper/org/GNOME/Accessibility/AtkValue.java
+++ b/wrapper/org/GNOME/Accessibility/AtkValue.java
@@ -21,14 +21,15 @@
 package org.GNOME.Accessibility;
 
 import javax.accessibility.*;
+import java.lang.ref.WeakReference;
 
 public class AtkValue {
 
-       AccessibleValue acc_value;
+       WeakReference<AccessibleValue> _acc_value;
 
        public AtkValue (AccessibleContext ac) {
                super();
-               this.acc_value = ac.getAccessibleValue();
+               this._acc_value = new WeakReference<AccessibleValue>(ac.getAccessibleValue());
        }
 
        public static AtkValue createAtkValue(AccessibleContext ac){
@@ -36,18 +37,34 @@ public class AtkValue {
        }
 
        public Number get_current_value () {
+               AccessibleValue acc_value = _acc_value.get();
+               if (acc_value == null)
+                       return 0.0;
+
                return AtkUtil.invokeInSwing ( () -> { return acc_value.getCurrentAccessibleValue(); }, 0.0);
        }
 
        public double getMaximumValue () {
+               AccessibleValue acc_value = _acc_value.get();
+               if (acc_value == null)
+                       return 0.0;
+
                return AtkUtil.invokeInSwing ( () -> { return 
acc_value.getMaximumAccessibleValue().doubleValue(); }, 0.0);
        }
 
        public double getMinimumValue () {
+               AccessibleValue acc_value = _acc_value.get();
+               if (acc_value == null)
+                       return 0.0;
+
                return AtkUtil.invokeInSwing ( () -> { return 
acc_value.getMinimumAccessibleValue().doubleValue(); }, 0.0);
        }
 
        public void setValue (Number n) {
+               AccessibleValue acc_value = _acc_value.get();
+               if (acc_value == null)
+                       return;
+
                AtkUtil.invokeInSwing( () -> { acc_value.setCurrentAccessibleValue(n); });
        }
 


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]