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
  • Loading branch information
Anton Tarasov committed Oct 26, 2021
1 parent c9dec2f commit 7c88a59
Showing 1 changed file with 17 additions and 15 deletions.
Expand Up @@ -419,13 +419,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 @@ -535,12 +542,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 @@ -561,10 +566,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

3 comments on commit 7c88a59

@openjdk-notifier
Copy link

Choose a reason for hiding this comment

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

@forantar
Copy link
Contributor

Choose a reason for hiding this comment

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

/backport jdk17u

@openjdk
Copy link

@openjdk openjdk bot commented on 7c88a59 Nov 23, 2021

Choose a reason for hiding this comment

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

@forantar the backport was successfully created on the branch forantar-backport-7c88a59b in my personal fork of openjdk/jdk17u. To create a pull request with this backport targeting openjdk/jdk17u:master, just click the following link:

➡️ Create pull request

The title of the pull request is automatically filled in correctly and below you find a suggestion for the pull request body:

Hi all,

This pull request contains a backport of commit 7c88a59b from the openjdk/jdk repository.

The commit being backported was authored by Anton Tarasov on 26 Oct 2021 and was reviewed by Alexander Zuev and Pankaj Bansal.

Thanks!

If you need to update the source branch of the pull then run the following commands in a local clone of your personal fork of openjdk/jdk17u:

$ git fetch https://github.com/openjdk-bots/jdk17u forantar-backport-7c88a59b:forantar-backport-7c88a59b
$ git checkout forantar-backport-7c88a59b
# make changes
$ git add paths/to/changed/files
$ git commit --message 'Describe additional changes made'
$ git push https://github.com/openjdk-bots/jdk17u forantar-backport-7c88a59b

Please sign in to comment.