Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
8275809: crash in [CommonComponentAccessibility getCAccessible:withEnv:]
Reviewed-by: kizune, pbansal
Backport-of: 7c88a59b7bca50061f120a1cf2c1d4457a1d741b
  • Loading branch information
Anton Tarasov committed Nov 23, 2021
1 parent 63981ab commit f1d9e37
Showing 1 changed file with 17 additions and 15 deletions.
Expand Up @@ -423,13 +423,20 @@ + (jobject) getCAccessible:(jobject)jaccessible withEnv:(JNIEnv *)env {
GET_CACCESSIBLE_CLASS_RETURN(NULL);
DECLARE_STATIC_METHOD_RETURN(sjm_getCAccessible, sjc_CAccessible, "getCAccessible",
"(Ljavax/accessibility/Accessible;)Lsun/lwawt/macosx/CAccessible;", NULL);
if ((*env)->IsInstanceOf(env, jaccessible, sjc_CAccessible)) {
return jaccessible;
} else if ((*env)->IsInstanceOf(env, jaccessible, sjc_Accessible)) {
jobject o = (*env)->CallStaticObjectMethod(env, sjc_CAccessible, sjm_getCAccessible, jaccessible);

// jaccessible is a weak ref, check it's still alive
jobject jaccessibleLocal = (*env)->NewLocalRef(env, jaccessible);
if ((*env)->IsSameObject(env, jaccessibleLocal, NULL)) return NULL;

if ((*env)->IsInstanceOf(env, jaccessibleLocal, sjc_CAccessible)) {
return jaccessibleLocal; // delete in the caller
} else if ((*env)->IsInstanceOf(env, jaccessibleLocal, sjc_Accessible)) {
jobject jCAX = (*env)->CallStaticObjectMethod(env, sjc_CAccessible, sjm_getCAccessible, jaccessibleLocal);
CHECK_EXCEPTION();
return o;
(*env)->DeleteLocalRef(env, jaccessibleLocal);
return jCAX; // delete in the caller
}
(*env)->DeleteLocalRef(env, jaccessibleLocal);
return NULL;
}

Expand Down Expand Up @@ -539,12 +546,10 @@ + (CommonComponentAccessibility *) createWithParent:(CommonComponentAccessibilit
// try to fetch the jCAX from Java, and return autoreleased
jobject jCAX = [CommonComponentAccessibility getCAccessible:jaccessible withEnv:env];
if (jCAX == NULL) return nil;
if (!wrapped) { // If wrapped is true, then you don't need to get an existing instance, you need to create a new one
CommonComponentAccessibility *value = (CommonComponentAccessibility *) jlong_to_ptr((*env)->GetLongField(env, jCAX, jf_ptr));
if (value != nil) {
(*env)->DeleteLocalRef(env, jCAX);
return [[value retain] autorelease];
}
CommonComponentAccessibility *value = (CommonComponentAccessibility *) jlong_to_ptr((*env)->GetLongField(env, jCAX, jf_ptr));
if (value != nil) {
(*env)->DeleteLocalRef(env, jCAX);
return [[value retain] autorelease];
}

// otherwise, create a new instance
Expand All @@ -565,10 +570,7 @@ + (CommonComponentAccessibility *) createWithParent:(CommonComponentAccessibilit
[newChild retain];
(*env)->SetLongField(env, jCAX, jf_ptr, ptr_to_jlong(newChild));

// the link is removed in the wrapper
if (!wrapped) {
(*env)->DeleteLocalRef(env, jCAX);
}
(*env)->DeleteLocalRef(env, jCAX);

// return autoreleased instance
return [newChild autorelease];
Expand Down

1 comment on commit f1d9e37

@openjdk-notifier
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.