--- old/src/java.base/share/classes/java/lang/reflect/Executable.java 2014-10-31 12:16:19.013726064 -0400 +++ new/src/java.base/share/classes/java/lang/reflect/Executable.java 2014-10-31 12:16:18.916724920 -0400 @@ -286,6 +286,64 @@ } /** + * Behaves like {@code getGenericParameterTypes}, but returns type + * information for all parameters, including synthetic parameters. + */ + Type[] getAllGenericParameterTypes() { + Type[] tmp = allGenericParams; + if (tmp == null) { + tmp = privateGetAllGenericParameterTypes(); + allGenericParams = tmp; + } + return tmp; + } + + private Type[] privateGetAllGenericParameterTypes() { + final boolean genericInfo = hasGenericInformation(); + + // Easy case: we don't have generic parameter information. In + // this case, we just return the result of + // getParameterTypes(). + if (!genericInfo) { + return getParameterTypes(); + } else { + final boolean realParamData = hasRealParameterData(); + final Type[] genericParamTypes = getGenericParameterTypes(); + final Type[] nonGenericParamTypes = getParameterTypes(); + final Type[] out = new Type[nonGenericParamTypes.length]; + final Parameter[] params = getParameters(); + int fromidx = 0; + // If we have real parameter data, then we use the + // synthetic and mandate flags to our advantage. + if (realParamData) { + for (int i = 0; i < out.length; i++) { + final Parameter param = params[i]; + if (param.isSynthetic() || param.isImplicit()) { + // If we hit a synthetic or mandated parameter, + // use the non generic parameter info. + out[i] = nonGenericParamTypes[i]; + } else { + // Otherwise, use the generic parameter info. + out[i] = genericParamTypes[fromidx]; + fromidx++; + } + } + } else { + // Otherwise, use the non-generic parameter data. + // Without method parameter reflection data, we have + // no way to figure out which parameters are + // synthetic/mandated, thus, no way to match up the + // indexes. + return genericParamTypes.length == nonGenericParamTypes.length ? + genericParamTypes : nonGenericParamTypes; + } + return out; + } + } + + private transient volatile Type[] allGenericParams; + + /** * Returns an array of {@code Parameter} objects that represent * all the parameters to the underlying executable represented by * this object. Returns an array of length 0 if the executable @@ -646,7 +704,7 @@ getConstantPool(getDeclaringClass()), this, getDeclaringClass(), - getGenericParameterTypes(), + getAllGenericParameterTypes(), TypeAnnotation.TypeAnnotationTarget.METHOD_FORMAL_PARAMETER); } --- old/src/java.base/share/classes/java/lang/reflect/Parameter.java 2014-10-31 12:16:19.297729413 -0400 +++ new/src/java.base/share/classes/java/lang/reflect/Parameter.java 2014-10-31 12:16:19.200728269 -0400 @@ -198,7 +198,7 @@ public Type getParameterizedType() { Type tmp = parameterTypeCache; if (null == tmp) { - tmp = executable.getGenericParameterTypes()[index]; + tmp = executable.getAllGenericParameterTypes()[index]; parameterTypeCache = tmp; } --- /dev/null 2014-10-20 11:41:52.790260796 -0400 +++ new/test/java/lang/reflect/Parameter/InnerClassToString.java 2014-10-31 12:16:19.480731570 -0400 @@ -0,0 +1,60 @@ +/* + * Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +/* + * @test + * @compile -parameters InnerClassToString.java + * @run main InnerClassToString + * @summary javac should generate method parameters correctly. + */ + +import java.lang.reflect.Constructor; +import java.lang.reflect.Parameter; +import java.util.Set; + +// Test copied and expanded from webbug group report. +public class InnerClassToString { + public static void main(String[] args) throws Exception { + Constructor genericConstructor = + MyEntity.class.getConstructor(InnerClassToString.class, Set.class); + for (Parameter parameter : genericConstructor.getParameters()) { + System.out.println(parameter.toString()); + System.out.println(parameter.getType()); + System.out.println(parameter.getParameterizedType()); + System.out.println(parameter.getAnnotatedType()); + } + Constructor nongenericConstructor = + MyEntity.class.getConstructor(InnerClassToString.class, String.class); + for (Parameter parameter : nongenericConstructor.getParameters()) { + System.out.println(parameter.toString()); + System.out.println(parameter.getType()); + System.out.println(parameter.getParameterizedType()); + System.out.println(parameter.getAnnotatedType()); + } + } + + public class MyEntity { + public MyEntity(Set names) {} + public MyEntity(String names) {} + } +} --- /dev/null 2014-10-20 11:41:52.790260796 -0400 +++ new/test/java/lang/reflect/Parameter/InnerClassToStringNoParameters.java 2014-10-31 12:16:19.799735332 -0400 @@ -0,0 +1,32 @@ +/* + * Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +/* + * @test + * @compile InnerClassToString.java + * @run main InnerClassToString + * @summary javac should generate method parameters correctly. + */ + +// We don't need any additional classes. We just reuse +// InnerClassToString, but compile it without parameters.