1 /* 2 * Copyright (c) 2009, 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 * @test 26 * @bug 6795356 27 * @summary Leak caused by javax.swing.UIDefaults.ProxyLazyValue.acc 28 * @author Alexander Potochkin 29 * @library ../../regtesthelpers 30 * @build Util 31 * @run main bug6795356 32 */ 33 34 import java.lang.ref.WeakReference; 35 import java.security.ProtectionDomain; 36 import java.security.AccessController; 37 import java.security.PrivilegedAction; 38 import java.security.AccessControlContext; 39 import java.util.LinkedList; 40 import java.util.List; 41 import javax.swing.*; 42 43 public class bug6795356 { 44 volatile static WeakReference<ProtectionDomain> weakRef; 45 46 public static void main(String[] args) throws Exception { 47 48 ProtectionDomain domain = new ProtectionDomain(null, null); 49 50 AccessController.doPrivileged(new PrivilegedAction<Object>() { 51 public Object run() { 52 53 // this initialize ProxyLazyValues 54 UIManager.getLookAndFeel(); 55 56 return null; 57 } 58 }, new AccessControlContext(new ProtectionDomain[]{domain})); 59 60 weakRef = new WeakReference<ProtectionDomain>(domain); 61 domain = null; 62 63 Util.generateOOME(); 64 65 if (weakRef.get() != null) { 66 throw new RuntimeException("Memory leak found!"); 67 } 68 System.out.println("Test passed"); 69 } 70 }