Path: blob/aarch64-shenandoah-jdk8u272-b10/jdk/test/java/lang/reflect/Proxy/nonJavaNames/Test.java
38889 views
/*1* Copyright (c) 2004, 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/* @test24* @bug 497892525* @summary This test verifies that java.lang.reflect.Proxy will work26* with a proxy interface that contains names that are not valid Java27* identifiers but that are legal at runtime as of version 49.0 of the28* class file format.29* @author Peter Jones30*31* @build Test32* @run main Test33*/3435import java.lang.reflect.Proxy;3637public class Test {3839private static final String CLASS_NAME = "Test+Interface";4041/**42* class file for empty interface named "Test+Interface"43*/44private static final byte[] CLASS_FILE = {45(byte) 0xca, (byte) 0xfe, (byte) 0xba, (byte) 0xbe,460x00, 0x00, 0x00, 0x31,470x00, 0x07, 0x07, 0x00, 0x05, 0x07, 0x00, 0x06,480x01, 0x00, 0x0a, 0x53, 0x6f, 0x75, 0x72, 0x63,490x65, 0x46, 0x69, 0x6c, 0x65, 0x01, 0x00, 0x13,500x54, 0x65, 0x73, 0x74, 0x2b, 0x49, 0x6e, 0x74,510x65, 0x72, 0x66, 0x61, 0x63, 0x65, 0x2e, 0x6a,520x61, 0x76, 0x61, 0x01, 0x00, 0x0e, 0x54, 0x65,530x73, 0x74, 0x2b, 0x49, 0x6e, 0x74, 0x65, 0x72,540x66, 0x61, 0x63, 0x65, 0x01, 0x00, 0x10, 0x6a,550x61, 0x76, 0x61, 0x2f, 0x6c, 0x61, 0x6e, 0x67,560x2f, 0x4f, 0x62, 0x6a, 0x65, 0x63, 0x74, 0x06,570x01, 0x00, 0x01, 0x00, 0x02, 0x00, 0x00, 0x00,580x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x03, 0x00,590x00, 0x00, 0x02, 0x00, 0x0460};6162public static void main(String[] args) throws Exception {63ClassLoader l = new Loader();64Class i = Class.forName(CLASS_NAME, false, l);65System.out.println(i);66Class p = Proxy.getProxyClass(i.getClassLoader(), new Class[] { i });67System.out.println(p);68}6970private static class Loader extends ClassLoader {71Loader() { }72protected Class findClass(String name) throws ClassNotFoundException {73if (name.equals(CLASS_NAME)) {74return defineClass(name, CLASS_FILE, 0, CLASS_FILE.length);75} else {76return super.findClass(name);77}78}79}80}818283