8034118: [parfait] JNI exception pending in macosx/native/sun/awt/JavaComponentAccessibility.m
authorptbrunet
Fri, 28 Mar 2014 16:40:00 -0500
changeset 24140 db4b6390d43c
parent 24139 527624e52137
child 24141 1c430b506094
8034118: [parfait] JNI exception pending in macosx/native/sun/awt/JavaComponentAccessibility.m Summary: handle possible JNI Exceptions Reviewed-by: prr, serb Contributed-by: peter.brunet@oracle.com
jdk/src/macosx/native/sun/awt/JavaComponentAccessibility.m
--- a/jdk/src/macosx/native/sun/awt/JavaComponentAccessibility.m	Fri Mar 28 11:37:45 2014 -0700
+++ b/jdk/src/macosx/native/sun/awt/JavaComponentAccessibility.m	Fri Mar 28 16:40:00 2014 -0500
@@ -242,11 +242,15 @@
         jsize count = [ignoredKeys count];
 
         JNIEnv *env = [ThreadUtilities getJNIEnv];
-        jclass clazz = (*env)->FindClass(env, "java/lang/String");
-        result = (*env)->NewObjectArray(env, count, clazz, NULL); // AWT_THREADING Safe (known object)
-        (*env)->DeleteLocalRef(env, clazz);
 
-        NSUInteger i;
+        static JNF_CLASS_CACHE(jc_String, "java/lang/String");
+        result = JNFNewObjectArray(env, &jc_String, count);
+        if (!result) {
+            NSLog(@"In %s, can't create Java array of String objects", __FUNCTION__);
+            return;
+        }
+
+        NSInteger i;
         for (i = 0; i < count; i++) {
             jstring jString = JNFNSToJavaString(env, [ignoredKeys objectAtIndex:i]);
             (*env)->SetObjectArrayElement(env, result, i, jString);
@@ -281,7 +285,7 @@
     jsize arrayLen = (*env)->GetArrayLength(env, jchildrenAndRoles);
     NSMutableArray *children = [NSMutableArray arrayWithCapacity:arrayLen/2]; //childrenAndRoles array contains two elements (child, role) for each child
 
-    NSUInteger i;
+    NSInteger i;
     NSUInteger childIndex = (whichChildren >= 0) ? whichChildren : 0; // if we're getting one particular child, make sure to set its index correctly
     for(i = 0; i < arrayLen; i+=2)
     {
@@ -377,8 +381,13 @@
     // Get all the other accessibility attributes states we need in one swell foop.
     // javaRole isn't pulled in because we need protected access to AccessibleRole.key
     jbooleanArray attributeStates = JNFCallStaticObjectMethod(env, jm_getInitialAttributeStates, fAccessible, fComponent); // AWT_THREADING Safe (AWTRunLoop)
-    if (attributeStates == NULL) return NULL;
+    if (attributeStates == NULL) return nil;
     jboolean *attributeStatesArray = (*env)->GetBooleanArrayElements(env, attributeStates, 0);
+    if (attributeStatesArray == NULL) {
+        // Note: Java will not be on the stack here so a java exception can't happen and no need to call ExceptionCheck.
+        NSLog(@"%s failed calling GetBooleanArrayElements", __FUNCTION__);
+        return nil;
+    }
 
     // if there's a component, it can be enabled and it has a size/position
     if (attributeStatesArray[0]) {
@@ -1206,7 +1215,7 @@
     // Go through the tabs and find selAccessible
     _numTabs = [tabs count];
     JavaComponentAccessibility *aTab;
-    NSUInteger i;
+    NSInteger i;
     for (i = 0; i < _numTabs; i++) {
         aTab = (JavaComponentAccessibility *)[tabs objectAtIndex:i];
         if ([aTab isAccessibleWithEnv:env forAccessible:selAccessible]) {
@@ -1233,7 +1242,7 @@
 
     NSString *tabJavaRole = JNFJavaToNSString(env, JNFGetObjectField(env, jtabJavaRole, sjf_key));
 
-    NSUInteger i;
+    NSInteger i;
     NSUInteger tabIndex = (whichTabs >= 0) ? whichTabs : 0; // if we're getting one particular child, make sure to set its index correctly
     for(i = 0; i < arrayLen; i+=2) {
         jobject jtab = (*env)->GetObjectArrayElement(env, jtabsAndRoles, i);