0N/A/*
2362N/A * Copyright (c) 2005, 2008, 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 6292705
0N/A * @summary Test support for arrays in parameterized types.
0N/A * @author Luis-Miguel Alventosa
0N/A * @run clean GenericArrayTypeTest
0N/A * @run build GenericArrayTypeTest
0N/A * @run main GenericArrayTypeTest
0N/A */
0N/A
0N/Aimport java.lang.management.ManagementFactory;
0N/Aimport java.util.ArrayList;
0N/Aimport java.util.HashMap;
0N/Aimport java.util.HashSet;
0N/Aimport java.util.List;
0N/Aimport java.util.Map;
0N/Aimport java.util.Set;
469N/Aimport javax.management.Attribute;
0N/Aimport javax.management.JMX;
0N/Aimport javax.management.MBeanServer;
0N/Aimport javax.management.MBeanServerConnection;
0N/Aimport javax.management.ObjectName;
469N/Aimport javax.management.StandardMBean;
469N/Aimport javax.management.openmbean.CompositeData;
0N/Aimport javax.management.remote.JMXConnector;
0N/Aimport javax.management.remote.JMXConnectorFactory;
0N/Aimport javax.management.remote.JMXConnectorServer;
0N/Aimport javax.management.remote.JMXConnectorServerFactory;
0N/Aimport javax.management.remote.JMXServiceURL;
0N/A
0N/Apublic class GenericArrayTypeTest {
469N/A // A version of java.lang.management.MonitorInfo so we can run this test
469N/A // on JDK 5, where that class didn't exist.
469N/A public static class MonitorInfo {
469N/A private final String className;
469N/A private final int identityHashCode;
469N/A private final int lockedStackDepth;
469N/A private final StackTraceElement lockedStackFrame;
469N/A
469N/A public MonitorInfo(
469N/A String className, int identityHashCode,
469N/A int lockedStackDepth, StackTraceElement lockedStackFrame) {
469N/A this.className = className;
469N/A this.identityHashCode = identityHashCode;
469N/A this.lockedStackDepth = lockedStackDepth;
469N/A this.lockedStackFrame = lockedStackFrame;
469N/A }
469N/A
469N/A public static MonitorInfo from(CompositeData cd) {
469N/A try {
469N/A CompositeData stecd = (CompositeData) cd.get("lockedStackFrame");
469N/A StackTraceElement ste = new StackTraceElement(
469N/A (String) stecd.get("className"),
469N/A (String) stecd.get("methodName"),
469N/A (String) stecd.get("fileName"),
469N/A (Integer) stecd.get("lineNumber"));
469N/A return new MonitorInfo(
469N/A (String) cd.get("className"),
469N/A (Integer) cd.get("identityHashCode"),
469N/A (Integer) cd.get("lockedStackDepth"),
469N/A ste);
469N/A } catch (Exception e) {
469N/A throw new RuntimeException(e);
469N/A }
469N/A }
469N/A
469N/A public String getClassName() {
469N/A return className;
469N/A }
469N/A
469N/A public int getIdentityHashCode() {
469N/A return identityHashCode;
469N/A }
469N/A
469N/A public int getLockedStackDepth() {
469N/A return lockedStackDepth;
469N/A }
469N/A
469N/A public StackTraceElement getLockedStackFrame() {
469N/A return lockedStackFrame;
469N/A }
469N/A }
469N/A
0N/A
0N/A public interface TestMXBean {
0N/A
0N/A public String[] getT1();
0N/A public void setT1(String[] v);
0N/A
0N/A public MonitorInfo[] getT2();
0N/A public void setT2(MonitorInfo[] v);
0N/A
0N/A public Map<String,String[]> getT3();
0N/A public void setT3(Map<String,String[]> v);
0N/A
0N/A public Map<String,MonitorInfo[]> getT4();
0N/A public void setT4(Map<String,MonitorInfo[]> v);
0N/A
0N/A public Set<String[]> getT5();
0N/A public void setT5(Set<String[]> v);
0N/A
0N/A public Set<MonitorInfo[]> getT6();
0N/A public void setT6(Set<MonitorInfo[]> v);
0N/A
0N/A public List<String[]> getT7();
0N/A public void setT7(List<String[]> v);
0N/A
0N/A public List<MonitorInfo[]> getT8();
0N/A public void setT8(List<MonitorInfo[]> v);
0N/A
0N/A public Set<List<String[]>> getT9();
0N/A public void setT9(Set<List<String[]>> v);
0N/A
0N/A public Set<List<MonitorInfo[]>> getT10();
0N/A public void setT10(Set<List<MonitorInfo[]>> v);
0N/A
0N/A public Map<String,Set<List<String[]>>> getT11();
0N/A public void setT11(Map<String,Set<List<String[]>>> v);
0N/A
0N/A public Map<String,Set<List<MonitorInfo[]>>> getT12();
0N/A public void setT12(Map<String,Set<List<MonitorInfo[]>>> v);
0N/A }
0N/A
0N/A public static class Test implements TestMXBean {
0N/A
0N/A public String[] getT1() {
0N/A return t1;
0N/A }
0N/A public void setT1(String[] v) {
0N/A t1 = v;
0N/A }
0N/A private String[] t1;
0N/A
0N/A public MonitorInfo[] getT2() {
0N/A return t2;
0N/A }
0N/A public void setT2(MonitorInfo[] v) {
0N/A t2 = v;
0N/A }
0N/A private MonitorInfo[] t2;
0N/A
0N/A public Map<String,String[]> getT3() {
0N/A return t3;
0N/A }
0N/A public void setT3(Map<String,String[]> v) {
0N/A t3 = v;
0N/A }
0N/A private Map<String,String[]> t3;
0N/A
0N/A public Map<String,MonitorInfo[]> getT4() {
0N/A return t4;
0N/A }
0N/A public void setT4(Map<String,MonitorInfo[]> v) {
0N/A t4 = v;
0N/A }
0N/A private Map<String,MonitorInfo[]> t4;
0N/A
0N/A public Set<String[]> getT5() {
0N/A return t5;
0N/A }
0N/A public void setT5(Set<String[]> v) {
0N/A t5 = v;
0N/A }
0N/A private Set<String[]> t5;
0N/A
0N/A public Set<MonitorInfo[]> getT6() {
0N/A return t6;
0N/A }
0N/A public void setT6(Set<MonitorInfo[]> v) {
0N/A t6 = v;
0N/A }
0N/A private Set<MonitorInfo[]> t6;
0N/A
0N/A public List<String[]> getT7() {
0N/A return t7;
0N/A }
0N/A public void setT7(List<String[]> v) {
0N/A t7 = v;
0N/A }
0N/A private List<String[]> t7;
0N/A
0N/A public List<MonitorInfo[]> getT8() {
0N/A return t8;
0N/A }
0N/A public void setT8(List<MonitorInfo[]> v) {
0N/A t8 = v;
0N/A }
0N/A private List<MonitorInfo[]> t8;
0N/A
0N/A public Set<List<String[]>> getT9() {
0N/A return t9;
0N/A }
0N/A public void setT9(Set<List<String[]>> v) {
0N/A t9 = v;
0N/A }
0N/A private Set<List<String[]>> t9;
0N/A
0N/A public Set<List<MonitorInfo[]>> getT10() {
0N/A return t10;
0N/A }
0N/A public void setT10(Set<List<MonitorInfo[]>> v) {
0N/A t10 = v;
0N/A }
0N/A private Set<List<MonitorInfo[]>> t10;
0N/A
0N/A public Map<String,Set<List<String[]>>> getT11() {
0N/A return t11;
0N/A }
0N/A public void setT11(Map<String,Set<List<String[]>>> v) {
0N/A t11 = v;
0N/A }
0N/A private Map<String,Set<List<String[]>>> t11;
0N/A
0N/A public Map<String,Set<List<MonitorInfo[]>>> getT12() {
0N/A return t12;
0N/A }
0N/A public void setT12(Map<String,Set<List<MonitorInfo[]>>> v) {
0N/A t12 = v;
0N/A }
0N/A private Map<String,Set<List<MonitorInfo[]>>> t12;
0N/A }
0N/A
0N/A public static void main(String[] args) throws Exception {
0N/A
0N/A int error = 0;
0N/A JMXConnector cc = null;
0N/A JMXConnectorServer cs = null;
0N/A
0N/A try {
0N/A // Instantiate the MBean server
0N/A //
0N/A echo("\n>>> Create the MBean server");
0N/A MBeanServer mbs = ManagementFactory.getPlatformMBeanServer();
0N/A
0N/A // Get default domain
0N/A //
0N/A echo("\n>>> Get the MBean server's default domain");
0N/A String domain = mbs.getDefaultDomain();
0N/A echo("\tDefault Domain = " + domain);
0N/A
0N/A // Register TestMXBean
0N/A //
0N/A echo("\n>>> Register TestMXBean");
0N/A ObjectName name =
0N/A ObjectName.getInstance(domain + ":type=" + TestMXBean.class);
0N/A mbs.createMBean(Test.class.getName(), name);
0N/A
0N/A // Create an RMI connector server
0N/A //
0N/A echo("\n>>> Create an RMI connector server");
0N/A JMXServiceURL url = new JMXServiceURL("service:jmx:rmi://");
0N/A cs =
0N/A JMXConnectorServerFactory.newJMXConnectorServer(url, null, mbs);
0N/A
0N/A // Start the RMI connector server
0N/A //
0N/A echo("\n>>> Start the RMI connector server");
0N/A cs.start();
0N/A
0N/A // Create an RMI connector client
0N/A //
0N/A echo("\n>>> Create an RMI connector client");
0N/A cc = JMXConnectorFactory.connect(cs.getAddress(), null);
0N/A MBeanServerConnection mbsc = cc.getMBeanServerConnection();
0N/A
0N/A // Create TestMXBean proxy
0N/A //
0N/A echo("\n>>> Create the TestMXBean proxy");
0N/A TestMXBean test = JMX.newMXBeanProxy(mbsc, name, TestMXBean.class);
0N/A
0N/A // Play with proxy getters and setters
0N/A //
0N/A echo("\n>>> Play with proxy getters and setters");
0N/A String[] t1 = new String[] { "t1" };
0N/A MonitorInfo[] t2 = new MonitorInfo[] {
0N/A new MonitorInfo("dummy", 0, 0,
0N/A new StackTraceElement("dummy", "dummy", "dummy", 0)) };
0N/A Map<String,String[]> t3 = new HashMap<String,String[]>();
0N/A t3.put("key", t1);
0N/A Map<String,MonitorInfo[]> t4 = new HashMap<String,MonitorInfo[]>();
0N/A t4.put("key", t2);
0N/A Set<String[]> t5 = new HashSet<String[]>();
0N/A t5.add(t1);
0N/A Set<MonitorInfo[]> t6 = new HashSet<MonitorInfo[]>();
0N/A t6.add(t2);
0N/A List<String[]> t7 = new ArrayList<String[]>();
0N/A t7.add(t1);
0N/A List<MonitorInfo[]> t8 = new ArrayList<MonitorInfo[]>();
0N/A t8.add(t2);
0N/A Set<List<String[]>> t9 = new HashSet<List<String[]>>();
0N/A t9.add(t7);
0N/A Set<List<MonitorInfo[]>> t10 = new HashSet<List<MonitorInfo[]>>();
0N/A t10.add(t8);
0N/A Map<String,Set<List<String[]>>> t11 = new HashMap<String,Set<List<String[]>>>();
0N/A t11.put("key", t9);
0N/A Map<String,Set<List<MonitorInfo[]>>> t12 = new HashMap<String,Set<List<MonitorInfo[]>>>();
0N/A t12.put("key", t10);
0N/A
0N/A test.setT1(t1);
0N/A test.setT2(t2);
0N/A test.setT3(t3);
0N/A test.setT4(t4);
0N/A test.setT5(t5);
0N/A test.setT6(t6);
0N/A test.setT7(t7);
0N/A test.setT8(t8);
0N/A test.setT9(t9);
0N/A test.setT10(t10);
0N/A test.setT11(t11);
0N/A test.setT12(t12);
0N/A
0N/A String r;
0N/A String e1 = "t1";
0N/A String e2 = "dummy";
0N/A echo("\tT1 = " + test.getT1());
0N/A r = ((String[])test.getT1())[0];
0N/A echo("\tR1 = " + r);
0N/A if (!e1.equals(r)) error++;
0N/A echo("\tT2 = " + test.getT2());
0N/A r = ((MonitorInfo[])test.getT2())[0].getClassName();
0N/A echo("\tR2 = " + r);
0N/A if (!e2.equals(r)) error++;
0N/A echo("\tT3 = " + test.getT3());
0N/A r = ((String[])((Map<String,String[]>)test.getT3()).get("key"))[0];
0N/A echo("\tR3 = " + r);
0N/A if (!e1.equals(r)) error++;
0N/A echo("\tT4 = " + test.getT4());
0N/A r = ((MonitorInfo[])((Map<String,MonitorInfo[]>)test.getT4()).get("key"))[0].getClassName();
0N/A echo("\tR4 = " + r);
0N/A if (!e2.equals(r)) error++;
0N/A echo("\tT5 = " + test.getT5());
0N/A r = ((String[])((Set<String[]>)test.getT5()).iterator().next())[0];
0N/A echo("\tR5 = " + r);
0N/A if (!e1.equals(r)) error++;
0N/A echo("\tT6 = " + test.getT6());
0N/A r = ((MonitorInfo[])((Set<MonitorInfo[]>)test.getT6()).iterator().next())[0].getClassName();
0N/A echo("\tR6 = " + r);
0N/A if (!e2.equals(r)) error++;
0N/A echo("\tT7 = " + test.getT7());
0N/A r = ((String[])((List<String[]>)test.getT7()).get(0))[0];
0N/A echo("\tR7 = " + r);
0N/A if (!e1.equals(r)) error++;
0N/A echo("\tT8 = " + test.getT8());
0N/A r = ((MonitorInfo[])((List<MonitorInfo[]>)test.getT8()).get(0))[0].getClassName();
0N/A echo("\tR8 = " + r);
0N/A if (!e2.equals(r)) error++;
0N/A echo("\tT9 = " + test.getT9());
0N/A r = ((String[])((List<String[]>)((Set<List<String[]>>)test.getT9()).iterator().next()).get(0))[0];
0N/A echo("\tR9 = " + r);
0N/A if (!e1.equals(r)) error++;
0N/A echo("\tT10 = " + test.getT10());
0N/A r = ((MonitorInfo[])((List<MonitorInfo[]>)((Set<List<MonitorInfo[]>>)test.getT10()).iterator().next()).get(0))[0].getClassName();
0N/A echo("\tR10 = " + r);
0N/A if (!e2.equals(r)) error++;
0N/A echo("\tT11 = " + test.getT11());
0N/A r = ((String[])((List<String[]>)((Set<List<String[]>>)((Map<String,Set<List<String[]>>>)test.getT11()).get("key")).iterator().next()).get(0))[0];
0N/A echo("\tR11 = " + r);
0N/A if (!e1.equals(r)) error++;
0N/A echo("\tT12 = " + test.getT12());
0N/A r = ((MonitorInfo[])((List<MonitorInfo[]>)((Set<List<MonitorInfo[]>>)((Map<String,Set<List<MonitorInfo[]>>>)test.getT12()).get("key")).iterator().next()).get(0))[0].getClassName();
0N/A echo("\tR12 = " + r);
0N/A if (!e2.equals(r)) error++;
0N/A } catch (Exception e) {
0N/A e.printStackTrace(System.out);
0N/A error++;
0N/A } finally {
0N/A // Close client
0N/A //
0N/A echo("\n>>> Close the RMI connector client");
0N/A if (cc != null)
0N/A cc.close();
0N/A
0N/A // Stop server
0N/A //
0N/A echo("\n>>> Stop the RMI connector server");
0N/A if (cs != null)
0N/A cs.stop();
0N/A
0N/A echo("\n>>> Bye! Bye!");
0N/A }
0N/A
0N/A if (error > 0) {
0N/A echo("\nTest failed! " + error + " errors.\n");
0N/A throw new IllegalArgumentException("Test failed");
0N/A } else {
0N/A echo("\nTest passed!\n");
0N/A }
0N/A }
0N/A
0N/A private static void echo(String msg) {
0N/A System.out.println(msg);
0N/A }
0N/A}