Skip to content

Commit

Permalink
8286266: [macos] Voice over moving JTable column to be the first colu…
Browse files Browse the repository at this point in the history
…mn JVM crashes

Backport-of: b33c6e52c1ba675efdae6e48a9ff022b2b24513c
  • Loading branch information
GoeLin committed Jul 7, 2022
1 parent 25b7596 commit 05b9400
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 9 deletions.
@@ -1,6 +1,6 @@
/*
* Copyright (c) 2021, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2021, JetBrains s.r.o.. All rights reserved.
* Copyright (c) 2021, 2022, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2021, 2022, JetBrains s.r.o.. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
Expand Down Expand Up @@ -29,6 +29,7 @@
@interface TableAccessibility : CommonComponentAccessibility <NSAccessibilityTable>
{
NSMutableDictionary<NSNumber*, id> *rowCache;
BOOL cacheValid;
}

- (BOOL)isAccessibleChildSelectedFromIndex:(int)index;
Expand Down
@@ -1,6 +1,6 @@
/*
* Copyright (c) 2021, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2021, JetBrains s.r.o.. All rights reserved.
* Copyright (c) 2021, 2022, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2021, 2022, JetBrains s.r.o.. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
Expand Down Expand Up @@ -130,6 +130,15 @@ - (TableRowAccessibility *)createRowWithIndex:(NSUInteger)index
if (rowCache == nil) {
int rowCount = [self accessibilityRowCount];
rowCache = [[NSMutableDictionary<NSNumber*, id> dictionaryWithCapacity:rowCount] retain];
cacheValid = YES;
}

if (!cacheValid) {
for (NSNumber *key in [rowCache allKeys]) {
[[rowCache objectForKey:key] release];
[rowCache removeObjectForKey:key];
}
cacheValid = YES;
}

id row = [rowCache objectForKey:[NSNumber numberWithUnsignedInteger:index]];
Expand Down Expand Up @@ -223,11 +232,7 @@ - (NSArray *)accessibilitySelectedCells
}

- (void)clearCache {
for (NSNumber *key in [rowCache allKeys]) {
[[rowCache objectForKey:key] release];
}
[rowCache release];
rowCache = nil;
cacheValid = NO;
}

@end
Expand Down
28 changes: 28 additions & 0 deletions test/jdk/java/awt/a11y/AccessibleJTableTest.java
Expand Up @@ -76,6 +76,27 @@ public void createUI() {
super.createUI(panel, "AccessibleJTableTest");
}

public void createUIDraggable() {
INSTRUCTIONS = "INSTRUCTIONS:\n"
+ "Check that table is properly updated when column order is changed.\n\n"
+ "Turn screen reader on, and Tab to the table.\n"
+ "Using arrow keys navigate to the last cell in the first row in the table."
+ "Screen reader should announce it as \"Column 3 row 1\"\n\n"
+ "Using mouse drag the header of the last culumn so the last column becomes the first one."
+ "Wait for the screen reader to finish announcing new position in table.\n\n"
+ "If new position in table corresponds to the new table layout ctrl+tab further "
+ "and press PASS, otherwise press FAIL.\n";

JTable table = new JTable(data, columnNames);
JPanel panel = new JPanel();
panel.setLayout(new FlowLayout());
JScrollPane scrollPane = new JScrollPane(table);
panel.add(scrollPane);
panel.setFocusable(false);
exceptionString = "AccessibleJTable test failed!";
super.createUI(panel, "AccessibleJTableTest");
}

public void createUINamed() {
INSTRUCTIONS = "INSTRUCTIONS:\n"
+ "Check a11y of named JTable.\n\n"
Expand Down Expand Up @@ -166,6 +187,13 @@ public static void main(String[] args) throws Exception {
throw new RuntimeException(exceptionString);
}

countDownLatch = test.createCountDownLatch();
SwingUtilities.invokeAndWait(test::createUIDraggable);
countDownLatch.await(15, TimeUnit.MINUTES);
if (!testResult) {
throw new RuntimeException(exceptionString);
}

countDownLatch = test.createCountDownLatch();
SwingUtilities.invokeAndWait(test::createUINamed);
countDownLatch.await(15, TimeUnit.MINUTES);
Expand Down

1 comment on commit 05b9400

@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.