Skip to content

Commit

Permalink
8241806: The sun/awt/shell/FileSystemViewMemoryLeak.java is unstable
Browse files Browse the repository at this point in the history
Backport-of: e730e8b
  • Loading branch information
mrserb committed Feb 5, 2023
1 parent f5a04fb commit 6ffd006
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 3 deletions.
1 change: 0 additions & 1 deletion test/jdk/ProblemList.txt
Expand Up @@ -216,7 +216,6 @@ java/awt/image/MultiResolutionImage/MultiResolutionDrawImageWithTransformTest.ja
java/awt/print/Headless/HeadlessPrinterJob.java 8196088 windows-all
sun/awt/datatransfer/SuplementaryCharactersTransferTest.java 8011371 generic-all
sun/awt/shell/ShellFolderMemoryLeak.java 8197794 windows-all
sun/awt/shell/FileSystemViewMemoryLeak.java 8241806 windows-all
sun/java2d/DirectX/OverriddenInsetsTest/OverriddenInsetsTest.java 8196102 generic-all
sun/java2d/DirectX/RenderingToCachedGraphicsTest/RenderingToCachedGraphicsTest.java 8196180 windows-all
sun/java2d/SunGraphics2D/EmptyClipRenderingTest.java 8144029 macosx-all
Expand Down
17 changes: 15 additions & 2 deletions test/jdk/sun/awt/shell/FileSystemViewMemoryLeak.java
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2017, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2017, 2020, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
Expand Down Expand Up @@ -27,10 +27,12 @@
* @summary FileSystemView.isDrive(File) memory leak on "C:\" file reference
* @modules java.desktop/sun.awt.shell
* @requires (os.family == "windows")
* @run main/othervm -Xmx8m FileSystemViewMemoryLeak
* @run main/othervm/timeout=320 -Xmx8m FileSystemViewMemoryLeak
*/
import java.io.File;
import java.text.NumberFormat;
import java.util.concurrent.TimeUnit;

import javax.swing.filechooser.FileSystemView;

public class FileSystemViewMemoryLeak {
Expand All @@ -39,6 +41,9 @@ public static void main(String[] args) {
test();
}

// Will run the test no more than 300 seconds
static long endtime = System.nanoTime() + TimeUnit.SECONDS.toNanos(300);

private static void test() {

File root = new File("C:\\");
Expand All @@ -52,6 +57,10 @@ private static void test() {
int iMax = 50000;
long lastPercentFinished = 0L;
for (int i = 0; i < iMax; i++) {
if (isComplete()) {
System.out.println("Time is over");
return;
}

long percentFinished = Math.round(((i * 1000d) / (double) iMax));

Expand All @@ -77,5 +86,9 @@ private static void test() {
boolean drive = fileSystemView.isDrive(root);
}
}

private static boolean isComplete() {
return endtime - System.nanoTime() < 0;
}
}

1 comment on commit 6ffd006

@openjdk-notifier
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.