Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/mobile
Path: blob/master/test/jdk/javax/swing/JProgressBar/8161664/ProgressBarMemoryLeakTest.java
41153 views
1
/*
2
* Copyright (c) 2016, Oracle and/or its affiliates. All rights reserved.
3
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4
*
5
* This code is free software; you can redistribute it and/or modify it
6
* under the terms of the GNU General Public License version 2 only, as
7
* published by the Free Software Foundation.
8
*
9
* This code is distributed in the hope that it will be useful, but WITHOUT
10
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
12
* version 2 for more details (a copy is included in the LICENSE file that
13
* accompanied this code).
14
*
15
* You should have received a copy of the GNU General Public License version
16
* 2 along with this work; if not, write to the Free Software Foundation,
17
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18
*
19
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20
* or visit www.oracle.com if you need additional information or have any
21
* questions.
22
*/
23
/*
24
* @test
25
* @bug 8161664
26
* @summary Memory leak in com.apple.laf.AquaProgressBarUI: removed progress bar still referenced
27
* @library ../../regtesthelpers
28
* @build Util
29
* @key headful
30
* @run main/timeout=300/othervm -Xmx16m ProgressBarMemoryLeakTest
31
*/
32
import java.awt.EventQueue;
33
import java.lang.ref.WeakReference;
34
35
import javax.swing.JFrame;
36
import javax.swing.JPanel;
37
import javax.swing.JProgressBar;
38
import javax.swing.UIManager;
39
import javax.swing.UnsupportedLookAndFeelException;
40
41
public class ProgressBarMemoryLeakTest {
42
43
private static JFrame sFrame;
44
private static WeakReference<JProgressBar> sProgressBar;
45
46
public static void main(String[] args) throws Exception {
47
UIManager.LookAndFeelInfo[] installedLookAndFeels = UIManager.getInstalledLookAndFeels();
48
for ( UIManager.LookAndFeelInfo installedLookAndFeel : installedLookAndFeels ) {
49
executeTestCase(installedLookAndFeel.getClassName());
50
}
51
}
52
53
private static void executeTestCase(String lookAndFeelString) throws Exception{
54
if (tryLookAndFeel(lookAndFeelString)) {
55
EventQueue.invokeAndWait( new Runnable() {
56
@Override
57
public void run() {
58
showUI();
59
}
60
} );
61
EventQueue.invokeAndWait( new Runnable() {
62
@Override
63
public void run() {
64
disposeUI();
65
}
66
} );
67
Util.generateOOME();
68
JProgressBar progressBar = sProgressBar.get();
69
if ( progressBar != null ) {
70
throw new RuntimeException( "Progress bar (using L&F: " + lookAndFeelString + ") should have been GC-ed" );
71
}
72
}
73
}
74
75
private static void showUI(){
76
sFrame = new JFrame();
77
78
JProgressBar progressBar = new JProgressBar();
79
progressBar.setVisible(false);
80
progressBar.setIndeterminate(false);
81
progressBar.setIndeterminate(true);
82
progressBar.setIndeterminate(false);
83
progressBar.setValue(10);
84
progressBar.setString("Progress");
85
86
sFrame.add(progressBar);
87
88
sProgressBar = new WeakReference<>(progressBar);
89
90
sFrame.setSize(200,200);
91
sFrame.setVisible(true);
92
}
93
94
private static void disposeUI(){
95
sFrame.setContentPane(new JPanel());
96
sFrame.dispose();
97
sFrame = null;
98
}
99
100
private static boolean tryLookAndFeel(String lookAndFeelString) throws Exception {
101
try {
102
UIManager.setLookAndFeel(lookAndFeelString);
103
} catch (UnsupportedLookAndFeelException | ClassNotFoundException | InstantiationException | IllegalAccessException e) {
104
return false;
105
}
106
return true;
107
}
108
}
109
110