提交 99569952 编写于 作者: P ptbrunet

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
上级 cee76d82
...@@ -256,11 +256,15 @@ static NSObject *sAttributeNamesLOCK = nil; ...@@ -256,11 +256,15 @@ static NSObject *sAttributeNamesLOCK = nil;
jsize count = [ignoredKeys count]; jsize count = [ignoredKeys count];
JNIEnv *env = [ThreadUtilities getJNIEnv]; 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++) { for (i = 0; i < count; i++) {
jstring jString = JNFNSToJavaString(env, [ignoredKeys objectAtIndex:i]); jstring jString = JNFNSToJavaString(env, [ignoredKeys objectAtIndex:i]);
(*env)->SetObjectArrayElement(env, result, i, jString); (*env)->SetObjectArrayElement(env, result, i, jString);
...@@ -295,7 +299,7 @@ static NSObject *sAttributeNamesLOCK = nil; ...@@ -295,7 +299,7 @@ static NSObject *sAttributeNamesLOCK = nil;
jsize arrayLen = (*env)->GetArrayLength(env, jchildrenAndRoles); jsize arrayLen = (*env)->GetArrayLength(env, jchildrenAndRoles);
NSMutableArray *children = [NSMutableArray arrayWithCapacity:arrayLen/2]; //childrenAndRoles array contains two elements (child, role) for each child 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 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) for(i = 0; i < arrayLen; i+=2)
{ {
...@@ -391,8 +395,13 @@ static NSObject *sAttributeNamesLOCK = nil; ...@@ -391,8 +395,13 @@ static NSObject *sAttributeNamesLOCK = nil;
// Get all the other accessibility attributes states we need in one swell foop. // 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 // 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) 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); 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 there's a component, it can be enabled and it has a size/position
if (attributeStatesArray[0]) { if (attributeStatesArray[0]) {
...@@ -1220,7 +1229,7 @@ JNF_COCOA_EXIT(env); ...@@ -1220,7 +1229,7 @@ JNF_COCOA_EXIT(env);
// Go through the tabs and find selAccessible // Go through the tabs and find selAccessible
_numTabs = [tabs count]; _numTabs = [tabs count];
JavaComponentAccessibility *aTab; JavaComponentAccessibility *aTab;
NSUInteger i; NSInteger i;
for (i = 0; i < _numTabs; i++) { for (i = 0; i < _numTabs; i++) {
aTab = (JavaComponentAccessibility *)[tabs objectAtIndex:i]; aTab = (JavaComponentAccessibility *)[tabs objectAtIndex:i];
if ([aTab isAccessibleWithEnv:env forAccessible:selAccessible]) { if ([aTab isAccessibleWithEnv:env forAccessible:selAccessible]) {
...@@ -1247,7 +1256,7 @@ JNF_COCOA_EXIT(env); ...@@ -1247,7 +1256,7 @@ JNF_COCOA_EXIT(env);
NSString *tabJavaRole = JNFJavaToNSString(env, JNFGetObjectField(env, jtabJavaRole, sjf_key)); 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 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) { for(i = 0; i < arrayLen; i+=2) {
jobject jtab = (*env)->GetObjectArrayElement(env, jtabsAndRoles, i); jobject jtab = (*env)->GetObjectArrayElement(env, jtabsAndRoles, i);
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册