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

Print this page

        

@@ -1,7 +1,7 @@
 /*
- * Copyright (c) 2006, 2011, Oracle and/or its affiliates. All rights reserved.
+ * 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,10 +34,12 @@
 
 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,10 +81,13 @@
      * 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,10 +129,11 @@
                         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,10 +141,11 @@
                     if (!(mbean instanceof StandardMBean)) {
                         throw new RuntimeException(
                                 "MXBeans must be wrapped in StandardMBean!");
                     }
                 }
+                }
                 return result;
             }
 
             return method.invoke(mbs, args);
         }