Skip to content

Commit 5e861e3

Browse files
committed
8298645: JNI works with accessibleSelection on a wrong thread
Reviewed-by: serb, kizune
1 parent fd746a2 commit 5e861e3

File tree

2 files changed

+36
-36
lines changed

2 files changed

+36
-36
lines changed

src/java.desktop/macosx/classes/sun/lwawt/macosx/CAccessibility.java

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2011, 2021, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2011, 2022, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* This code is free software; you can redistribute it and/or modify it
@@ -817,6 +817,26 @@ public Object[] call() throws Exception {
817817
}, c);
818818
}
819819

820+
// This method is called from the native in ComboBoxAccessibility.m
821+
private static Accessible getAccessibleComboboxValue(Accessible a, Component c) {
822+
if (a == null) return null;
823+
824+
return invokeAndWait(new Callable<Accessible>() {
825+
@Override
826+
public Accessible call() throws Exception {
827+
AccessibleContext ac = a.getAccessibleContext();
828+
if (ac != null) {
829+
AccessibleSelection as = ac.getAccessibleSelection();
830+
if (as != null) {
831+
return as.getAccessibleSelection(0);
832+
}
833+
}
834+
835+
return null;
836+
}
837+
}, c);
838+
}
839+
820840
@Native private static final int JAVA_AX_ROWS = 1;
821841
@Native private static final int JAVA_AX_COLS = 2;
822842

Lines changed: 15 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/*
2-
* Copyright (c) 2021, Oracle and/or its affiliates. All rights reserved.
3-
* Copyright (c) 2021, JetBrains s.r.o.. All rights reserved.
2+
* Copyright (c) 2022, Oracle and/or its affiliates. All rights reserved.
3+
* Copyright (c) 2022, JetBrains s.r.o.. All rights reserved.
44
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
55
*
66
* This code is free software; you can redistribute it and/or modify it
@@ -37,46 +37,26 @@
3737
GET_STATIC_METHOD_RETURN(sjm_getAccessibleName, sjc_CAccessibility, "getAccessibleName", \
3838
"(Ljavax/accessibility/Accessible;Ljava/awt/Component;)Ljava/lang/String;", ret);
3939

40-
static jmethodID sjm_getAccessibleSelection = NULL;
41-
#define GET_ACCESSIBLESELECTION_METHOD_RETURN(ret) \
42-
GET_CACCESSIBILITY_CLASS_RETURN(ret); \
43-
GET_STATIC_METHOD_RETURN(sjm_getAccessibleSelection, sjc_CAccessibility, "getAccessibleSelection", \
44-
"(Ljavax/accessibility/AccessibleContext;Ljava/awt/Component;)Ljavax/accessibility/AccessibleSelection;", ret);
45-
4640
@implementation ComboBoxAccessibility
4741

48-
// NSAccessibilityElement protocol methods
49-
50-
- (id)accessibilityValue {
42+
- (CommonComponentAccessibility *)accessibleSelection
43+
{
5144
JNIEnv *env = [ThreadUtilities getJNIEnv];
52-
jobject axContext = [self axContextWithEnv:env];
53-
if (axContext == NULL) return nil;
54-
GET_ACCESSIBLESELECTION_METHOD_RETURN(nil);
55-
jobject axSelection = (*env)->CallStaticObjectMethod(env, sjc_CAccessibility, sjm_getAccessibleSelection, axContext, self->fComponent);
56-
CHECK_EXCEPTION();
57-
if (axSelection == NULL) {
58-
return nil;
59-
}
60-
jclass axSelectionClass = (*env)->GetObjectClass(env, axSelection);
61-
DECLARE_METHOD_RETURN(jm_getAccessibleSelection, axSelectionClass, "getAccessibleSelection", "(I)Ljavax/accessibility/Accessible;", nil);
62-
jobject axSelectedChild = (*env)->CallObjectMethod(env, axSelection, jm_getAccessibleSelection, 0);
45+
GET_CACCESSIBILITY_CLASS_RETURN(nil);
46+
DECLARE_STATIC_METHOD_RETURN(sjm_getAccessibleComboboxValue, sjc_CAccessibility, "getAccessibleComboboxValue", "(Ljavax/accessibility/Accessible;Ljava/awt/Component;)Ljavax/accessibility/Accessible;", nil);
47+
jobject axSelectedChild = (*env)->CallStaticObjectMethod(env, sjc_CAccessibility, sjm_getAccessibleComboboxValue, fAccessible, fComponent);
6348
CHECK_EXCEPTION();
64-
(*env)->DeleteLocalRef(env, axSelection);
65-
(*env)->DeleteLocalRef(env, axContext);
6649
if (axSelectedChild == NULL) {
6750
return nil;
6851
}
69-
GET_ACCESSIBLENAME_METHOD_RETURN(nil);
70-
jobject childName = (*env)->CallStaticObjectMethod(env, sjc_CAccessibility, sjm_getAccessibleName, axSelectedChild, fComponent);
71-
CHECK_EXCEPTION();
72-
if (childName == NULL) {
73-
(*env)->DeleteLocalRef(env, axSelectedChild);
74-
return nil;
75-
}
76-
NSString *selectedText = JavaStringToNSString(env, childName);
77-
(*env)->DeleteLocalRef(env, axSelectedChild);
78-
(*env)->DeleteLocalRef(env, childName);
79-
return selectedText;
52+
return [CommonComponentAccessibility createWithAccessible:axSelectedChild withEnv:env withView:fView];
53+
}
54+
55+
// NSAccessibilityElement protocol methods
56+
57+
- (id)accessibilityValue
58+
{
59+
return [[self accessibleSelection] accessibilityLabel];
8060
}
8161

8262
@end

0 commit comments

Comments
 (0)