0N/A/*
2362N/A * Copyright (c) 2005, Oracle and/or its affiliates. All rights reserved.
0N/A * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
0N/A *
0N/A * This code is free software; you can redistribute it and/or modify it
0N/A * under the terms of the GNU General Public License version 2 only, as
0N/A * published by the Free Software Foundation.
0N/A *
0N/A * This code is distributed in the hope that it will be useful, but WITHOUT
0N/A * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
0N/A * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
0N/A * version 2 for more details (a copy is included in the LICENSE file that
0N/A * accompanied this code).
0N/A *
0N/A * You should have received a copy of the GNU General Public License version
0N/A * 2 along with this work; if not, write to the Free Software Foundation,
0N/A * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
0N/A *
2362N/A * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
2362N/A * or visit www.oracle.com if you need additional information or have any
2362N/A * questions.
0N/A */
0N/A
0N/A/*
0N/A * @test
0N/A * @bug 6332962
0N/A * @summary Test that DescriptorSupport does not serialize targetObject
0N/A * @author Eamonn McManus
0N/A * @run clean DescriptorSupportSerialTest
0N/A * @run build DescriptorSupportSerialTest
0N/A * @run main DescriptorSupportSerialTest
0N/A */
0N/A
0N/Aimport java.lang.reflect.Method;
0N/Aimport javax.management.*;
0N/Aimport javax.management.remote.*;
0N/Aimport javax.management.modelmbean.*;
0N/A
0N/Apublic class DescriptorSupportSerialTest {
0N/A public static void main(String[] args) throws Exception {
0N/A if (java.io.Serializable.class.isAssignableFrom(Thread.class))
0N/A throw new Exception("TEST BAD: Thread is Serializable!");
0N/A Method getName = Thread.class.getMethod("getName");
0N/A Descriptor d = new DescriptorSupport();
0N/A d.setField("name", "getName");
0N/A d.setField("descriptorType", "operation");
0N/A d.setField("TARGETObject", Thread.currentThread());
0N/A d.setField("foo", "bar");
0N/A ModelMBeanOperationInfo getNameInfo =
0N/A new ModelMBeanOperationInfo("Get name", getName, d);
0N/A ModelMBeanInfo mmbi =
0N/A new ModelMBeanInfoSupport(Thread.class.getName(),
0N/A "Thread!",
0N/A null, // no attributes
0N/A null, // no constructors
0N/A new ModelMBeanOperationInfo[] {getNameInfo},
0N/A null); // no notifications
0N/A ModelMBean mmb = new RequiredModelMBean(mmbi);
0N/A
0N/A ObjectName on = new ObjectName("d:type=Thread");
0N/A MBeanServer mbs = MBeanServerFactory.newMBeanServer();
0N/A mbs.registerMBean(mmb, on);
0N/A
0N/A JMXServiceURL url = new JMXServiceURL("rmi", null, 0);
0N/A JMXConnectorServer cs =
0N/A JMXConnectorServerFactory.newJMXConnectorServer(url, null, mbs);
0N/A cs.start();
0N/A JMXServiceURL addr = cs.getAddress();
0N/A JMXConnector cc = JMXConnectorFactory.connect(addr);
0N/A MBeanServerConnection mbsc = cc.getMBeanServerConnection();
0N/A
0N/A try {
0N/A test(mbsc, on);
0N/A System.out.println("TEST PASSED");
0N/A } finally {
0N/A cc.close();
0N/A cs.stop();
0N/A }
0N/A }
0N/A
0N/A private static void test(MBeanServerConnection mbsc, ObjectName on)
0N/A throws Exception {
0N/A ModelMBeanInfo mmbi2 = (ModelMBeanInfo) mbsc.getMBeanInfo(on);
0N/A // previous line will fail if serialization includes targetObject
0N/A
0N/A Descriptor d2 = mmbi2.getDescriptor("getName", "operation");
0N/A if (!"bar".equals(d2.getFieldValue("foo")))
0N/A throw new Exception("TEST FAILED: bad descriptor: " + d2);
0N/A
0N/A String name = (String) mbsc.invoke(on, "getName", null, null);
0N/A String thisName = Thread.currentThread().getName();
0N/A if (!thisName.equals(name)) {
0N/A throw new Exception("TEST FAILED: wrong thread name: " +
0N/A name + " should be " + thisName);
0N/A }
0N/A }
0N/A}