test/java/lang/management/ManagementFactory/MBeanServerMXBeanUnsupportedTest.java

Print this page

        

*** 1,7 **** /* ! * Copyright (c) 2006, 2011, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it * under the terms of the GNU General Public License version 2 only, as * published by the Free Software Foundation. --- 1,7 ---- /* ! * Copyright (c) 2006, 2013 Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it * under the terms of the GNU General Public License version 2 only, as * published by the Free Software Foundation.
*** 34,43 **** --- 34,45 ---- import java.lang.management.ManagementFactory; import java.lang.reflect.InvocationHandler; import java.lang.reflect.Method; import java.lang.reflect.Proxy; + import java.util.Arrays; + import java.util.HashSet; import javax.management.MBeanServer; import javax.management.MBeanServerBuilder; import javax.management.MBeanServerDelegate; import javax.management.ObjectName; import javax.management.StandardMBean;
*** 79,88 **** --- 81,93 ---- * RuntimeException if we try to register a non StandardMBean. */ public static class MBeanServerForwarderInvocationHandler implements InvocationHandler { + public static final HashSet<String> excludeList = new HashSet<String>( + Arrays.asList("com.sun.management:type=DiagnosticCommand")); + public static MBeanServerForwarder newProxyInstance() { final InvocationHandler handler = new MBeanServerForwarderInvocationHandler();
*** 124,133 **** --- 129,139 ---- mbean.getClass().getName() + "\tname=" + name); Object result = method.invoke(mbs, args); if (domain.equals("java.lang") || domain.equals("java.util.logging") || domain.equals("com.sun.management")) { + if(!excludeList.contains(name.getCanonicalName())) { String mxbean = (String) mbs.getMBeanInfo(name).getDescriptor().getFieldValue("mxbean"); if (mxbean == null || !mxbean.equals("true")) { throw new RuntimeException( "Platform MBeans must be MXBeans!");
*** 135,144 **** --- 141,151 ---- if (!(mbean instanceof StandardMBean)) { throw new RuntimeException( "MXBeans must be wrapped in StandardMBean!"); } } + } return result; } return method.invoke(mbs, args); }