Path: blob/master/test/jdk/java/beans/Introspector/8159696/UnloadClassBeanInfo.java
41153 views
/*1* Copyright (c) 2016, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation.7*8* This code is distributed in the hope that it will be useful, but WITHOUT9* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or10* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License11* version 2 for more details (a copy is included in the LICENSE file that12* accompanied this code).13*14* You should have received a copy of the GNU General Public License version15* 2 along with this work; if not, write to the Free Software Foundation,16* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.17*18* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA19* or visit www.oracle.com if you need additional information or have any20* questions.21*/2223import java.beans.BeanInfo;24import java.beans.Introspector;25import java.beans.MethodDescriptor;26import java.io.File;27import java.net.URL;28import java.net.URLClassLoader;29import java.nio.file.Files;30import java.nio.file.Path;31import java.nio.file.Paths;32import java.nio.file.StandardCopyOption;33import java.util.Arrays;3435/**36* @test37* @bug 815969638* @library /javax/swing/regtesthelpers39* @compile ./stub/Stub.java40* @run main/othervm -mx32M UnloadClassBeanInfo41*/42public class UnloadClassBeanInfo {4344private static URLClassLoader loader;4546public static void main(final String[] args) throws Exception {47Class cl = getStub();48System.out.println("cl.getClassLoader() = " + cl.getClassLoader());49final BeanInfo beanInfo = Introspector.getBeanInfo(cl, Object.class);50MethodDescriptor[] mds = beanInfo.getMethodDescriptors();51System.out.println("mds = " + Arrays.toString(mds));52loader.close();53loader=null;54cl=null;55Util.generateOOME();56mds = beanInfo.getMethodDescriptors();57System.out.println("mds = " + Arrays.toString(mds));58}5960/**61* The Stub class is compiled by jtreg, but we want to move it so it is not62* on the application classpath. We want to load it through a separate63* classloader.64*/65static Class<?> getStub() throws Exception {66final String testclasses = System.getProperty("test.classes");67final File subdir = new File(testclasses, "stub");68subdir.mkdir();6970final Path src = Paths.get(testclasses, "Stub.class");71final Path dest = subdir.toPath().resolve("Stub.class");72Files.move(src, dest, StandardCopyOption.REPLACE_EXISTING);7374loader = new URLClassLoader(new URL[]{subdir.toURL()});75return Class.forName("Stub", true, loader);76}77}787980