test/jdk/javax/swing/JFileChooser/FileSystemView/FileSystemViewListenerLeak.java
changeset 50007 70a63053cf68
parent 47368 147cb4cf2556
equal deleted inserted replaced
50006:394a0387a3ab 50007:70a63053cf68
     1 /*
     1 /*
     2  * Copyright (c) 2017, Oracle and/or its affiliates. All rights reserved.
     2  * Copyright (c) 2017, 2018, Oracle and/or its affiliates. All rights reserved.
     3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     4  *
     4  *
     5  * This code is free software; you can redistribute it and/or modify it
     5  * This code is free software; you can redistribute it and/or modify it
     6  * under the terms of the GNU General Public License version 2 only, as
     6  * under the terms of the GNU General Public License version 2 only, as
     7  * published by the Free Software Foundation.
     7  * published by the Free Software Foundation.
    21  * questions.
    21  * questions.
    22  */
    22  */
    23 
    23 
    24 import java.io.File;
    24 import java.io.File;
    25 import java.io.IOException;
    25 import java.io.IOException;
    26 import java.util.concurrent.TimeUnit;
       
    27 
    26 
    28 import javax.swing.UIManager;
    27 import javax.swing.UIManager;
    29 import javax.swing.filechooser.FileSystemView;
    28 import javax.swing.filechooser.FileSystemView;
    30 
    29 
    31 /**
    30 /**
    32  * @test
    31  * @test
    33  * @bug 8175968
    32  * @bug 8175968 8198342
       
    33  * @summary FileSystemView should clean listeners in UIManager before removal
    34  * @library /javax/swing/regtesthelpers
    34  * @library /javax/swing/regtesthelpers
    35  * @build Util
    35  * @build Util
    36  * @run main/othervm -Xmx8m -Djava.awt.headless=true FileSystemViewListenerLeak
    36  * @run main/othervm -Xmx8m -Djava.awt.headless=true FileSystemViewListenerLeak
    37 */
    37 */
    38 public final class FileSystemViewListenerLeak {
    38 public final class FileSystemViewListenerLeak {
    39 
    39 
    40     public static void main(final String[] args) {
    40     public static void main(final String[] args) {
    41         checkListenersCount();
    41         checkListenersCount();
    42         test();
    42         new CustomFileSystemView();
    43         Util.generateOOME();
    43         Util.generateOOME();
    44         checkListenersCount();
    44         checkListenersCount();
    45     }
       
    46 
       
    47     private static void test() {
       
    48         // Will run the test no more than 30 seconds
       
    49         long endtime = System.nanoTime() + TimeUnit.SECONDS.toNanos(30);
       
    50         while (!(endtime - System.nanoTime() < 0)) {
       
    51             new CustomFileSystemView();
       
    52         }
       
    53     }
    45     }
    54 
    46 
    55     private static void checkListenersCount() {
    47     private static void checkListenersCount() {
    56         int length = UIManager.getPropertyChangeListeners().length;
    48         int length = UIManager.getPropertyChangeListeners().length;
    57         if (length != 0) {
    49         if (length != 0) {