Path: blob/master/test/jdk/javax/swing/JFileChooser/6520101/bug6520101.java
41155 views
/*1* Copyright (c) 2010, 2016, 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/*24* @test25* @key headful26* @bug 652010127* @summary JFileChooser throws OOM in 1.4.2, 5.0u4 and 1.6.028* @author Praveen Gupta29* @run main/othervm/timeout=600 -Xmx8m -verify bug652010130*/3132import javax.swing.*;33import java.awt.event.ActionEvent;34import java.awt.event.ActionListener;3536public class bug6520101 implements Runnable {3738private static final int ATTEMPTS = 500;39private static final int INTERVAL = 100;4041private static final boolean ALWAYS_NEW_INSTANCE = false;42private static final boolean DO_GC_EACH_INTERVAL = false;43private static final boolean UPDATE_UI_EACH_INTERVAL = true;44private static final boolean AUTO_CLOSE_DIALOG = true;4546private static JFileChooser CHOOSER;4748public static void main(String[] args) throws Exception {49UIManager.setLookAndFeel("com.sun.java.swing.plaf.motif.MotifLookAndFeel");5051for (int i = 0; i < ATTEMPTS; i++) {52doAttempt();53}5455System.out.println("Test passed successfully");56}5758private static void doAttempt() throws InterruptedException {59if (ALWAYS_NEW_INSTANCE || (CHOOSER == null))60CHOOSER = new JFileChooser(".");6162if (UPDATE_UI_EACH_INTERVAL) {63CHOOSER.updateUI();64}6566if (AUTO_CLOSE_DIALOG) {67Thread t = new Thread(new bug6520101(CHOOSER));68t.start();69CHOOSER.showOpenDialog(null);70t.join();71} else {72CHOOSER.showOpenDialog(null);73}7475if (DO_GC_EACH_INTERVAL) {76System.gc();77}78}7980private final JFileChooser chooser;8182bug6520101(JFileChooser chooser) {83this.chooser = chooser;84}8586public void run() {87while (!this.chooser.isShowing()) {88try {89Thread.sleep(30);90} catch (InterruptedException exception) {91exception.printStackTrace();92}93}9495Timer timer = new Timer(INTERVAL, new ActionListener() {96public void actionPerformed(ActionEvent e) {97chooser.cancelSelection();98}99});100101timer.setRepeats(false);102timer.start();103}104}105106107