Path: blob/aarch64-shenandoah-jdk8u272-b10/jdk/test/javax/swing/JFileChooser/6489130/bug6489130.java
38854 views
/*1* Copyright (c) 2009, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation.7*8* This code is distributed in the hope that it will be useful, but WITHOUT9* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or10* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License11* version 2 for more details (a copy is included in the LICENSE file that12* accompanied this code).13*14* You should have received a copy of the GNU General Public License version15* 2 along with this work; if not, write to the Free Software Foundation,16* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.17*18* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA19* or visit www.oracle.com if you need additional information or have any20* questions.21*/2223/* @test24* @bug 648913025* @summary FileChooserDemo hung by keeping pressing Enter key26* @author Pavel Porvatov27@run main bug648913028*/2930import javax.swing.*;31import java.awt.*;32import java.awt.event.ActionEvent;33import java.awt.event.ActionListener;34import java.util.concurrent.CountDownLatch;35import java.util.concurrent.TimeUnit;3637public class bug6489130 {38private final JFileChooser chooser = new JFileChooser();3940private static final CountDownLatch MUX = new CountDownLatch(1);4142private final Timer timer = new Timer(1000, new ActionListener() {43public void actionPerformed(ActionEvent e) {44switch (state) {45case 0:46case 1: {47SwingUtilities.invokeLater(new Runnable() {48public void run() {49chooser.showOpenDialog(null);50}51});5253break;54}5556case 2:57case 3: {58Window[] windows = Frame.getWindows();5960if (windows.length > 0) {61windows[0].dispose();62}6364break;65}6667case 4: {68MUX.countDown();6970break;71}72}7374state++;75}76});7778private int state = 0;7980public static void main(String[] args) throws InterruptedException {81SwingUtilities.invokeLater(new Runnable() {82public void run() {83new bug6489130().run();84}85});8687if (!MUX.await(10, TimeUnit.SECONDS)) {88throw new RuntimeException("Timeout");89}90}9192private void run() {93timer.start();94}95}969798