0N/A/*
2362N/A * Copyright (c) 2003, 2007, 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 4530962
0N/A * @summary Tests method search using parameter classes in Statement
0N/A * @author Mark Davidson
0N/A */
0N/A
0N/Aimport java.beans.Statement;
0N/A
0N/A/**
0N/A * Ambiguous method signature should throw an exception.
0N/A * Statement should execute the most specific method.
0N/A */
0N/Apublic class Test4530962 {
0N/A public static void main(String[] args) throws Exception {
0N/A try {
0N/A test(new A(), new Y(), new Y());
0N/A throw new Error("exception expected");
0N/A }
0N/A catch (NoSuchMethodException exception) {
0N/A // should throw an exception
0N/A }
0N/A catch (Exception exception) {
0N/A throw new Error("unexpected exception", exception);
0N/A }
0N/A test(new B(), new Y(), new Y());
0N/A test(new C(), new Z(), new Z());
0N/A test(new D(), new Z(), new Z());
0N/A test(new E(), new Z(), new Z());
0N/A }
0N/A
0N/A private static void test(Object target, Object... params) throws Exception {
0N/A new Statement(target, "m", params).execute();
0N/A }
0N/A
0N/A /**
0N/A * All ambiguous method declarations should fail.
0N/A */
0N/A public static class A {
0N/A public void m(X x1, X x2) {
0N/A throw new Error("A.m(X,X) should not be called");
0N/A }
0N/A
0N/A public void m(X x1, Y y2) {
0N/A throw new Error("A.m(X,Y) should not be called");
0N/A }
0N/A
0N/A public void m(Y y1, X x2) {
0N/A throw new Error("A.m(Y,X) should not be called");
0N/A }
0N/A }
0N/A
0N/A /**
0N/A * The most specific method in this case would be the second declaration.
0N/A */
0N/A public static class B {
0N/A public void m(X x1, X x2) {
0N/A throw new Error("B.m(X,X) should not be called");
0N/A }
0N/A
0N/A public void m(X x1, Y y2) {
0N/A // expected: B.m(X,Y) should be called
0N/A }
0N/A }
0N/A
0N/A /**
0N/A * The most specific method in this case would be the first declaration.
0N/A */
0N/A public static class C {
0N/A public void m(Y y1, Y y2) {
0N/A // expected: C.m(Y,Y) should be called
0N/A }
0N/A
0N/A public void m(X x1, X x2) {
0N/A throw new Error("C.m(X,X) should not be called");
0N/A }
0N/A }
0N/A
0N/A /**
0N/A * Same as the previous case but flip methods.
0N/A */
0N/A public static class D {
0N/A public void m(X x1, X x2) {
0N/A throw new Error("D.m(X,X) should not be called");
0N/A }
0N/A
0N/A public void m(Y y1, Y y2) {
0N/A // expected: D.m(Y,Y) should be called
0N/A }
0N/A }
0N/A
0N/A /**
0N/A * The method should be called with (Z,Z).
0N/A */
0N/A public static class E {
0N/A public void m(X x1, X x2) {
0N/A // expected: E.m(X,X) should be called
0N/A }
0N/A }
0N/A
0N/A public static class X {
0N/A }
0N/A
0N/A public static class Y extends X {
0N/A }
0N/A
0N/A public static class Z extends Y {
0N/A }
0N/A}