blob: d49ce3eda3dd00738683c178de0e46f29fe8309c [file] [log] [blame]
J. Duke319a3b92007-12-01 00:00:00 +00001/*
2 * Copyright 2004 Sun Microsystems, Inc. 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 Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
20 * CA 95054 USA or visit www.sun.com if you need additional information or
21 * have any questions.
22 */
23
24/* @test
25 * @bug 4978925
26 * @summary This test verifies that java.lang.reflect.Proxy will work
27 * with a proxy interface that contains names that are not valid Java
28 * identifiers but that are legal at runtime as of version 49.0 of the
29 * class file format.
30 * @author Peter Jones
31 *
32 * @build Test
33 * @run main Test
34 */
35
36import java.lang.reflect.Proxy;
37
38public class Test {
39
40 private static final String CLASS_NAME = "Test+Interface";
41
42 /**
43 * class file for empty interface named "Test+Interface"
44 */
45 private static final byte[] CLASS_FILE = {
46 (byte) 0xca, (byte) 0xfe, (byte) 0xba, (byte) 0xbe,
47 0x00, 0x00, 0x00, 0x31,
48 0x00, 0x07, 0x07, 0x00, 0x05, 0x07, 0x00, 0x06,
49 0x01, 0x00, 0x0a, 0x53, 0x6f, 0x75, 0x72, 0x63,
50 0x65, 0x46, 0x69, 0x6c, 0x65, 0x01, 0x00, 0x13,
51 0x54, 0x65, 0x73, 0x74, 0x2b, 0x49, 0x6e, 0x74,
52 0x65, 0x72, 0x66, 0x61, 0x63, 0x65, 0x2e, 0x6a,
53 0x61, 0x76, 0x61, 0x01, 0x00, 0x0e, 0x54, 0x65,
54 0x73, 0x74, 0x2b, 0x49, 0x6e, 0x74, 0x65, 0x72,
55 0x66, 0x61, 0x63, 0x65, 0x01, 0x00, 0x10, 0x6a,
56 0x61, 0x76, 0x61, 0x2f, 0x6c, 0x61, 0x6e, 0x67,
57 0x2f, 0x4f, 0x62, 0x6a, 0x65, 0x63, 0x74, 0x06,
58 0x01, 0x00, 0x01, 0x00, 0x02, 0x00, 0x00, 0x00,
59 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x03, 0x00,
60 0x00, 0x00, 0x02, 0x00, 0x04
61 };
62
63 public static void main(String[] args) throws Exception {
64 ClassLoader l = new Loader();
65 Class i = Class.forName(CLASS_NAME, false, l);
66 System.out.println(i);
67 Class p = Proxy.getProxyClass(i.getClassLoader(), new Class[] { i });
68 System.out.println(p);
69 }
70
71 private static class Loader extends ClassLoader {
72 Loader() { }
73 protected Class findClass(String name) throws ClassNotFoundException {
74 if (name.equals(CLASS_NAME)) {
75 return defineClass(name, CLASS_FILE, 0, CLASS_FILE.length);
76 } else {
77 return super.findClass(name);
78 }
79 }
80 }
81}