404N/A/*
2362N/A * Copyright (c) 2007, 2008, Oracle and/or its affiliates. All rights reserved.
404N/A * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
404N/A *
404N/A * This code is free software; you can redistribute it and/or modify it
404N/A * under the terms of the GNU General Public License version 2 only, as
404N/A * published by the Free Software Foundation.
404N/A *
404N/A * This code is distributed in the hope that it will be useful, but WITHOUT
404N/A * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
404N/A * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
404N/A * version 2 for more details (a copy is included in the LICENSE file that
404N/A * accompanied this code).
404N/A *
404N/A * You should have received a copy of the GNU General Public License version
404N/A * 2 along with this work; if not, write to the Free Software Foundation,
404N/A * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
404N/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.
404N/A */
404N/A
404N/A/*
404N/A * @test
404N/A * @bug 6601652
404N/A * @summary Test exception when SortedMap or SortedSet has non-null Comparator
404N/A * @author Eamonn McManus
404N/A */
404N/A
404N/Aimport java.util.SortedMap;
404N/Aimport java.util.SortedSet;
404N/Aimport java.util.TreeMap;
404N/Aimport java.util.TreeSet;
404N/Aimport javax.management.MBeanServer;
404N/Aimport javax.management.MBeanServerFactory;
404N/Aimport javax.management.ObjectName;
404N/A
404N/Apublic class ComparatorExceptionTest {
404N/A public static interface TestMXBean {
404N/A public SortedSet<String> getSortedSet();
404N/A public SortedMap<String, String> getSortedMap();
404N/A }
404N/A
404N/A public static class TestImpl implements TestMXBean {
404N/A public SortedSet<String> getSortedSet() {
404N/A return new TreeSet<String>(String.CASE_INSENSITIVE_ORDER);
404N/A }
404N/A
404N/A public SortedMap<String, String> getSortedMap() {
404N/A return new TreeMap<String, String>(String.CASE_INSENSITIVE_ORDER);
404N/A }
404N/A }
404N/A
404N/A private static String failure;
404N/A
404N/A private static void fail(String why) {
404N/A failure = "FAILED: " + why;
404N/A System.out.println(failure);
404N/A }
404N/A
404N/A public static void main(String[] args) throws Exception {
404N/A MBeanServer mbs = MBeanServerFactory.newMBeanServer();
404N/A ObjectName name = new ObjectName("a:b=c");
404N/A mbs.registerMBean(new TestImpl(), name);
404N/A
404N/A for (String attr : new String[] {"SortedSet", "SortedMap"}) {
404N/A try {
404N/A Object value = mbs.getAttribute(name, attr);
404N/A fail("get " + attr + " did not throw exception");
404N/A } catch (Exception e) {
404N/A Throwable t = e;
404N/A while (!(t instanceof IllegalArgumentException)) {
404N/A if (t == null)
404N/A break;
404N/A t = t.getCause();
404N/A }
404N/A if (t != null)
404N/A System.out.println("Correct exception for " + attr);
404N/A else {
404N/A fail("get " + attr + " got wrong exception");
404N/A e.printStackTrace(System.out);
404N/A }
404N/A }
404N/A }
404N/A
404N/A if (failure != null)
404N/A throw new Exception(failure);
404N/A }
404N/A}