1/* 2 * Copyright (c) 2013, 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/* 25 * @test 26 * @run main NoName 27 * @summary The reflection API should report parameters with no name properly. 28 */ 29import java.lang.Class; 30import java.lang.reflect.Method; 31import java.lang.reflect.Parameter; 32import java.lang.reflect.MalformedParametersException; 33import java.lang.ClassLoader; 34import java.lang.ClassNotFoundException; 35import java.io.File; 36import java.io.FileOutputStream; 37import java.io.IOException; 38 39public class NoName { 40 41 private static final byte[] NoName_bytes = { 42 -54,-2,-70,-66,0,0,0,52, 43 0,18,10,0,3,0,15,7, 44 0,16,7,0,17,1,0,6, 45 60,105,110,105,116,62,1,0, 46 3,40,41,86,1,0,4,67, 47 111,100,101,1,0,15,76,105, 48 110,101,78,117,109,98,101,114, 49 84,97,98,108,101,1,0,1, 50 109,1,0,5,40,73,73,41, 51 86,1,0,16,77,101,116,104, 52 111,100,80,97,114,97,109,101, 53 116,101,114,115,1,0,0,1, 54 0,1,98,1,0,10,83,111, 55 117,114,99,101,70,105,108,101, 56 1,0,14,69,109,112,116,121, 57 78,97,109,101,46,106,97,118, 58 97,12,0,4,0,5,1,0, 59 9,69,109,112,116,121,78,97, 60 109,101,1,0,16,106,97,118, 61 97,47,108,97,110,103,47,79, 62 98,106,101,99,116,0,33,0, 63 2,0,3,0,0,0,0,0, 64 2,0,1,0,4,0,5,0, 65 1,0,6,0,0,0,29,0, 66 1,0,1,0,0,0,5,42, 67 -73,0,1,-79,0,0,0,1, 68 0,7,0,0,0,6,0,1, 69 0,0,0,1,0,1,0,8, 70 0,9,0,2,0,6,0,0, 71 0,25,0,0,0,3,0,0, 72 0,1,-79,0,0,0,1,0, 73 7,0,0,0,6,0,1,0, 74 0,0,2, 75 // Method Parameters attribute here 76 0,10, 77 // attribute_length 78 0,0,0,9, 79 // parameter_count 80 2, 81 // first parameter name 82 0,0, 83 // first parameter modifiers 84 0,0, 85 // second parameter name 86 0,12, 87 // second parameter modifiers 88 0,0, 89 // end attribute 90 0,1,0,13,0,0,0,2,0,14 91 }; 92 93 private static class InMemoryClassLoader extends ClassLoader { 94 public Class<?> defineClass(String name, byte[] b) { 95 return defineClass(name, b, 0, b.length); 96 } 97 }; 98 99 private static final InMemoryClassLoader loader = new InMemoryClassLoader(); 100 101 private final Class<?> noName; 102 103 private NoName() throws ClassNotFoundException { 104 noName = loader.defineClass("EmptyName", NoName_bytes); 105 } 106 107 public static void main(String... args) 108 throws NoSuchMethodException, IOException, ClassNotFoundException { 109 new NoName().run(); 110 } 111 112 public void run() throws NoSuchMethodException { 113 final Class<?> cls = noName; 114 System.err.println("Trying " + cls); 115 final Method method = cls.getMethod("m", int.class, int.class); 116 final Parameter[] params = method.getParameters(); 117 System.err.println("Name " + params[0].getName()); 118 System.err.println("Name " + params[1].getName()); 119 } 120 121} 122