Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/openjdk-multiarch-jdk8u
Path: blob/aarch64-shenandoah-jdk8u272-b10/jdk/test/javax/swing/JProgressBar/8161664/ProgressBarMemoryLeakTest.java
38918 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
* @run main/timeout=300/othervm -Xmx16m ProgressBarMemoryLeakTest
30
*/
31
import java.awt.EventQueue;
32
import java.lang.ref.WeakReference;
33
34
import javax.swing.JFrame;
35
import javax.swing.JPanel;
36
import javax.swing.JProgressBar;
37
import javax.swing.UIManager;
38
import javax.swing.UnsupportedLookAndFeelException;
39
40
public class ProgressBarMemoryLeakTest {
41
42
private static JFrame sFrame;
43
private static WeakReference<JProgressBar> sProgressBar;
44
45
public static void main(String[] args) throws Exception {
46
UIManager.LookAndFeelInfo[] installedLookAndFeels = UIManager.getInstalledLookAndFeels();
47
for ( UIManager.LookAndFeelInfo installedLookAndFeel : installedLookAndFeels ) {
48
executeTestCase(installedLookAndFeel.getClassName());
49
}
50
}
51
52
private static void executeTestCase(String lookAndFeelString) throws Exception{
53
if (tryLookAndFeel(lookAndFeelString)) {
54
EventQueue.invokeAndWait( new Runnable() {
55
@Override
56
public void run() {
57
showUI();
58
}
59
} );
60
EventQueue.invokeAndWait( new Runnable() {
61
@Override
62
public void run() {
63
disposeUI();
64
}
65
} );
66
Util.generateOOME();
67
JProgressBar progressBar = sProgressBar.get();
68
if ( progressBar != null ) {
69
throw new RuntimeException( "Progress bar (using L&F: " + lookAndFeelString + ") should have been GC-ed" );
70
}
71
}
72
}
73
74
private static void showUI(){
75
sFrame = new JFrame();
76
77
JProgressBar progressBar = new JProgressBar();
78
progressBar.setVisible(false);
79
progressBar.setIndeterminate(false);
80
progressBar.setIndeterminate(true);
81
progressBar.setIndeterminate(false);
82
progressBar.setValue(10);
83
progressBar.setString("Progress");
84
85
sFrame.add(progressBar);
86
87
sProgressBar = new WeakReference<>(progressBar);
88
89
sFrame.setSize(200,200);
90
sFrame.setVisible(true);
91
}
92
93
private static void disposeUI(){
94
sFrame.setContentPane(new JPanel());
95
sFrame.dispose();
96
sFrame = null;
97
}
98
99
private static boolean tryLookAndFeel(String lookAndFeelString) throws Exception {
100
try {
101
UIManager.setLookAndFeel(lookAndFeelString);
102
} catch (UnsupportedLookAndFeelException | ClassNotFoundException | InstantiationException | IllegalAccessException e) {
103
return false;
104
}
105
return true;
106
}
107
}
108
109