Path: blob/master/test/jdk/javax/management/mxbean/AmbiguousConstructorTest.java
41149 views
/*1* Copyright (c) 2005, 2015, 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 6175517 627870726* @summary Test that ambiguous ConstructorProperties annotations are detected.27* @author Eamonn McManus28*29* @run clean AmbiguousConstructorTest30* @run build AmbiguousConstructorTest31* @run main AmbiguousConstructorTest32*/3334import javax.management.ConstructorParameters;35import javax.management.*;3637public class AmbiguousConstructorTest {38public static void main(String[] args) throws Exception {39MBeanServer mbs = MBeanServerFactory.newMBeanServer();4041System.out.println("Unambiguous case:");42ObjectName unambigName = new ObjectName("d:type=Unambiguous");43mbs.registerMBean(new UnambiguousImpl(), unambigName);44System.out.println("...OK");4546System.out.println("Ambiguous case:");47ObjectName ambigName = new ObjectName("d:type=Ambiguous");48boolean exception = false;49try {50mbs.registerMBean(new AmbiguousImpl(), ambigName);51} catch (Exception e) {52// TODO - check for the specific exception we should get.53// Currently exception happens in preRegister so we have54// RuntimeMBeanException -> IllegalArgumentException ->55// InvalidObjectException, where the IllegalArgumentException56// is thrown by MXSupport.MBeanDispatcher.visitAttribute when57// it calls ConvertingMethod.checkCallFromOpen58System.out.println("...OK, got expected exception:");59e.printStackTrace(System.out);60exception = true;61}62if (!exception) {63System.out.println("TEST FAILED: expected exception, got none");64throw new Exception("Did not get expected exception");65}6667System.out.println("TEST PASSED");68}6970public static class Unambiguous {71public byte getA() {return 0;}72public short getB() {return 0;}73public int getC() {return 0;}74public long getD() {return 0;}7576@ConstructorParameters({"a", "b"})77public Unambiguous(byte a, short b) {}7879@ConstructorParameters({"b", "c"})80public Unambiguous(short b, int c) {}8182@ConstructorParameters({"a", "b", "c"})83public Unambiguous(byte a, short b, int c) {}84}8586public static class Ambiguous {87public byte getA() {return 0;}88public short getB() {return 0;}89public int getC() {return 0;}90public long getD() {return 0;}9192@ConstructorParameters({"a", "b"})93public Ambiguous(byte a, short b) {}9495@ConstructorParameters({"b", "c"})96public Ambiguous(short b, int c) {}9798@ConstructorParameters({"a", "b", "c", "d"})99public Ambiguous(byte a, short b, int c, long d) {}100}101102public static interface UnambiguousMXBean {103public void setUnambiguous(Unambiguous x);104}105106public static class UnambiguousImpl implements UnambiguousMXBean {107public void setUnambiguous(Unambiguous x) {}108}109110public static interface AmbiguousMXBean {111public void setAmbiguous(Ambiguous x);112}113114public static class AmbiguousImpl implements AmbiguousMXBean {115public void setAmbiguous(Ambiguous x) {}116}117}118119120