1/* 2 * Copyright (c) 2003, 2010, Oracle and/or its affiliates. All rights reserved. 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 * 5 * This code is free software; you can redistribute it and/or modify it 6 * under the terms of the GNU General Public License version 2 only, as 7 * published by the Free Software Foundation. 8 * 9 * This code is distributed in the hope that it will be useful, but WITHOUT 10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 12 * version 2 for more details (a copy is included in the LICENSE file that 13 * accompanied this code). 14 * 15 * You should have received a copy of the GNU General Public License version 16 * 2 along with this work; if not, write to the Free Software Foundation, 17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 18 * 19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 20 * or visit www.oracle.com if you need additional information or have any 21 * questions. 22 */ 23 24/* @test 25 * @bug 4838310 26 * @summary This test verifies that the restrictions on proxy interface 27 * methods with the same signature but different return types are 28 * correctly enforced. 29 * @author Peter Jones 30 * 31 * @build GetObject GetSerializable GetCloneable GetArray 32 * @run main Test 33 */ 34 35import java.lang.reflect.Proxy; 36import java.security.PrivilegedAction; 37import java.util.Arrays; 38import java.util.Collection; 39import java.util.List; 40 41public class Test { 42 43 // additional test cases may be added to both of these lists: 44 45 private static final Class<?>[][] GOOD = { 46 { Collection.class }, 47 { Iterable.class, Collection.class }, 48 { Iterable.class, Collection.class, List.class }, 49 { GetSerializable.class, GetCloneable.class, GetArray.class }, 50 { GetObject.class, GetSerializable.class, GetCloneable.class, 51 GetArray.class } 52 }; 53 54 private static final Class<?>[][] BAD = { 55 { Runnable.class, PrivilegedAction.class }, 56 { GetSerializable.class, GetCloneable.class }, 57 { GetObject.class, GetSerializable.class, GetCloneable.class } 58 }; 59 60 public static void main(String[] args) throws Exception { 61 System.err.println("\nRegression test for bug 4838310\n"); 62 63 ClassLoader loader = Test.class.getClassLoader(); 64 65 System.err.println("Testing GOOD combinations:"); 66 67 for (int i = 0; i < GOOD.length; i++) { 68 Class<?>[] interfaces = GOOD[i]; 69 System.err.println(Arrays.asList(interfaces)); 70 Proxy.getProxyClass(loader, interfaces); 71 System.err.println("--- OK."); 72 } 73 74 System.err.println("Testing BAD combinations:"); 75 76 for (int i = 0; i < BAD.length; i++) { 77 Class<?>[] interfaces = BAD[i]; 78 System.err.println(Arrays.asList(interfaces)); 79 try { 80 Proxy.getProxyClass(loader, interfaces); 81 throw new RuntimeException( 82 "TEST FAILED: bad combination succeeded"); 83 } catch (IllegalArgumentException e) { 84 e.printStackTrace(); 85 System.err.println("--- OK."); 86 } 87 } 88 89 System.err.println("TEST PASSED"); 90 } 91} 92