Skip to content
Permalink
Browse files
8225116: Test OwnedWindowsLeak.java intermittently fails
Reviewed-by: pbansal
  • Loading branch information
mrserb committed Jan 3, 2021
1 parent f5ee356 commit 497efefa3d91a17c0024a045ddce058bc88addca
Showing with 14 additions and 22 deletions.
  1. +14 −22 test/jdk/java/awt/Window/OwnedWindowsLeak/OwnedWindowsLeak.java
@@ -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 @@

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 static void main(String[] args)
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 static void main(String[] args)
// 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);
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)
Field f = Window.class.getDeclaredField("ownedWindowList");
f.setAccessible(true);
Vector ownersChildren = (Vector)f.get(owner);
while (ownersChildren.size() > 0)
{
throw new RuntimeException("Test FAILED: unexpected exception", z);
System.out.println("ownersChildren = " + ownersChildren);
System.gc();
Thread.sleep(1000);
}

// Test passed

1 comment on commit 497efef

@openjdk-notifier

This comment has been minimized.

Copy link

@openjdk-notifier openjdk-notifier bot commented on 497efef Jan 3, 2021

Please sign in to comment.