Path: blob/aarch64-shenandoah-jdk8u272-b10/jdk/test/javax/management/security/AvoidGetMBeanInfoCallsTest.java
38840 views
/*1* Copyright (c) 2005, 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 633178326* @summary Test that MBeanServer.queryNames doesn't call getMBeanInfo on every27* resultant MBean when there is no security manager installed.28* @author Luis-Miguel Alventosa29* @run clean AvoidGetMBeanInfoCallsTest30* @run build AvoidGetMBeanInfoCallsTest31* @run main AvoidGetMBeanInfoCallsTest32*/3334import java.util.Set;35import javax.management.Attribute;36import javax.management.AttributeList;37import javax.management.AttributeNotFoundException;38import javax.management.DynamicMBean;39import javax.management.InvalidAttributeValueException;40import javax.management.MBeanException;41import javax.management.MBeanInfo;42import javax.management.MBeanServer;43import javax.management.MBeanServerFactory;44import javax.management.ObjectName;45import javax.management.ReflectionException;4647public class AvoidGetMBeanInfoCallsTest {4849/**50* Test DynamicMBean class51*/52public static class Test implements DynamicMBean {5354public Object getAttribute(String attribute)55throws AttributeNotFoundException,56MBeanException,57ReflectionException {58return null;59}6061public void setAttribute(Attribute attribute)62throws AttributeNotFoundException,63InvalidAttributeValueException,64MBeanException,65ReflectionException {66}6768public AttributeList getAttributes(String[] attributes) {69return null;70}7172public AttributeList setAttributes(AttributeList attributes) {73return null;74}7576public Object invoke(String actionName,77Object params[],78String signature[])79throws MBeanException,80ReflectionException {81return null;82}8384public MBeanInfo getMBeanInfo() {85entered = true;86return new MBeanInfo(Test.class.getName(),87"Test description",88null, null, null, null);89}9091public boolean entered;92}9394/*95* Print message96*/97private static void echo(String message) {98System.out.println(message);99}100101/**102* Standalone entry point.103*104* Run the test and report to stdout.105*/106public static void main(String args[]) throws Exception {107108echo(">>> Create MBeanServer");109MBeanServer server = MBeanServerFactory.newMBeanServer();110111echo(">>> Default Domain: " + server.getDefaultDomain());112113echo(">>> Create and register Test MBean");114Test mbean = new Test();115ObjectName name = ObjectName.getInstance(":type=Test");116server.registerMBean(mbean, name);117118echo(">>> Set entered flag to false in Test MBean");119mbean.entered = false;120121echo(">>> Query Names:");122Set<ObjectName> names = server.queryNames(null, null);123for (ObjectName on : names) {124echo("\t" + on.toString());125}126127echo(">>> Entered flag = " + mbean.entered);128129if (mbean.entered) {130echo(">>> Test FAILED!");131throw new IllegalArgumentException("getMBeanInfo got called");132} else {133echo(">>> Test PASSED!");134}135}136}137138139