Skip to content

Commit

Permalink
8277396: [TESTBUG] In DefaultButtonModelCrashTest.java, frame is acce…
Browse files Browse the repository at this point in the history
…ssed from main thread

Backport-of: b310f301efd5390408fb56b62cc09eb9a1604413
  • Loading branch information
TheRealMDoerr committed Apr 27, 2022
1 parent 11d3c00 commit 6f109a4
Showing 1 changed file with 15 additions and 14 deletions.
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2017, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2017, 2021, Oracle and/or its affiliates. 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 All @@ -21,32 +21,28 @@
* questions.
*/

/**
/*
* @test
* @bug 8182577
* @summary Verifies if moving focus via custom ButtonModel causes crash
* @summary Verifies if moving focus to JToggleButton with DefaultButtonModel
* that is added to a ButtonGroup doesn't throw ClassCastException
* @key headful
* @run main DefaultButtonModelCrashTest
*/

import java.awt.BorderLayout;
import java.awt.Container;
import java.awt.Point;
import java.awt.Robot;
import java.awt.event.KeyEvent;
import javax.swing.ButtonModel;
import javax.swing.DefaultButtonModel;
import javax.swing.JCheckBox;
import javax.swing.JComponent;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.JTextField;
import javax.swing.SwingUtilities;

public class DefaultButtonModelCrashTest {
private JFrame frame = null;
private JPanel panel;
private volatile Point p = null;

public static void main(String[] args) throws Exception {
new DefaultButtonModelCrashTest();
Expand All @@ -58,29 +54,34 @@ public DefaultButtonModelCrashTest() throws Exception {
robot.setAutoDelay(200);
SwingUtilities.invokeAndWait(() -> go());
robot.waitForIdle();
robot.delay(1000);
robot.keyPress(KeyEvent.VK_TAB);
robot.keyRelease(KeyEvent.VK_TAB);
robot.delay(100);
robot.keyPress(KeyEvent.VK_TAB);
robot.keyRelease(KeyEvent.VK_TAB);
} finally {
if (frame != null) { SwingUtilities.invokeAndWait(()->frame.dispose()); }
SwingUtilities.invokeAndWait(() -> {
if (frame != null) {
frame.dispose();
}
});
}
}

private void go() {

frame = new JFrame();
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
Container contentPane = frame.getContentPane();
ButtonModel model = new DefaultButtonModel();

ButtonModel model = new DefaultButtonModel();
JCheckBox check = new JCheckBox("a bit broken");
check.setModel(model);
panel = new JPanel(new BorderLayout());

JPanel panel = new JPanel(new BorderLayout());
panel.add(new JTextField("Press Tab (twice?)"), BorderLayout.NORTH);
panel.add(check);
contentPane.add(panel);

frame.getContentPane().add(panel);
frame.setLocationRelativeTo(null);
frame.pack();
frame.setVisible(true);
Expand Down

1 comment on commit 6f109a4

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