changeset 12724:30d341cf1562

8165829: Android Studio 2.x crashes with NPE at sun.lwawt.macosx.CAccessibility.getAccessibleIndexInParent Reviewed-by: serb, ptbrunet
author ant
date Wed, 28 Sep 2016 13:23:22 +0300
parents 148b38441505
children 2a40c91d61de
files src/macosx/classes/sun/lwawt/macosx/CAccessibility.java src/macosx/native/sun/awt/JavaComponentAccessibility.m
diffstat 2 files changed, 21 insertions(+), 8 deletions(-) [+]
line wrap: on
line diff
--- a/src/macosx/classes/sun/lwawt/macosx/CAccessibility.java	Mon Apr 24 14:54:03 2017 +0300
+++ b/src/macosx/classes/sun/lwawt/macosx/CAccessibility.java	Wed Sep 28 13:23:22 2016 +0300
@@ -84,6 +84,15 @@
         return null;
     }
 
+    static <T> T invokeAndWait(final Callable<T> callable, final Component c, final T defValue) {
+        T value = null;
+        try {
+            value = LWCToolkit.invokeAndWait(callable, c);
+        } catch (final Exception e) { e.printStackTrace(); }
+
+        return value != null ? value : defValue;
+    }
+
     static void invokeLater(final Runnable runnable, final Component c) {
         try {
             LWCToolkit.invokeLater(runnable, c);
@@ -179,7 +188,7 @@
 
                 return new Boolean(as.isAccessibleChildSelected(index));
             }
-        }, c);
+        }, c, false);
     }
 
     public static AccessibleStateSet getAccessibleStateSet(final AccessibleContext ac, final Component c) {
@@ -201,7 +210,7 @@
                 if (ass == null) return null;
                 return ass.contains(as);
             }
-        }, c);
+        }, c, false);
     }
 
     static Field getAccessibleBundleKeyFieldWithReflection() {
@@ -267,7 +276,7 @@
             public Integer call() throws Exception {
                 return at.getCharCount();
             }
-        }, c);
+        }, c, 0);
     }
 
     // Accessibility Threadsafety for JavaComponentAccessibility.m
@@ -292,7 +301,7 @@
                 if (ac == null) return null;
                 return ac.getAccessibleIndexInParent();
             }
-        }, c);
+        }, c, -1);
     }
 
     public static AccessibleComponent getAccessibleComponent(final Accessible a, final Component c) {
@@ -388,7 +397,7 @@
 
                 return aComp.isFocusTraversable();
             }
-        }, c);
+        }, c, false);
     }
 
     public static Accessible accessibilityHitTest(final Container parent, final float hitPointX, final float hitPointY) {
@@ -447,7 +456,7 @@
 
                 return aComp.isEnabled();
             }
-        }, c);
+        }, c, false);
     }
 
     // KCH - can we make this a postEvent instead?
--- a/src/macosx/native/sun/awt/JavaComponentAccessibility.m	Mon Apr 24 14:54:03 2017 +0300
+++ b/src/macosx/native/sun/awt/JavaComponentAccessibility.m	Wed Sep 28 13:23:22 2016 +0300
@@ -316,11 +316,15 @@
 
 + (JavaComponentAccessibility *)createWithAccessible:(jobject)jaccessible withEnv:(JNIEnv *)env withView:(NSView *)view
 {
+    JavaComponentAccessibility *ret = nil;
     jobject jcomponent = [(AWTView *)view awtComponent:env];
     jint index = JNFCallStaticIntMethod(env, sjm_getAccessibleIndexInParent, jaccessible, jcomponent);
-    NSString *javaRole = getJavaRole(env, jaccessible, jcomponent);
+    if (index >= 0) {
+      NSString *javaRole = getJavaRole(env, jaccessible, jcomponent);
+      ret = [self createWithAccessible:jaccessible role:javaRole index:index withEnv:env withView:view];
+    }
     (*env)->DeleteLocalRef(env, jcomponent);
-    return [self createWithAccessible:jaccessible role:javaRole index:index withEnv:env withView:view];
+    return ret;
 }
 
 + (JavaComponentAccessibility *) createWithAccessible:(jobject)jaccessible role:(NSString *)javaRole index:(jint)index withEnv:(JNIEnv *)env withView:(NSView *)view