8225116: Test OwnedWindowsLeak.java intermittently fails
Reviewed-by: pbansal
This commit is contained in:
parent
f5ee356540
commit
497efefa3d
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2008, 2016, 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
|
||||
@ -39,7 +39,7 @@ import java.util.Vector;
|
||||
|
||||
public class OwnedWindowsLeak
|
||||
{
|
||||
public static void main(String[] args)
|
||||
public static void main(String[] args) throws Exception
|
||||
{
|
||||
Frame owner = new Frame("F");
|
||||
|
||||
@ -49,6 +49,7 @@ public class OwnedWindowsLeak
|
||||
for (int i = 0; i < 1000; i++)
|
||||
{
|
||||
Window child = new Window(owner);
|
||||
child.setName("window_" + i);
|
||||
children.add(new WeakReference<Window>(child));
|
||||
}
|
||||
|
||||
@ -70,31 +71,22 @@ public class OwnedWindowsLeak
|
||||
// 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
|
||||
|
Loading…
x
Reference in New Issue
Block a user