Skip to content

Commit 8352618

Browse files
Anton Tarasovpull[bot]
Anton Tarasov
authored andcommitted
8278612: [macos] test/jdk/java/awt/dnd/RemoveDropTargetCrashTest crashes with VoiceOver on macOS
Reviewed-by: serb, kizune
1 parent daca753 commit 8352618

File tree

3 files changed

+28
-8
lines changed

3 files changed

+28
-8
lines changed

src/java.desktop/macosx/native/libawt_lwawt/awt/a11y/CommonComponentAccessibility.h

+1
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,7 @@
8383
- (NSView* _Nonnull)view;
8484
- (NSWindow* _Nonnull)window;
8585
- (id _Nonnull)parent;
86+
- (CommonComponentAccessibility* _Nullable)typeSafeParent;
8687
- (NSString* _Nonnull)javaRole;
8788

8889
- (BOOL)isMenu;

src/java.desktop/macosx/native/libawt_lwawt/awt/a11y/CommonComponentAccessibility.m

+19-3
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,11 @@ - (BOOL)isSelected:(JNIEnv *)env
9595
return NO;
9696
}
9797

98-
return isChildSelected(env, ((CommonComponentAccessibility *)[self parent])->fAccessible, fIndex, fComponent);
98+
CommonComponentAccessibility* parent = [self typeSafeParent];
99+
if (parent != nil) {
100+
return isChildSelected(env, parent->fAccessible, fIndex, fComponent);
101+
}
102+
return NO;
99103
}
100104

101105
- (BOOL)isSelectable:(JNIEnv *)env
@@ -708,6 +712,15 @@ - (id)parent
708712
return fParent;
709713
}
710714

715+
- (CommonComponentAccessibility *)typeSafeParent
716+
{
717+
id parent = [self parent];
718+
if ([parent isKindOfClass:[CommonComponentAccessibility class]]) {
719+
return (CommonComponentAccessibility*)parent;
720+
}
721+
return nil;
722+
}
723+
711724
- (NSString *)javaRole
712725
{
713726
if(fJavaRole == nil) {
@@ -824,11 +837,13 @@ - (NSAccessibilityRole)accessibilityRole
824837
if (fNSRole == nil) {
825838
NSString *javaRole = [self javaRole];
826839
fNSRole = [sRoles objectForKey:javaRole];
840+
CommonComponentAccessibility* parent = [self typeSafeParent];
827841
// The sRoles NSMutableDictionary maps popupmenu to Mac's popup button.
828842
// JComboBox behavior currently relies on this. However this is not the
829843
// proper mapping for a JPopupMenu so fix that.
830844
if ( [javaRole isEqualToString:@"popupmenu"] &&
831-
![[[self parent] javaRole] isEqualToString:@"combobox"] ) {
845+
parent != nil &&
846+
![[parent javaRole] isEqualToString:@"combobox"] ) {
832847
fNSRole = NSAccessibilityMenuRole;
833848
}
834849
if (fNSRole == nil) {
@@ -1025,8 +1040,9 @@ - (id)accessibilityValue
10251040
// This may change when later fixing issues which currently
10261041
// exist for combo boxes, but for now the following is only
10271042
// for JPopupMenus, not for combobox menus.
1028-
id parent = [self parent];
1043+
id parent = [self typeSafeParent];
10291044
if ( [[self javaRole] isEqualToString:@"popupmenu"] &&
1045+
parent != nil &&
10301046
![[parent javaRole] isEqualToString:@"combobox"] ) {
10311047
NSArray *children =
10321048
[CommonComponentAccessibility childrenOfParent:self

src/java.desktop/macosx/native/libawt_lwawt/awt/a11y/TabButtonAccessibility.m

+8-5
Original file line numberDiff line numberDiff line change
@@ -59,11 +59,14 @@ - (void)dealloc
5959
- (jobject)tabGroup
6060
{
6161
if (fTabGroupAxContext == NULL) {
62-
JNIEnv* env = [ThreadUtilities getJNIEnv];
63-
jobject tabGroupAxContext = [(CommonComponentAccessibility *)[self parent] axContextWithEnv:env];
64-
fTabGroupAxContext = (*env)->NewWeakGlobalRef(env, tabGroupAxContext);
65-
CHECK_EXCEPTION();
66-
(*env)->DeleteLocalRef(env, tabGroupAxContext);
62+
CommonComponentAccessibility* parent = [self typeSafeParent];
63+
if (parent != nil) {
64+
JNIEnv *env = [ThreadUtilities getJNIEnv];
65+
jobject tabGroupAxContext = [parent axContextWithEnv:env];
66+
fTabGroupAxContext = (*env)->NewWeakGlobalRef(env, tabGroupAxContext);
67+
CHECK_EXCEPTION();
68+
(*env)->DeleteLocalRef(env, tabGroupAxContext);
69+
}
6770
}
6871
return fTabGroupAxContext;
6972
}

0 commit comments

Comments
 (0)