author | goetz |
Tue, 14 Jun 2016 10:44:59 +0200 | |
changeset 39056 | d99e63b6d962 |
parent 5957 | 73a2c01f5843 |
permissions | -rw-r--r-- |
5957
73a2c01f5843
6520101: FileChooser will cause OutOfMemory when application will run long time
rupashka
parents:
diff
changeset
|
1 |
/* |
39056
d99e63b6d962
8159690: [TESTBUG] Mark headful tests with @key headful.
goetz
parents:
5957
diff
changeset
|
2 |
* Copyright (c) 2010, 2016, Oracle and/or its affiliates. All rights reserved. |
5957
73a2c01f5843
6520101: FileChooser will cause OutOfMemory when application will run long time
rupashka
parents:
diff
changeset
|
3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
73a2c01f5843
6520101: FileChooser will cause OutOfMemory when application will run long time
rupashka
parents:
diff
changeset
|
4 |
* |
73a2c01f5843
6520101: FileChooser will cause OutOfMemory when application will run long time
rupashka
parents:
diff
changeset
|
5 |
* This code is free software; you can redistribute it and/or modify it |
73a2c01f5843
6520101: FileChooser will cause OutOfMemory when application will run long time
rupashka
parents:
diff
changeset
|
6 |
* under the terms of the GNU General Public License version 2 only, as |
73a2c01f5843
6520101: FileChooser will cause OutOfMemory when application will run long time
rupashka
parents:
diff
changeset
|
7 |
* published by the Free Software Foundation. |
73a2c01f5843
6520101: FileChooser will cause OutOfMemory when application will run long time
rupashka
parents:
diff
changeset
|
8 |
* |
73a2c01f5843
6520101: FileChooser will cause OutOfMemory when application will run long time
rupashka
parents:
diff
changeset
|
9 |
* This code is distributed in the hope that it will be useful, but WITHOUT |
73a2c01f5843
6520101: FileChooser will cause OutOfMemory when application will run long time
rupashka
parents:
diff
changeset
|
10 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
73a2c01f5843
6520101: FileChooser will cause OutOfMemory when application will run long time
rupashka
parents:
diff
changeset
|
11 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
73a2c01f5843
6520101: FileChooser will cause OutOfMemory when application will run long time
rupashka
parents:
diff
changeset
|
12 |
* version 2 for more details (a copy is included in the LICENSE file that |
73a2c01f5843
6520101: FileChooser will cause OutOfMemory when application will run long time
rupashka
parents:
diff
changeset
|
13 |
* accompanied this code). |
73a2c01f5843
6520101: FileChooser will cause OutOfMemory when application will run long time
rupashka
parents:
diff
changeset
|
14 |
* |
73a2c01f5843
6520101: FileChooser will cause OutOfMemory when application will run long time
rupashka
parents:
diff
changeset
|
15 |
* You should have received a copy of the GNU General Public License version |
73a2c01f5843
6520101: FileChooser will cause OutOfMemory when application will run long time
rupashka
parents:
diff
changeset
|
16 |
* 2 along with this work; if not, write to the Free Software Foundation, |
73a2c01f5843
6520101: FileChooser will cause OutOfMemory when application will run long time
rupashka
parents:
diff
changeset
|
17 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
73a2c01f5843
6520101: FileChooser will cause OutOfMemory when application will run long time
rupashka
parents:
diff
changeset
|
18 |
* |
73a2c01f5843
6520101: FileChooser will cause OutOfMemory when application will run long time
rupashka
parents:
diff
changeset
|
19 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
73a2c01f5843
6520101: FileChooser will cause OutOfMemory when application will run long time
rupashka
parents:
diff
changeset
|
20 |
* or visit www.oracle.com if you need additional information or have any |
73a2c01f5843
6520101: FileChooser will cause OutOfMemory when application will run long time
rupashka
parents:
diff
changeset
|
21 |
* questions. |
73a2c01f5843
6520101: FileChooser will cause OutOfMemory when application will run long time
rupashka
parents:
diff
changeset
|
22 |
*/ |
73a2c01f5843
6520101: FileChooser will cause OutOfMemory when application will run long time
rupashka
parents:
diff
changeset
|
23 |
|
73a2c01f5843
6520101: FileChooser will cause OutOfMemory when application will run long time
rupashka
parents:
diff
changeset
|
24 |
/* |
73a2c01f5843
6520101: FileChooser will cause OutOfMemory when application will run long time
rupashka
parents:
diff
changeset
|
25 |
* @test @(#)bug6520101 |
39056
d99e63b6d962
8159690: [TESTBUG] Mark headful tests with @key headful.
goetz
parents:
5957
diff
changeset
|
26 |
* @key headful |
5957
73a2c01f5843
6520101: FileChooser will cause OutOfMemory when application will run long time
rupashka
parents:
diff
changeset
|
27 |
* @bug 6520101 |
73a2c01f5843
6520101: FileChooser will cause OutOfMemory when application will run long time
rupashka
parents:
diff
changeset
|
28 |
* @summary JFileChooser throws OOM in 1.4.2, 5.0u4 and 1.6.0 |
73a2c01f5843
6520101: FileChooser will cause OutOfMemory when application will run long time
rupashka
parents:
diff
changeset
|
29 |
* @author Praveen Gupta |
73a2c01f5843
6520101: FileChooser will cause OutOfMemory when application will run long time
rupashka
parents:
diff
changeset
|
30 |
* @run main/othervm/timeout=600 -Xmx8m -verify bug6520101 |
73a2c01f5843
6520101: FileChooser will cause OutOfMemory when application will run long time
rupashka
parents:
diff
changeset
|
31 |
*/ |
73a2c01f5843
6520101: FileChooser will cause OutOfMemory when application will run long time
rupashka
parents:
diff
changeset
|
32 |
|
73a2c01f5843
6520101: FileChooser will cause OutOfMemory when application will run long time
rupashka
parents:
diff
changeset
|
33 |
import javax.swing.*; |
73a2c01f5843
6520101: FileChooser will cause OutOfMemory when application will run long time
rupashka
parents:
diff
changeset
|
34 |
import java.awt.event.ActionEvent; |
73a2c01f5843
6520101: FileChooser will cause OutOfMemory when application will run long time
rupashka
parents:
diff
changeset
|
35 |
import java.awt.event.ActionListener; |
73a2c01f5843
6520101: FileChooser will cause OutOfMemory when application will run long time
rupashka
parents:
diff
changeset
|
36 |
|
73a2c01f5843
6520101: FileChooser will cause OutOfMemory when application will run long time
rupashka
parents:
diff
changeset
|
37 |
public class bug6520101 implements Runnable { |
73a2c01f5843
6520101: FileChooser will cause OutOfMemory when application will run long time
rupashka
parents:
diff
changeset
|
38 |
|
73a2c01f5843
6520101: FileChooser will cause OutOfMemory when application will run long time
rupashka
parents:
diff
changeset
|
39 |
private static final int ATTEMPTS = 500; |
73a2c01f5843
6520101: FileChooser will cause OutOfMemory when application will run long time
rupashka
parents:
diff
changeset
|
40 |
private static final int INTERVAL = 100; |
73a2c01f5843
6520101: FileChooser will cause OutOfMemory when application will run long time
rupashka
parents:
diff
changeset
|
41 |
|
73a2c01f5843
6520101: FileChooser will cause OutOfMemory when application will run long time
rupashka
parents:
diff
changeset
|
42 |
private static final boolean ALWAYS_NEW_INSTANCE = false; |
73a2c01f5843
6520101: FileChooser will cause OutOfMemory when application will run long time
rupashka
parents:
diff
changeset
|
43 |
private static final boolean DO_GC_EACH_INTERVAL = false; |
73a2c01f5843
6520101: FileChooser will cause OutOfMemory when application will run long time
rupashka
parents:
diff
changeset
|
44 |
private static final boolean UPDATE_UI_EACH_INTERVAL = true; |
73a2c01f5843
6520101: FileChooser will cause OutOfMemory when application will run long time
rupashka
parents:
diff
changeset
|
45 |
private static final boolean AUTO_CLOSE_DIALOG = true; |
73a2c01f5843
6520101: FileChooser will cause OutOfMemory when application will run long time
rupashka
parents:
diff
changeset
|
46 |
|
73a2c01f5843
6520101: FileChooser will cause OutOfMemory when application will run long time
rupashka
parents:
diff
changeset
|
47 |
private static JFileChooser CHOOSER; |
73a2c01f5843
6520101: FileChooser will cause OutOfMemory when application will run long time
rupashka
parents:
diff
changeset
|
48 |
|
73a2c01f5843
6520101: FileChooser will cause OutOfMemory when application will run long time
rupashka
parents:
diff
changeset
|
49 |
public static void main(String[] args) throws Exception { |
73a2c01f5843
6520101: FileChooser will cause OutOfMemory when application will run long time
rupashka
parents:
diff
changeset
|
50 |
UIManager.setLookAndFeel("com.sun.java.swing.plaf.motif.MotifLookAndFeel"); |
73a2c01f5843
6520101: FileChooser will cause OutOfMemory when application will run long time
rupashka
parents:
diff
changeset
|
51 |
|
73a2c01f5843
6520101: FileChooser will cause OutOfMemory when application will run long time
rupashka
parents:
diff
changeset
|
52 |
for (int i = 0; i < ATTEMPTS; i++) { |
73a2c01f5843
6520101: FileChooser will cause OutOfMemory when application will run long time
rupashka
parents:
diff
changeset
|
53 |
doAttempt(); |
73a2c01f5843
6520101: FileChooser will cause OutOfMemory when application will run long time
rupashka
parents:
diff
changeset
|
54 |
} |
73a2c01f5843
6520101: FileChooser will cause OutOfMemory when application will run long time
rupashka
parents:
diff
changeset
|
55 |
|
73a2c01f5843
6520101: FileChooser will cause OutOfMemory when application will run long time
rupashka
parents:
diff
changeset
|
56 |
System.out.println("Test passed successfully"); |
73a2c01f5843
6520101: FileChooser will cause OutOfMemory when application will run long time
rupashka
parents:
diff
changeset
|
57 |
} |
73a2c01f5843
6520101: FileChooser will cause OutOfMemory when application will run long time
rupashka
parents:
diff
changeset
|
58 |
|
73a2c01f5843
6520101: FileChooser will cause OutOfMemory when application will run long time
rupashka
parents:
diff
changeset
|
59 |
private static void doAttempt() throws InterruptedException { |
73a2c01f5843
6520101: FileChooser will cause OutOfMemory when application will run long time
rupashka
parents:
diff
changeset
|
60 |
if (ALWAYS_NEW_INSTANCE || (CHOOSER == null)) |
73a2c01f5843
6520101: FileChooser will cause OutOfMemory when application will run long time
rupashka
parents:
diff
changeset
|
61 |
CHOOSER = new JFileChooser("."); |
73a2c01f5843
6520101: FileChooser will cause OutOfMemory when application will run long time
rupashka
parents:
diff
changeset
|
62 |
|
73a2c01f5843
6520101: FileChooser will cause OutOfMemory when application will run long time
rupashka
parents:
diff
changeset
|
63 |
if (UPDATE_UI_EACH_INTERVAL) { |
73a2c01f5843
6520101: FileChooser will cause OutOfMemory when application will run long time
rupashka
parents:
diff
changeset
|
64 |
CHOOSER.updateUI(); |
73a2c01f5843
6520101: FileChooser will cause OutOfMemory when application will run long time
rupashka
parents:
diff
changeset
|
65 |
} |
73a2c01f5843
6520101: FileChooser will cause OutOfMemory when application will run long time
rupashka
parents:
diff
changeset
|
66 |
|
73a2c01f5843
6520101: FileChooser will cause OutOfMemory when application will run long time
rupashka
parents:
diff
changeset
|
67 |
if (AUTO_CLOSE_DIALOG) { |
73a2c01f5843
6520101: FileChooser will cause OutOfMemory when application will run long time
rupashka
parents:
diff
changeset
|
68 |
Thread t = new Thread(new bug6520101(CHOOSER)); |
73a2c01f5843
6520101: FileChooser will cause OutOfMemory when application will run long time
rupashka
parents:
diff
changeset
|
69 |
t.start(); |
73a2c01f5843
6520101: FileChooser will cause OutOfMemory when application will run long time
rupashka
parents:
diff
changeset
|
70 |
CHOOSER.showOpenDialog(null); |
73a2c01f5843
6520101: FileChooser will cause OutOfMemory when application will run long time
rupashka
parents:
diff
changeset
|
71 |
t.join(); |
73a2c01f5843
6520101: FileChooser will cause OutOfMemory when application will run long time
rupashka
parents:
diff
changeset
|
72 |
} else { |
73a2c01f5843
6520101: FileChooser will cause OutOfMemory when application will run long time
rupashka
parents:
diff
changeset
|
73 |
CHOOSER.showOpenDialog(null); |
73a2c01f5843
6520101: FileChooser will cause OutOfMemory when application will run long time
rupashka
parents:
diff
changeset
|
74 |
} |
73a2c01f5843
6520101: FileChooser will cause OutOfMemory when application will run long time
rupashka
parents:
diff
changeset
|
75 |
|
73a2c01f5843
6520101: FileChooser will cause OutOfMemory when application will run long time
rupashka
parents:
diff
changeset
|
76 |
if (DO_GC_EACH_INTERVAL) { |
73a2c01f5843
6520101: FileChooser will cause OutOfMemory when application will run long time
rupashka
parents:
diff
changeset
|
77 |
System.gc(); |
73a2c01f5843
6520101: FileChooser will cause OutOfMemory when application will run long time
rupashka
parents:
diff
changeset
|
78 |
} |
73a2c01f5843
6520101: FileChooser will cause OutOfMemory when application will run long time
rupashka
parents:
diff
changeset
|
79 |
} |
73a2c01f5843
6520101: FileChooser will cause OutOfMemory when application will run long time
rupashka
parents:
diff
changeset
|
80 |
|
73a2c01f5843
6520101: FileChooser will cause OutOfMemory when application will run long time
rupashka
parents:
diff
changeset
|
81 |
private final JFileChooser chooser; |
73a2c01f5843
6520101: FileChooser will cause OutOfMemory when application will run long time
rupashka
parents:
diff
changeset
|
82 |
|
73a2c01f5843
6520101: FileChooser will cause OutOfMemory when application will run long time
rupashka
parents:
diff
changeset
|
83 |
bug6520101(JFileChooser chooser) { |
73a2c01f5843
6520101: FileChooser will cause OutOfMemory when application will run long time
rupashka
parents:
diff
changeset
|
84 |
this.chooser = chooser; |
73a2c01f5843
6520101: FileChooser will cause OutOfMemory when application will run long time
rupashka
parents:
diff
changeset
|
85 |
} |
73a2c01f5843
6520101: FileChooser will cause OutOfMemory when application will run long time
rupashka
parents:
diff
changeset
|
86 |
|
73a2c01f5843
6520101: FileChooser will cause OutOfMemory when application will run long time
rupashka
parents:
diff
changeset
|
87 |
public void run() { |
73a2c01f5843
6520101: FileChooser will cause OutOfMemory when application will run long time
rupashka
parents:
diff
changeset
|
88 |
while (!this.chooser.isShowing()) { |
73a2c01f5843
6520101: FileChooser will cause OutOfMemory when application will run long time
rupashka
parents:
diff
changeset
|
89 |
try { |
73a2c01f5843
6520101: FileChooser will cause OutOfMemory when application will run long time
rupashka
parents:
diff
changeset
|
90 |
Thread.sleep(30); |
73a2c01f5843
6520101: FileChooser will cause OutOfMemory when application will run long time
rupashka
parents:
diff
changeset
|
91 |
} catch (InterruptedException exception) { |
73a2c01f5843
6520101: FileChooser will cause OutOfMemory when application will run long time
rupashka
parents:
diff
changeset
|
92 |
exception.printStackTrace(); |
73a2c01f5843
6520101: FileChooser will cause OutOfMemory when application will run long time
rupashka
parents:
diff
changeset
|
93 |
} |
73a2c01f5843
6520101: FileChooser will cause OutOfMemory when application will run long time
rupashka
parents:
diff
changeset
|
94 |
} |
73a2c01f5843
6520101: FileChooser will cause OutOfMemory when application will run long time
rupashka
parents:
diff
changeset
|
95 |
|
73a2c01f5843
6520101: FileChooser will cause OutOfMemory when application will run long time
rupashka
parents:
diff
changeset
|
96 |
Timer timer = new Timer(INTERVAL, new ActionListener() { |
73a2c01f5843
6520101: FileChooser will cause OutOfMemory when application will run long time
rupashka
parents:
diff
changeset
|
97 |
public void actionPerformed(ActionEvent e) { |
73a2c01f5843
6520101: FileChooser will cause OutOfMemory when application will run long time
rupashka
parents:
diff
changeset
|
98 |
chooser.cancelSelection(); |
73a2c01f5843
6520101: FileChooser will cause OutOfMemory when application will run long time
rupashka
parents:
diff
changeset
|
99 |
} |
73a2c01f5843
6520101: FileChooser will cause OutOfMemory when application will run long time
rupashka
parents:
diff
changeset
|
100 |
}); |
73a2c01f5843
6520101: FileChooser will cause OutOfMemory when application will run long time
rupashka
parents:
diff
changeset
|
101 |
|
73a2c01f5843
6520101: FileChooser will cause OutOfMemory when application will run long time
rupashka
parents:
diff
changeset
|
102 |
timer.setRepeats(false); |
73a2c01f5843
6520101: FileChooser will cause OutOfMemory when application will run long time
rupashka
parents:
diff
changeset
|
103 |
timer.start(); |
73a2c01f5843
6520101: FileChooser will cause OutOfMemory when application will run long time
rupashka
parents:
diff
changeset
|
104 |
} |
73a2c01f5843
6520101: FileChooser will cause OutOfMemory when application will run long time
rupashka
parents:
diff
changeset
|
105 |
} |