Mercurial > hg > openjdk > jdk8u > jdk
changeset 4444:565555e89034
7073296: Executable.equalParamTypes() incorrectly returns true when the number of params differs.
Reviewed-by: alanb, darcy
author | mduigou |
---|---|
date | Thu, 04 Aug 2011 08:53:16 -0700 |
parents | e68db408d08c |
children | b9fffbe98230 3f3a59423a7e |
files | src/share/classes/java/lang/Class.java src/share/classes/java/lang/reflect/Executable.java test/java/lang/reflect/Constructor/Equals.java |
diffstat | 3 files changed, 66 insertions(+), 8 deletions(-) [+] |
line wrap: on
line diff
--- a/src/share/classes/java/lang/Class.java Thu Aug 04 18:18:45 2011 +0800 +++ b/src/share/classes/java/lang/Class.java Thu Aug 04 08:53:16 2011 -0700 @@ -31,7 +31,6 @@ import java.lang.reflect.Field; import java.lang.reflect.Method; import java.lang.reflect.Constructor; -import java.lang.reflect.GenericDeclaration; import java.lang.reflect.Modifier; import java.lang.reflect.Type; import java.lang.reflect.TypeVariable; @@ -45,10 +44,7 @@ import java.util.Arrays; import java.util.Collection; import java.util.HashSet; -import java.util.Iterator; import java.util.List; -import java.util.LinkedList; -import java.util.LinkedHashSet; import java.util.Set; import java.util.Map; import java.util.HashMap; @@ -56,7 +52,6 @@ import sun.reflect.ConstantPool; import sun.reflect.Reflection; import sun.reflect.ReflectionFactory; -import sun.reflect.SignatureIterator; import sun.reflect.generics.factory.CoreReflectionFactory; import sun.reflect.generics.factory.GenericsFactory; import sun.reflect.generics.repository.ClassRepository; @@ -2559,7 +2554,7 @@ // Start by fetching public declared methods MethodArray methods = new MethodArray(); { - Method[] tmp = privateGetDeclaredMethods(true); + Method[] tmp = privateGetDeclaredMethods(true); methods.addAll(tmp); } // Now recur over superclass and direct superinterfaces. @@ -2909,6 +2904,7 @@ return null; } + // Doesn't use Boolean.getBoolean to avoid class init. String val = System.getProperty("sun.reflect.noCaches"); if (val != null && val.equals("true")) {
--- a/src/share/classes/java/lang/reflect/Executable.java Thu Aug 04 18:18:45 2011 +0800 +++ b/src/share/classes/java/lang/reflect/Executable.java Thu Aug 04 08:53:16 2011 -0700 @@ -65,8 +65,9 @@ if (params1[i] != params2[i]) return false; } + return true; } - return true; + return false; } Annotation[][] parseParameterAnnotations(byte[] parameterAnnotations) { @@ -365,7 +366,8 @@ * {@inheritDoc} * @throws NullPointerException {@inheritDoc} */ - public <T extends Annotation> T getAnnotation(Class<T> annotationClass) { + @SuppressWarnings("unchecked") + public <T extends Annotation> T getAnnotation(Class<T> annotationClass) { if (annotationClass == null) throw new NullPointerException();
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/test/java/lang/reflect/Constructor/Equals.java Thu Aug 04 08:53:16 2011 -0700 @@ -0,0 +1,60 @@ +/* + * Copyright (c) 2011, 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 + * @bug 7073296 + * @summary Generic framework to test Constructor.equals. + * + * @compile Equals.java + * @run main Equals + */ + +import java.lang.reflect.*; + +public class Equals { + public Equals(){} + public Equals(Object o) {/* only for testing*/} + public Equals(int i) {/* only for testing */} + + public Equals m() { return this; } + + public static void main(String [] args) { + Equals e = new Equals(); + e.equalConstructors(); + } + + public void equalConstructors() { + Constructor<?>[] constructors = Equals.class.getDeclaredConstructors(); + for(Constructor<?> ctor1 : constructors) { + for(Constructor<?> ctor2 : constructors) { + boolean expected = (ctor1 == ctor2); + if (ctor1.equals(ctor2) != expected) + throw new RuntimeException("Constructors '" + + ctor1 + "'("+ System.identityHashCode(ctor1) + ") " + + (expected ? "!=" : "==") + " '" + + ctor2 + "'("+ System.identityHashCode(ctor2) + ")"); + } + } + } +}