1 /* 2 * Copyright (c) 2014, 2018, Oracle and/or its affiliates. All rights reserved. 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 * 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 7 * published by the Free Software Foundation. 8 * 9 * This code is distributed in the hope that it will be useful, but WITHOUT 10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 12 * version 2 for more details (a copy is included in the LICENSE file that 13 * accompanied this code). 14 * 15 * You should have received a copy of the GNU General Public License version 16 * 2 along with this work; if not, write to the Free Software Foundation, 17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 18 * 19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 20 * or visit www.oracle.com if you need additional information or have any 21 * questions. 22 */ 23 24 25 /* 26 test 27 @bug 4051487 4145670 8062021 28 @summary Tests that disposing of an empty Frame or a Frame with a MenuBar 29 while it is being created does not crash the VM. 30 @author dpm area=Threads 31 @run applet/timeout=7200 DisposeStressTest.html 32 */ 33 34 // Note there is no @ in front of test above. This is so that the 35 // harness will not mistake this file as a test file. It should 36 // only see the html file as a test file. (the harness runs all 37 // valid test files, so it would run this test twice if this file 38 // were valid as well as the html file.) 39 // Also, note the area= after Your Name in the author tag. Here, you 40 // should put which functional area the test falls in. See the 41 // AWT-core home page -> test areas and/or -> AWT team for a list of 42 // areas. 43 // Note also the 'DisposeStressTest.html' in the run tag. This should 44 // be changed to the name of the test. 45 46 47 /** 48 * DisposeStressTest.java 49 * 50 * summary: 51 */ 52 53 import java.applet.Applet; 54 import java.awt.*; 55 56 57 //Automated tests should run as applet tests if possible because they 58 // get their environments cleaned up, including AWT threads, any 59 // test created threads, and any system resources used by the test 60 // such as file descriptors. (This is normally not a problem as 61 // main tests usually run in a separate VM, however on some platforms 62 // such as the Mac, separate VMs are not possible and non-applet 63 // tests will cause problems). Also, you don't have to worry about 64 // synchronisation stuff in Applet tests they way you do in main 65 // tests... 66 67 68 public class DisposeStressTest extends Applet 69 { 70 //Declare things used in the test, like buttons and labels here 71 72 public void init() 73 { 74 //Create instructions for the user here, as well as set up 75 // the environment -- set the layout manager, add buttons, 76 // etc. 77 78 this.setLayout (new BorderLayout ()); 79 80 81 }//End init() 82 83 public void start () 84 { 85 for (int i = 0; i < 1000; i++) { 86 Frame f = new Frame(); 87 f.setBounds(10, 10, 10, 10); 88 f.show(); 89 f.dispose(); 90 91 Frame f2 = new Frame(); 92 f2.setBounds(10, 10, 100, 100); 93 MenuBar bar = new MenuBar(); 94 Menu menu = new Menu(); 95 menu.add(new MenuItem("foo")); 96 bar.add(menu); 97 f2.setMenuBar(bar); 98 f2.show(); 99 f2.dispose(); 100 } 101 }// start() 102 103 }// class DisposeStressTest