1
1
/*
2
- * Copyright (c) 2017, Oracle and/or its affiliates. All rights reserved.
2
+ * Copyright (c) 2017, 2020, 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
27
27
* @summary FileSystemView.isDrive(File) memory leak on "C:\" file reference
28
28
* @modules java.desktop/sun.awt.shell
29
29
* @requires (os.family == "windows")
30
- * @run main/othervm -Xmx8m FileSystemViewMemoryLeak
30
+ * @run main/othervm/timeout=320 -Xmx8m FileSystemViewMemoryLeak
31
31
*/
32
32
import java .io .File ;
33
33
import java .text .NumberFormat ;
34
+ import java .util .concurrent .TimeUnit ;
35
+
34
36
import javax .swing .filechooser .FileSystemView ;
35
37
36
38
public class FileSystemViewMemoryLeak {
@@ -39,6 +41,9 @@ public static void main(String[] args) {
39
41
test ();
40
42
}
41
43
44
+ // Will run the test no more than 300 seconds
45
+ static long endtime = System .nanoTime () + TimeUnit .SECONDS .toNanos (300 );
46
+
42
47
private static void test () {
43
48
44
49
File root = new File ("C:\\ " );
@@ -52,6 +57,10 @@ private static void test() {
52
57
int iMax = 50000 ;
53
58
long lastPercentFinished = 0L ;
54
59
for (int i = 0 ; i < iMax ; i ++) {
60
+ if (isComplete ()) {
61
+ System .out .println ("Time is over" );
62
+ return ;
63
+ }
55
64
56
65
long percentFinished = Math .round (((i * 1000d ) / (double ) iMax ));
57
66
@@ -77,5 +86,9 @@ private static void test() {
77
86
boolean drive = fileSystemView .isDrive (root );
78
87
}
79
88
}
89
+
90
+ private static boolean isComplete () {
91
+ return endtime - System .nanoTime () < 0 ;
92
+ }
80
93
}
81
94
0 commit comments