|
| 1 | +/* |
| 2 | + * Copyright (c) 2024, Oracle and/or its affiliates. All rights reserved. |
| 3 | + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
| 4 | + * |
| 5 | + * This code is free software; you can redistribute it and/or modify it |
| 6 | + * under the terms of the GNU General Public License version 2 only, as |
| 7 | + * published by the Free Software Foundation. |
| 8 | + * |
| 9 | + * This code is distributed in the hope that it will be useful, but WITHOUT |
| 10 | + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
| 11 | + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
| 12 | + * version 2 for more details (a copy is included in the LICENSE file that |
| 13 | + * accompanied this code). |
| 14 | + * |
| 15 | + * You should have received a copy of the GNU General Public License version |
| 16 | + * 2 along with this work; if not, write to the Free Software Foundation, |
| 17 | + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
| 18 | + * |
| 19 | + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
| 20 | + * or visit www.oracle.com if you need additional information or have any |
| 21 | + * questions. |
| 22 | + */ |
| 23 | + |
| 24 | +/* |
| 25 | + * @test |
| 26 | + * @bug 8322239 |
| 27 | + * @summary [macos] a11y : java.lang.NullPointerException is thrown when |
| 28 | + * focus is moved on the JTabbedPane |
| 29 | + * @key headful |
| 30 | + * @run main TabbedPaneNPECheck |
| 31 | + */ |
| 32 | + |
| 33 | +import java.awt.BorderLayout; |
| 34 | +import java.awt.Dimension; |
| 35 | +import java.awt.Point; |
| 36 | +import java.awt.Rectangle; |
| 37 | +import java.lang.reflect.InvocationTargetException; |
| 38 | +import javax.accessibility.Accessible; |
| 39 | +import javax.accessibility.AccessibleComponent; |
| 40 | +import javax.accessibility.AccessibleContext; |
| 41 | +import javax.swing.JFrame; |
| 42 | +import javax.swing.JPanel; |
| 43 | +import javax.swing.JTabbedPane; |
| 44 | +import javax.swing.SwingUtilities; |
| 45 | + |
| 46 | +public class TabbedPaneNPECheck { |
| 47 | + JTabbedPane pane; |
| 48 | + JFrame mainFrame; |
| 49 | + public static void main(String[] args) throws InterruptedException, |
| 50 | + InvocationTargetException { |
| 51 | + TabbedPaneNPECheck me = new TabbedPaneNPECheck(); |
| 52 | + SwingUtilities.invokeAndWait(me::setupGUI); |
| 53 | + try { |
| 54 | + SwingUtilities.invokeAndWait(me::test); |
| 55 | + } finally { |
| 56 | + SwingUtilities.invokeAndWait(me::shutdownGUI); |
| 57 | + } |
| 58 | + } |
| 59 | + |
| 60 | + public void setupGUI() { |
| 61 | + mainFrame = new JFrame("TabbedPaneNPECheck"); |
| 62 | + pane = new JTabbedPane(); |
| 63 | + Dimension panelSize = new Dimension(200, 200); |
| 64 | + for (int i = 0; i < 25; i++) { |
| 65 | + JPanel p = new JPanel(); |
| 66 | + p.setMinimumSize(panelSize); |
| 67 | + p.setMaximumSize(panelSize); |
| 68 | + p.setSize(panelSize); |
| 69 | + pane.addTab("Tab no." + i, p); |
| 70 | + } |
| 71 | + mainFrame.setLayout(new BorderLayout()); |
| 72 | + mainFrame.add(pane, BorderLayout.CENTER); |
| 73 | + mainFrame.setLocationRelativeTo(null); |
| 74 | + mainFrame.setSize(250, 250); |
| 75 | + mainFrame.setVisible(true); |
| 76 | + } |
| 77 | + |
| 78 | + public void test() { |
| 79 | + AccessibleContext context = pane.getAccessibleContext(); |
| 80 | + int nChild = context.getAccessibleChildrenCount(); |
| 81 | + for (int i = 0; i < nChild; i++) { |
| 82 | + Accessible accessible = context.getAccessibleChild(i); |
| 83 | + if (accessible instanceof AccessibleComponent) { |
| 84 | + try { |
| 85 | + AccessibleComponent component = (AccessibleComponent) accessible; |
| 86 | + Point p = component.getLocationOnScreen(); |
| 87 | + Rectangle r = component.getBounds(); |
| 88 | + } catch (NullPointerException npe) { |
| 89 | + throw new RuntimeException("Unexpected NullPointerException " + |
| 90 | + "while getting accessible component bounds: ", npe); |
| 91 | + } |
| 92 | + } |
| 93 | + } |
| 94 | + } |
| 95 | + |
| 96 | + public void shutdownGUI() { |
| 97 | + if (mainFrame != null) { |
| 98 | + mainFrame.setVisible(false); |
| 99 | + mainFrame.dispose(); |
| 100 | + } |
| 101 | + } |
| 102 | +} |
0 commit comments