1
1
/*
2
- * Copyright (c) 2009, 2015 , Oracle and/or its affiliates. All rights reserved.
2
+ * Copyright (c) 2009, 2024 , Oracle and/or its affiliates. All rights reserved.
3
3
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4
4
*
5
5
* This code is free software; you can redistribute it and/or modify it
21
21
* questions.
22
22
*/
23
23
24
- /* @test %W% %E%
25
- @bug 6798062
26
- @summary Memory Leak on using getFiles of FileSystemView
27
- @author Pavel Porvatov
28
- @modules java.desktop/sun.awt
29
- java.desktop/sun.awt.shell
30
- @run applet/manual=done bug6798062.html
31
- */
24
+ /*
25
+ * @test
26
+ * @bug 6798062
27
+ * @requires (os.family == "windows")
28
+ * @summary Memory Leak on using getFiles of FileSystemView
29
+ * @library /java/awt/regtesthelpers
30
+ * @build PassFailJFrame
31
+ * @modules java.desktop/sun.awt
32
+ * java.desktop/sun.awt.shell
33
+ * @run main/manual bug6798062
34
+ */
32
35
33
36
import sun .awt .OSInfo ;
34
37
import sun .awt .shell .ShellFolder ;
35
38
36
- import javax . swing .* ;
39
+ import java . awt . Dimension ;
37
40
import java .awt .event .ActionEvent ;
38
41
import java .awt .event .ActionListener ;
39
- import java .awt .*;
40
42
import java .io .File ;
41
43
import java .io .FileNotFoundException ;
42
-
43
- public class bug6798062 extends JApplet {
44
-
45
- private final JSlider slider = new JSlider (0 , 100 );
46
-
47
- private final JTextField tfLink = new JTextField ();
48
-
49
- private final JButton btnStart = new JButton ("Start" );
50
-
51
- private final JButton btnStop = new JButton ("Stop" );
52
-
53
- private final JButton btnGC = new JButton ("Run System.gc()" );
44
+ import javax .swing .BoxLayout ;
45
+ import javax .swing .JButton ;
46
+ import javax .swing .JComponent ;
47
+ import javax .swing .JFrame ;
48
+ import javax .swing .JLabel ;
49
+ import javax .swing .JPanel ;
50
+ import javax .swing .JSlider ;
51
+ import javax .swing .JTextField ;
52
+
53
+ public class bug6798062 {
54
+
55
+ private static final String INSTRUCTIONS = """
56
+ The test is suitable only for Windows.
57
+
58
+ 1. Create a shortcut (.lnk) file
59
+ 2. Copy path to the shortcut (.lnk file) into TextField
60
+ 3. Run the Windows Task Manager. Select the Processes tab and find the java process
61
+ 4. Press the Start button in the test window
62
+ 5. Wait several minutes and observe in the Windows Task Manager
63
+ that Memory Usage of java process is not increasing
64
+ If memory usage is increasing, click Fail else click Pass.""" ;
65
+
66
+ private static JSlider slider ;
67
+ private static JTextField tfLink ;
68
+ private static JButton btnStart ;
69
+ private static JButton btnStop ;
70
+ private static JButton btnGC ;
54
71
55
72
private ShellFolder folder ;
56
-
57
73
private Thread thread ;
58
74
59
- public static void main (String [] args ) {
75
+ public static void main (String [] args ) throws Exception {
76
+ PassFailJFrame .builder ()
77
+ .title ("JFileChooser Instructions" )
78
+ .instructions (INSTRUCTIONS )
79
+ .testTimeOut (10 )
80
+ .rows (10 )
81
+ .columns (35 )
82
+ .testUI (bug6798062 ::createUI )
83
+ .build ()
84
+ .awaitAndCheck ();
85
+ }
86
+
87
+ private static JFrame createUI () {
88
+ slider = new JSlider (0 , 100 );
89
+ tfLink = new JTextField ();
90
+ btnStart = new JButton ("Start" );
91
+ btnStop = new JButton ("Stop" );
92
+ btnGC = new JButton ("Run System.gc()" );
60
93
JFrame frame = new JFrame ("bug6798062" );
61
94
62
95
frame .setSize (400 , 300 );
63
- frame .setLocationRelativeTo (null );
64
96
frame .setDefaultCloseOperation (JFrame .EXIT_ON_CLOSE );
65
97
frame .add (new bug6798062 ().initialize ());
66
98
67
- frame .setVisible (true );
68
- }
69
-
70
- public void init () {
71
- add (initialize ());
99
+ return frame ;
72
100
}
73
101
74
102
private JComponent initialize () {
@@ -87,7 +115,7 @@ private JComponent initialize() {
87
115
try {
88
116
folder = ShellFolder .getShellFolder (new File (tempDir ));
89
117
} catch (FileNotFoundException e ) {
90
- fail ("Directory " + tempDir + " not found" );
118
+ fail ("Directory not found" );
91
119
}
92
120
93
121
slider .setMajorTickSpacing (10 );
@@ -153,7 +181,7 @@ private void setEnabledState(boolean enabled) {
153
181
}
154
182
155
183
private static void fail (String msg ) {
156
- throw new RuntimeException (msg );
184
+ PassFailJFrame . forceFail (msg );
157
185
}
158
186
159
187
private class MyThread extends Thread {
@@ -169,7 +197,7 @@ private MyThread(int delay, String link) {
169
197
try {
170
198
linkFolder = ShellFolder .getShellFolder (new File (link ));
171
199
} catch (FileNotFoundException e ) {
172
- e . printStackTrace ( );
200
+ fail ( "File not found" );
173
201
174
202
linkFolder = null ;
175
203
}
@@ -184,7 +212,7 @@ public void run() {
184
212
try {
185
213
link .getLinkLocation ();
186
214
} catch (FileNotFoundException e ) {
187
- e . printStackTrace ( );
215
+ fail ( "File not found" );
188
216
}
189
217
}
190
218
0 commit comments