11/*
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.
33 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44 *
55 * This code is free software; you can redistribute it and/or modify it
2121 * questions.
2222 */
2323
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+ */
3235
3336import sun .awt .OSInfo ;
3437import sun .awt .shell .ShellFolder ;
3538
36- import javax . swing .* ;
39+ import java . awt . Dimension ;
3740import java .awt .event .ActionEvent ;
3841import java .awt .event .ActionListener ;
39- import java .awt .*;
4042import java .io .File ;
4143import 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 ;
5471
5572 private ShellFolder folder ;
56-
5773 private Thread thread ;
5874
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()" );
6093 JFrame frame = new JFrame ("bug6798062" );
6194
6295 frame .setSize (400 , 300 );
63- frame .setLocationRelativeTo (null );
6496 frame .setDefaultCloseOperation (JFrame .EXIT_ON_CLOSE );
6597 frame .add (new bug6798062 ().initialize ());
6698
67- frame .setVisible (true );
68- }
69-
70- public void init () {
71- add (initialize ());
99+ return frame ;
72100 }
73101
74102 private JComponent initialize () {
@@ -87,7 +115,7 @@ private JComponent initialize() {
87115 try {
88116 folder = ShellFolder .getShellFolder (new File (tempDir ));
89117 } catch (FileNotFoundException e ) {
90- fail ("Directory " + tempDir + " not found" );
118+ fail ("Directory not found" );
91119 }
92120
93121 slider .setMajorTickSpacing (10 );
@@ -153,7 +181,7 @@ private void setEnabledState(boolean enabled) {
153181 }
154182
155183 private static void fail (String msg ) {
156- throw new RuntimeException (msg );
184+ PassFailJFrame . forceFail (msg );
157185 }
158186
159187 private class MyThread extends Thread {
@@ -169,7 +197,7 @@ private MyThread(int delay, String link) {
169197 try {
170198 linkFolder = ShellFolder .getShellFolder (new File (link ));
171199 } catch (FileNotFoundException e ) {
172- e . printStackTrace ( );
200+ fail ( "File not found" );
173201
174202 linkFolder = null ;
175203 }
@@ -184,7 +212,7 @@ public void run() {
184212 try {
185213 link .getLinkLocation ();
186214 } catch (FileNotFoundException e ) {
187- e . printStackTrace ( );
215+ fail ( "File not found" );
188216 }
189217 }
190218
0 commit comments