Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

JDK-8277396: [TESTBUG] In DefaultButtonModelCrashTest.java, frame is accessed from main thread #6455

Closed
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -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
@@ -21,32 +21,28 @@
* questions.
*/

/**
/*
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

With double asterisk, it's highlighted as a warning by my IDE: Dangling Javadoc comment.
I prefer fixing it.

* @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();
@@ -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);