提交 1de3ffb3 编写于 作者: M mduigou

7073296: Executable.equalParamTypes() incorrectly returns true when the number of params differs.

Reviewed-by: alanb, darcy
上级 9f36164a
...@@ -31,7 +31,6 @@ import java.lang.reflect.Member; ...@@ -31,7 +31,6 @@ import java.lang.reflect.Member;
import java.lang.reflect.Field; import java.lang.reflect.Field;
import java.lang.reflect.Method; import java.lang.reflect.Method;
import java.lang.reflect.Constructor; import java.lang.reflect.Constructor;
import java.lang.reflect.GenericDeclaration;
import java.lang.reflect.Modifier; import java.lang.reflect.Modifier;
import java.lang.reflect.Type; import java.lang.reflect.Type;
import java.lang.reflect.TypeVariable; import java.lang.reflect.TypeVariable;
...@@ -45,10 +44,7 @@ import java.util.ArrayList; ...@@ -45,10 +44,7 @@ import java.util.ArrayList;
import java.util.Arrays; import java.util.Arrays;
import java.util.Collection; import java.util.Collection;
import java.util.HashSet; import java.util.HashSet;
import java.util.Iterator;
import java.util.List; import java.util.List;
import java.util.LinkedList;
import java.util.LinkedHashSet;
import java.util.Set; import java.util.Set;
import java.util.Map; import java.util.Map;
import java.util.HashMap; import java.util.HashMap;
...@@ -56,7 +52,6 @@ import sun.misc.Unsafe; ...@@ -56,7 +52,6 @@ import sun.misc.Unsafe;
import sun.reflect.ConstantPool; import sun.reflect.ConstantPool;
import sun.reflect.Reflection; import sun.reflect.Reflection;
import sun.reflect.ReflectionFactory; import sun.reflect.ReflectionFactory;
import sun.reflect.SignatureIterator;
import sun.reflect.generics.factory.CoreReflectionFactory; import sun.reflect.generics.factory.CoreReflectionFactory;
import sun.reflect.generics.factory.GenericsFactory; import sun.reflect.generics.factory.GenericsFactory;
import sun.reflect.generics.repository.ClassRepository; import sun.reflect.generics.repository.ClassRepository;
...@@ -2559,7 +2554,7 @@ public final ...@@ -2559,7 +2554,7 @@ public final
// Start by fetching public declared methods // Start by fetching public declared methods
MethodArray methods = new MethodArray(); MethodArray methods = new MethodArray();
{ {
Method[] tmp = privateGetDeclaredMethods(true); Method[] tmp = privateGetDeclaredMethods(true);
methods.addAll(tmp); methods.addAll(tmp);
} }
// Now recur over superclass and direct superinterfaces. // Now recur over superclass and direct superinterfaces.
...@@ -2909,6 +2904,7 @@ public final ...@@ -2909,6 +2904,7 @@ public final
return null; return null;
} }
// Doesn't use Boolean.getBoolean to avoid class init.
String val = String val =
System.getProperty("sun.reflect.noCaches"); System.getProperty("sun.reflect.noCaches");
if (val != null && val.equals("true")) { if (val != null && val.equals("true")) {
......
...@@ -65,8 +65,9 @@ public abstract class Executable extends AccessibleObject ...@@ -65,8 +65,9 @@ public abstract class Executable extends AccessibleObject
if (params1[i] != params2[i]) if (params1[i] != params2[i])
return false; return false;
} }
return true;
} }
return true; return false;
} }
Annotation[][] parseParameterAnnotations(byte[] parameterAnnotations) { Annotation[][] parseParameterAnnotations(byte[] parameterAnnotations) {
...@@ -365,7 +366,8 @@ public abstract class Executable extends AccessibleObject ...@@ -365,7 +366,8 @@ public abstract class Executable extends AccessibleObject
* {@inheritDoc} * {@inheritDoc}
* @throws NullPointerException {@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) if (annotationClass == null)
throw new NullPointerException(); throw new NullPointerException();
......
/*
* 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) + ")");
}
}
}
}
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册