Path: blob/aarch64-shenandoah-jdk8u272-b10/jdk/test/javax/management/loading/SystemClassLoaderTest.java
38838 views
/*1* Copyright (c) 2003, 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*/2223/*24* @test25* @bug 483938926* @summary Test that a class can load MBeans from its class loader27* (at least if it is the system class loader)28* @author Eamonn McManus29* @run clean SystemClassLoaderTest30* @run build SystemClassLoaderTest31* @run main SystemClassLoaderTest32*/3334import javax.management.MBeanServer;35import javax.management.MBeanServerFactory;36import javax.management.ObjectName;3738/* Test that we can load an MBean using createMBean(className, objectName)39even if the class of the MBean is not known to the JMX class loader. */40public class SystemClassLoaderTest {4142public static void main(String[] args) throws Exception {43// Instantiate the MBean server44//45System.out.println("Create the MBean server");46MBeanServer mbs = MBeanServerFactory.createMBeanServer();4748ClassLoader mbsClassLoader = mbs.getClass().getClassLoader();4950String testClassName = Test.class.getName();5152// Check that the MBeanServer class loader does not know our test class53try {54Class.forName(testClassName, true, mbsClassLoader);55System.out.println("TEST IS INVALID: MBEANSERVER'S CLASS LOADER " +56"KNOWS OUR TEST CLASS");57System.exit(1);58} catch (ClassNotFoundException e) {59// As required60}6162// Register the MBean63//64System.out.println("Create MBean from this class");65ObjectName objectName = new ObjectName("whatever:type=whatever");66mbs.createMBean(testClassName, objectName);67// Test OK!68//69System.out.println("Bye! Bye!");70}7172public static class Test implements TestMBean {73public Test() {}74}7576public static interface TestMBean {}77}787980