Path: blob/aarch64-shenandoah-jdk8u272-b10/jdk/test/java/lang/reflect/Parameter/BadClassFiles.java
38828 views
/*1* Copyright (c) 2013, 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/*24* @test25* @run main BadClassFiles26* @summary The reflection API should throw the correct exceptions.27*/28import java.lang.Class;29import java.lang.reflect.Method;30import java.lang.reflect.Parameter;31import java.lang.reflect.MalformedParametersException;32import java.lang.ClassLoader;33import java.lang.ClassNotFoundException;34import java.io.File;35import java.io.FileOutputStream;36import java.io.IOException;3738public class BadClassFiles {39private int errors = 0;404142/* Class files were created by compiling the following source and43* then editing it:44*45* public class EmptyName {46* public void m(int a, int b) {}47* }48*49*/50private static final byte[] EmptyName_bytes = {51-54,-2,-70,-66,0,0,0,52,520,18,10,0,3,0,15,7,530,16,7,0,17,1,0,6,5460,105,110,105,116,62,1,0,553,40,41,86,1,0,4,67,56111,100,101,1,0,15,76,105,57110,101,78,117,109,98,101,114,5884,97,98,108,101,1,0,1,59109,1,0,5,40,73,73,41,6086,1,0,16,77,101,116,104,61111,100,80,97,114,97,109,101,62116,101,114,115,1,0,0,1,630,1,98,1,0,10,83,111,64117,114,99,101,70,105,108,101,651,0,14,69,109,112,116,121,6678,97,109,101,46,106,97,118,6797,12,0,4,0,5,1,0,689,69,109,112,116,121,78,97,69109,101,1,0,16,106,97,118,7097,47,108,97,110,103,47,79,7198,106,101,99,116,0,33,0,722,0,3,0,0,0,0,0,732,0,1,0,4,0,5,0,741,0,6,0,0,0,29,0,751,0,1,0,0,0,5,42,76-73,0,1,-79,0,0,0,1,770,7,0,0,0,6,0,1,780,0,0,1,0,1,0,8,790,9,0,2,0,6,0,0,800,25,0,0,0,3,0,0,810,1,-79,0,0,0,1,0,827,0,0,0,6,0,1,0,830,0,2,0,10,0,0,0,849,2,0,11,0,0,0,12,850,0,0,1,0,13,0,0,860,2,0,1487};8889private static final byte[] BadModifiers_bytes = {90-54,-2,-70,-66,0,0,0,52,910,18,10,0,3,0,15,7,920,16,7,0,17,1,0,6,9360,105,110,105,116,62,1,0,943,40,41,86,1,0,4,67,95111,100,101,1,0,15,76,105,96110,101,78,117,109,98,101,114,9784,97,98,108,101,1,0,1,98109,1,0,5,40,73,73,41,9986,1,0,16,77,101,116,104,100111,100,80,97,114,97,109,101,101116,101,114,115,1,0,1,97,1021,0,1,98,1,0,10,83,103111,117,114,99,101,70,105,108,104101,1,0,17,66,97,100,77,105111,100,105,102,105,101,114,115,10646,106,97,118,97,12,0,4,1070,5,1,0,12,66,97,100,10877,111,100,105,102,105,101,114,109115,1,0,16,106,97,118,97,11047,108,97,110,103,47,79,98,111106,101,99,116,0,33,0,2,1120,3,0,0,0,0,0,2,1130,1,0,4,0,5,0,1,1140,6,0,0,0,29,0,1,1150,1,0,0,0,5,42,-73,1160,1,-79,0,0,0,1,0,1177,0,0,0,6,0,1,0,1180,0,1,0,1,0,8,0,1199,0,2,0,6,0,0,0,12025,0,0,0,3,0,0,0,1211,-79,0,0,0,1,0,7,1220,0,0,6,0,1,0,0,1230,2,0,10,0,0,0,9,1242,0,11,0,51,51,12,0,1250,0,1,0,13,0,0,0,1262,0,14127};128129private static final byte[] BadNameIndex_bytes = {130-54,-2,-70,-66,0,0,0,52,1310,18,10,0,3,0,15,7,1320,16,7,0,17,1,0,6,13360,105,110,105,116,62,1,0,1343,40,41,86,1,0,4,67,135111,100,101,1,0,15,76,105,136110,101,78,117,109,98,101,114,13784,97,98,108,101,1,0,1,138109,1,0,5,40,73,73,41,13986,1,0,16,77,101,116,104,140111,100,80,97,114,97,109,101,141116,101,114,115,1,0,1,97,1421,0,1,98,1,0,10,83,143111,117,114,99,101,70,105,108,144101,1,0,17,66,97,100,78,14597,109,101,73,110,100,101,120,14646,106,97,118,97,12,0,4,1470,5,1,0,12,66,97,100,14878,97,109,101,73,110,100,101,149120,1,0,16,106,97,118,97,15047,108,97,110,103,47,79,98,151106,101,99,116,0,33,0,2,1520,3,0,0,0,0,0,2,1530,1,0,4,0,5,0,1,1540,6,0,0,0,29,0,1,1550,1,0,0,0,5,42,-73,1560,1,-79,0,0,0,1,0,1577,0,0,0,6,0,1,0,1580,0,1,0,1,0,8,0,1599,0,2,0,6,0,0,0,16025,0,0,0,3,0,0,0,1611,-79,0,0,0,1,0,7,1620,0,0,6,0,1,0,0,1630,2,0,10,0,0,0,9,1642,0,1,0,0,0,12,0,1650,0,1,0,13,0,0,0,1662,0,14167};168169private static final byte[] NameIndexOutOfBounds_bytes = {170-54,-2,-70,-66,0,0,0,52,1710,18,10,0,3,0,15,7,1720,16,7,0,17,1,0,6,17360,105,110,105,116,62,1,0,1743,40,41,86,1,0,4,67,175111,100,101,1,0,15,76,105,176110,101,78,117,109,98,101,114,17784,97,98,108,101,1,0,1,178109,1,0,5,40,73,73,41,17986,1,0,16,77,101,116,104,180111,100,80,97,114,97,109,101,181116,101,114,115,1,0,1,97,1821,0,1,98,1,0,10,83,183111,117,114,99,101,70,105,108,184101,1,0,25,78,97,109,101,18573,110,100,101,120,79,117,116,18679,102,66,111,117,110,100,115,18746,106,97,118,97,12,0,4,1880,5,1,0,20,78,97,109,189101,73,110,100,101,120,79,117,190116,79,102,66,111,117,110,100,191115,1,0,16,106,97,118,97,19247,108,97,110,103,47,79,98,193106,101,99,116,0,33,0,2,1940,3,0,0,0,0,0,2,1950,1,0,4,0,5,0,1,1960,6,0,0,0,29,0,1,1970,1,0,0,0,5,42,-73,1980,1,-79,0,0,0,1,0,1997,0,0,0,6,0,1,0,2000,0,1,0,1,0,8,0,2019,0,2,0,6,0,0,0,20225,0,0,0,3,0,0,0,2031,-79,0,0,0,1,0,7,2040,0,0,6,0,1,0,0,2050,2,0,10,0,0,0,9,2062,0,-1,0,0,0,12,0,2070,0,1,0,13,0,0,0,2082,0,14209210};211212private static final byte[] ExtraParams_bytes = {213-54,-2,-70,-66,0,0,0,52,2140,18,10,0,3,0,15,7,2150,16,7,0,17,1,0,6,21660,105,110,105,116,62,1,0,2173,40,41,86,1,0,4,67,218111,100,101,1,0,15,76,105,219110,101,78,117,109,98,101,114,22084,97,98,108,101,1,0,1,221109,1,0,5,40,73,73,41,22286,1,0,16,77,101,116,104,223111,100,80,97,114,97,109,101,224116,101,114,115,1,0,1,97,2251,0,1,98,1,0,10,83,226111,117,114,99,101,70,105,108,227101,1,0,16,69,120,116,114,22897,80,97,114,97,109,115,46,229106,97,118,97,12,0,4,0,2305,1,0,11,69,120,116,114,23197,80,97,114,97,109,115,1,2320,16,106,97,118,97,47,108,23397,110,103,47,79,98,106,101,23499,116,0,33,0,2,0,3,2350,0,0,0,0,2,0,1,2360,4,0,5,0,1,0,6,2370,0,0,29,0,1,0,1,2380,0,0,5,42,-73,0,1,239-79,0,0,0,1,0,7,0,2400,0,6,0,1,0,0,0,2411,0,1,0,8,0,9,0,2422,0,6,0,0,0,25,0,2430,0,3,0,0,0,1,-79,2440,0,0,1,0,7,0,0,2450,6,0,1,0,0,0,2,2460,10,0,0,0,13,3,0,24711,0,0,0,12,0,0,0,24811,0,0,0,1,0,13,0,2490,0,2,0,14250};251252private static final byte[] BadName1_bytes = {253-54,-2,-70,-66,0,0,0,52,2540,18,10,0,3,0,15,7,2550,16,7,0,17,1,0,6,25660,105,110,105,116,62,1,0,2573,40,41,86,1,0,4,67,258111,100,101,1,0,15,76,105,259110,101,78,117,109,98,101,114,26084,97,98,108,101,1,0,1,261109,1,0,5,40,73,73,41,26286,1,0,16,77,101,116,104,263111,100,80,97,114,97,109,101,264116,101,114,115,1,0,1,46,2651,0,1,98,1,0,10,83,266111,117,114,99,101,70,105,108,267101,1,0,13,66,97,100,78,26897,109,101,49,46,106,97,118,26997,12,0,4,0,5,1,0,2708,66,97,100,78,97,109,101,27149,1,0,16,106,97,118,97,27247,108,97,110,103,47,79,98,273106,101,99,116,0,33,0,2,2740,3,0,0,0,0,0,2,2750,1,0,4,0,5,0,1,2760,6,0,0,0,29,0,1,2770,1,0,0,0,5,42,-73,2780,1,-79,0,0,0,1,0,2797,0,0,0,6,0,1,0,2800,0,1,0,1,0,8,0,2819,0,2,0,6,0,0,0,28225,0,0,0,3,0,0,0,2831,-79,0,0,0,1,0,7,2840,0,0,6,0,1,0,0,2850,2,0,10,0,0,0,9,2862,0,11,0,0,0,12,0,2870,0,1,0,13,0,0,0,2882,0,14289};290291private static final byte[] BadName2_bytes = {292-54,-2,-70,-66,0,0,0,52,2930,18,10,0,3,0,15,7,2940,16,7,0,17,1,0,6,29560,105,110,105,116,62,1,0,2963,40,41,86,1,0,4,67,297111,100,101,1,0,15,76,105,298110,101,78,117,109,98,101,114,29984,97,98,108,101,1,0,1,300109,1,0,5,40,73,73,41,30186,1,0,16,77,101,116,104,302111,100,80,97,114,97,109,101,303116,101,114,115,1,0,1,91,3041,0,1,98,1,0,10,83,305111,117,114,99,101,70,105,108,306101,1,0,13,66,97,100,78,30797,109,101,50,46,106,97,118,30897,12,0,4,0,5,1,0,3098,66,97,100,78,97,109,101,31050,1,0,16,106,97,118,97,31147,108,97,110,103,47,79,98,312106,101,99,116,0,33,0,2,3130,3,0,0,0,0,0,2,3140,1,0,4,0,5,0,1,3150,6,0,0,0,29,0,1,3160,1,0,0,0,5,42,-73,3170,1,-79,0,0,0,1,0,3187,0,0,0,6,0,1,0,3190,0,1,0,1,0,8,0,3209,0,2,0,6,0,0,0,32125,0,0,0,3,0,0,0,3221,-79,0,0,0,1,0,7,3230,0,0,6,0,1,0,0,3240,2,0,10,0,0,0,9,3252,0,11,0,0,0,12,0,3260,0,1,0,13,0,0,0,3272,0,14328};329330private static final byte[] BadName3_bytes = {331-54,-2,-70,-66,0,0,0,52,3320,18,10,0,3,0,15,7,3330,16,7,0,17,1,0,6,33460,105,110,105,116,62,1,0,3353,40,41,86,1,0,4,67,336111,100,101,1,0,15,76,105,337110,101,78,117,109,98,101,114,33884,97,98,108,101,1,0,1,339109,1,0,5,40,73,73,41,34086,1,0,16,77,101,116,104,341111,100,80,97,114,97,109,101,342116,101,114,115,1,0,1,59,3431,0,1,98,1,0,10,83,344111,117,114,99,101,70,105,108,345101,1,0,13,66,97,100,78,34697,109,101,51,46,106,97,118,34797,12,0,4,0,5,1,0,3488,66,97,100,78,97,109,101,34951,1,0,16,106,97,118,97,35047,108,97,110,103,47,79,98,351106,101,99,116,0,33,0,2,3520,3,0,0,0,0,0,2,3530,1,0,4,0,5,0,1,3540,6,0,0,0,29,0,1,3550,1,0,0,0,5,42,-73,3560,1,-79,0,0,0,1,0,3577,0,0,0,6,0,1,0,3580,0,1,0,1,0,8,0,3599,0,2,0,6,0,0,0,36025,0,0,0,3,0,0,0,3611,-79,0,0,0,1,0,7,3620,0,0,6,0,1,0,0,3630,2,0,10,0,0,0,9,3642,0,11,0,0,0,12,0,3650,0,1,0,13,0,0,0,3662,0,14367};368369private static final byte[] BadName4_bytes = {370-54,-2,-70,-66,0,0,0,52,3710,18,10,0,3,0,15,7,3720,16,7,0,17,1,0,6,37360,105,110,105,116,62,1,0,3743,40,41,86,1,0,4,67,375111,100,101,1,0,15,76,105,376110,101,78,117,109,98,101,114,37784,97,98,108,101,1,0,1,378109,1,0,5,40,73,73,41,37986,1,0,16,77,101,116,104,380111,100,80,97,114,97,109,101,381116,101,114,115,1,0,1,47,3821,0,1,98,1,0,10,83,383111,117,114,99,101,70,105,108,384101,1,0,13,66,97,100,78,38597,109,101,52,46,106,97,118,38697,12,0,4,0,5,1,0,3878,66,97,100,78,97,109,101,38852,1,0,16,106,97,118,97,38947,108,97,110,103,47,79,98,390106,101,99,116,0,33,0,2,3910,3,0,0,0,0,0,2,3920,1,0,4,0,5,0,1,3930,6,0,0,0,29,0,1,3940,1,0,0,0,5,42,-73,3950,1,-79,0,0,0,1,0,3967,0,0,0,6,0,1,0,3970,0,1,0,1,0,8,0,3989,0,2,0,6,0,0,0,39925,0,0,0,3,0,0,0,4001,-79,0,0,0,1,0,7,4010,0,0,6,0,1,0,0,4020,2,0,10,0,0,0,9,4032,0,11,0,0,0,12,0,4040,0,1,0,13,0,0,0,4052,0,14406};407408private static class InMemoryClassLoader extends ClassLoader {409public Class<?> defineClass(String name, byte[] b) {410return defineClass(name, b, 0, b.length);411}412};413414private static final InMemoryClassLoader loader = new InMemoryClassLoader();415416private final Class<?>[] classes;417418private BadClassFiles() throws ClassNotFoundException {419classes = new Class<?>[] {420loader.defineClass("EmptyName", EmptyName_bytes),421loader.defineClass("BadModifiers", BadModifiers_bytes),422loader.defineClass("BadNameIndex", BadNameIndex_bytes),423loader.defineClass("NameIndexOutOfBounds", NameIndexOutOfBounds_bytes),424loader.defineClass("ExtraParams", ExtraParams_bytes),425// Name with .426loader.defineClass("BadName1", BadName1_bytes),427// Name with [428loader.defineClass("BadName2", BadName2_bytes),429// Name with ;430loader.defineClass("BadName3", BadName3_bytes),431// Name with /432loader.defineClass("BadName4", BadName4_bytes)433};434}435436public static void main(String... args)437throws NoSuchMethodException, IOException, ClassNotFoundException {438new BadClassFiles().run();439}440441public void assertBadParameters(Class<?> cls) throws NoSuchMethodException {442try {443System.err.println("Trying " + cls);444final Method method = cls.getMethod("m", int.class, int.class);445final Parameter[] params = method.getParameters();446System.err.println("Name " + params[0].getName());447System.err.println("Did not see expected exception");448errors++;449} catch(MalformedParametersException e) {450System.err.println("Expected exception seen");451}452}453454public void run() throws NoSuchMethodException {455for (Class<?> cls : classes)456assertBadParameters(cls);457458if (errors != 0)459throw new RuntimeException(errors + " errors in test");460}461}462463464