changeset 14428:5fcc99380a8c

8225116: Test OwnedWindowsLeak.java intermittently fails Reviewed-by: pbansal
author serb
date Sun, 03 Jan 2021 05:08:48 +0000
parents dd12c46be499
children faad8e276d64
files test/java/awt/Window/OwnedWindowsLeak/OwnedWindowsLeak.java
diffstat 1 files changed, 14 insertions(+), 22 deletions(-) [+]
line wrap: on
line diff
--- a/test/java/awt/Window/OwnedWindowsLeak/OwnedWindowsLeak.java	Thu May 05 01:30:23 2016 +0300
+++ b/test/java/awt/Window/OwnedWindowsLeak/OwnedWindowsLeak.java	Sun Jan 03 05:08:48 2021 +0000
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2008, 2009, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2008, 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
@@ -37,7 +37,7 @@
 
 public class OwnedWindowsLeak
 {
-    public static void main(String[] args)
+    public static void main(String[] args) throws Exception
     {
         Frame owner = new Frame("F");
 
@@ -47,6 +47,7 @@
         for (int i = 0; i < 1000; i++)
         {
             Window child = new Window(owner);
+            child.setName("window_" +  i);
             children.add(new WeakReference<Window>(child));
         }
 
@@ -68,31 +69,22 @@
         // Third, make sure all the weak references are null
         for (WeakReference<Window> ref : children)
         {
-            if (ref.get() != null)
-            {
-                throw new RuntimeException("Test FAILED: some of child windows are not GCed");
+            while (ref.get() != null) {
+                System.out.println("ref.get() = " + ref.get());
+                System.gc();
+                Thread.sleep(1000);
             }
         }
 
         // Fourth, make sure owner's children list contains no elements
-        try
+        Field f = Window.class.getDeclaredField("ownedWindowList");
+        f.setAccessible(true);
+        Vector ownersChildren = (Vector)f.get(owner);
+        while (ownersChildren.size() > 0)
         {
-            Field f = Window.class.getDeclaredField("ownedWindowList");
-            f.setAccessible(true);
-            Vector ownersChildren = (Vector)f.get(owner);
-            if (ownersChildren.size() > 0)
-            {
-                throw new RuntimeException("Test FAILED: some of the child windows are not removed from owner's children list");
-            }
-        }
-        catch (NoSuchFieldException z)
-        {
-            System.out.println("Test PASSED: no 'ownedWindowList' field in Window class");
-            return;
-        }
-        catch (Exception z)
-        {
-            throw new RuntimeException("Test FAILED: unexpected exception", z);
+            System.out.println("ownersChildren = " + ownersChildren);
+            System.gc();
+            Thread.sleep(1000);
         }
 
         // Test passed