# HG changeset patch # User serb # Date 1609650528 0 # Node ID 5fcc99380a8c6948077c298780dd8b25e3964978 # Parent dd12c46be499e3aa9284ec435199fa068aad56b8 8225116: Test OwnedWindowsLeak.java intermittently fails Reviewed-by: pbansal diff -r dd12c46be499 -r 5fcc99380a8c test/java/awt/Window/OwnedWindowsLeak/OwnedWindowsLeak.java --- 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(child)); } @@ -68,31 +69,22 @@ // Third, make sure all the weak references are null for (WeakReference 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