提交 552b1a32 编写于 作者: J jjg

7077389: Reflection classes do not build with javac -Xlint:all -Werror

Reviewed-by: darcy
Contributed-by: alexandre.boulgakov@oracle.com
上级 a925cd89
......@@ -34,6 +34,7 @@ LIBRARY = java
PRODUCT = java
SUBDIRS_MAKEFLAGS += JAVAC_MAX_WARNINGS=true
SUBDIRS_MAKEFLAGS += JAVAC_WARNINGS_FATAL=true
JAVAC_MAX_WARNINGS=true
include $(BUILDDIR)/common/Defs.gmk
# windows compiler flags
......
......@@ -474,10 +474,10 @@ class Array {
* Private
*/
private static native Object newArray(Class componentType, int length)
private static native Object newArray(Class<?> componentType, int length)
throws NegativeArraySizeException;
private static native Object multiNewArray(Class componentType,
private static native Object multiNewArray(Class<?> componentType,
int[] dimensions)
throws IllegalArgumentException, NegativeArraySizeException;
......
......@@ -27,14 +27,12 @@ package java.lang.reflect;
import sun.reflect.ConstructorAccessor;
import sun.reflect.Reflection;
import sun.reflect.annotation.AnnotationParser;
import sun.reflect.generics.repository.ConstructorRepository;
import sun.reflect.generics.factory.CoreReflectionFactory;
import sun.reflect.generics.factory.GenericsFactory;
import sun.reflect.generics.scope.ConstructorScope;
import java.lang.annotation.Annotation;
import java.lang.annotation.AnnotationFormatError;
import java.lang.reflect.Modifier;
/**
* {@code Constructor} provides information about, and access to, a single
......@@ -184,6 +182,7 @@ public final class Constructor<T> extends Executable {
* @since 1.5
*/
@Override
@SuppressWarnings({ "rawtypes", "unchecked" })
public TypeVariable<Constructor<T>>[] getTypeParameters() {
if (getSignature() != null) {
return (TypeVariable<Constructor<T>>[])getGenericInfo().getTypeParameters();
......@@ -197,7 +196,7 @@ public final class Constructor<T> extends Executable {
*/
@Override
public Class<?>[] getParameterTypes() {
return (Class<?>[]) parameterTypes.clone();
return parameterTypes.clone();
}
/**
......@@ -217,7 +216,7 @@ public final class Constructor<T> extends Executable {
*/
@Override
public Class<?>[] getExceptionTypes() {
return (Class<?>[])exceptionTypes.clone();
return exceptionTypes.clone();
}
......@@ -392,7 +391,9 @@ public final class Constructor<T> extends Executable {
if (ca == null) {
ca = acquireConstructorAccessor();
}
return (T) ca.newInstance(initargs);
@SuppressWarnings("unchecked")
T inst = (T) ca.newInstance(initargs);
return inst;
}
/**
......
......@@ -29,9 +29,6 @@ import java.lang.annotation.*;
import java.util.Map;
import sun.reflect.annotation.AnnotationParser;
import sun.reflect.generics.repository.ConstructorRepository;
import sun.reflect.generics.factory.CoreReflectionFactory;
import sun.reflect.generics.factory.GenericsFactory;
import sun.reflect.generics.scope.ConstructorScope;
/**
* A shared superclass for the common functionality of {@link Method}
......@@ -366,8 +363,8 @@ public abstract class Executable extends AccessibleObject
* {@inheritDoc}
* @throws NullPointerException {@inheritDoc}
*/
@SuppressWarnings("unchecked")
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();
......
......@@ -1012,6 +1012,7 @@ class Field extends AccessibleObject implements Member {
* @throws NullPointerException {@inheritDoc}
* @since 1.5
*/
@SuppressWarnings("unchecked")
public <T extends Annotation> T getAnnotation(Class<T> annotationClass) {
if (annotationClass == null)
throw new NullPointerException();
......
......@@ -194,6 +194,7 @@ public final class Method extends Executable {
* @since 1.5
*/
@Override
@SuppressWarnings({ "rawtypes", "unchecked" })
public TypeVariable<Method>[] getTypeParameters() {
if (getGenericSignature() != null)
return (TypeVariable<Method>[])getGenericInfo().getTypeParameters();
......@@ -246,7 +247,7 @@ public final class Method extends Executable {
*/
@Override
public Class<?>[] getParameterTypes() {
return (Class<?>[]) parameterTypes.clone();
return parameterTypes.clone();
}
/**
......@@ -266,7 +267,7 @@ public final class Method extends Executable {
*/
@Override
public Class<?>[] getExceptionTypes() {
return (Class<?>[]) exceptionTypes.clone();
return exceptionTypes.clone();
}
/**
......
......@@ -604,15 +604,12 @@ public class Proxy implements java.io.Serializable {
* Invoke its constructor with the designated invocation handler.
*/
try {
Constructor cons = cl.getConstructor(constructorParams);
Constructor<?> cons = cl.getConstructor(constructorParams);
return cons.newInstance(new Object[] { h });
} catch (NoSuchMethodException e) {
throw new InternalError(e.toString());
} catch (IllegalAccessException e) {
throw new InternalError(e.toString());
} catch (InstantiationException e) {
throw new InternalError(e.toString());
} catch (InvocationTargetException e) {
} catch (NoSuchMethodException |
IllegalAccessException |
InstantiationException |
InvocationTargetException e) {
throw new InternalError(e.toString());
}
}
......@@ -661,6 +658,6 @@ public class Proxy implements java.io.Serializable {
return p.h;
}
private static native Class defineClass0(ClassLoader loader, String name,
byte[] b, int off, int len);
private static native Class<?> defineClass0(ClassLoader loader, String name,
byte[] b, int off, int len);
}
......@@ -382,7 +382,7 @@ class AccessorGenerator implements ClassFileConstants {
/** Returns class name in "internal" form (i.e., '/' separators
instead of '.') */
protected static String getClassName
(Class c, boolean addPrefixAndSuffixForNonPrimitiveTypes)
(Class<?> c, boolean addPrefixAndSuffixForNonPrimitiveTypes)
{
if (c.isPrimitive()) {
if (c == Boolean.TYPE) {
......@@ -490,7 +490,7 @@ class AccessorGenerator implements ClassFileConstants {
}
}
protected short indexForPrimitiveType(Class type) {
protected short indexForPrimitiveType(Class<?> type) {
if (type == Boolean.TYPE) {
return booleanIdx;
} else if (type == Byte.TYPE) {
......@@ -511,7 +511,7 @@ class AccessorGenerator implements ClassFileConstants {
throw new InternalError("Should have found primitive type");
}
protected short ctorIndexForPrimitiveType(Class type) {
protected short ctorIndexForPrimitiveType(Class<?> type) {
if (type == Boolean.TYPE) {
return booleanCtorIdx;
} else if (type == Byte.TYPE) {
......@@ -534,7 +534,7 @@ class AccessorGenerator implements ClassFileConstants {
/** Returns true for widening or identity conversions for primitive
types only */
protected static boolean canWidenTo(Class type, Class otherType) {
protected static boolean canWidenTo(Class<?> type, Class<?> otherType) {
if (!type.isPrimitive()) {
return false;
}
......@@ -609,8 +609,8 @@ class AccessorGenerator implements ClassFileConstants {
called and returned true. */
protected static void emitWideningBytecodeForPrimitiveConversion
(ClassFileAssembler cb,
Class fromType,
Class toType)
Class<?> fromType,
Class<?> toType)
{
// Note that widening conversions for integral types (i.e., "b2s",
// "s2i") are no-ops since values on the Java stack are
......@@ -650,7 +650,7 @@ class AccessorGenerator implements ClassFileConstants {
// Otherwise, was identity or no-op conversion. Fall through.
}
protected short unboxingMethodForPrimitiveType(Class primType) {
protected short unboxingMethodForPrimitiveType(Class<?> primType) {
if (primType == Boolean.TYPE) {
return booleanUnboxIdx;
} else if (primType == Byte.TYPE) {
......@@ -671,7 +671,7 @@ class AccessorGenerator implements ClassFileConstants {
throw new InternalError("Illegal primitive type " + primType.getName());
}
protected static final Class[] primitiveTypes = new Class[] {
protected static final Class<?>[] primitiveTypes = new Class<?>[] {
Boolean.TYPE,
Byte.TYPE,
Character.TYPE,
......@@ -683,11 +683,11 @@ class AccessorGenerator implements ClassFileConstants {
};
/** We don't consider "Void" to be a primitive type */
protected static boolean isPrimitive(Class c) {
protected static boolean isPrimitive(Class<?> c) {
return (c.isPrimitive() && c != Void.TYPE);
}
protected int typeSizeInStackSlots(Class c) {
protected int typeSizeInStackSlots(Class<?> c) {
if (c == Void.TYPE) {
return 0;
}
......
......@@ -32,9 +32,9 @@ import java.lang.reflect.Constructor;
bootstrapping. */
class BootstrapConstructorAccessorImpl extends ConstructorAccessorImpl {
private Constructor constructor;
private Constructor<?> constructor;
BootstrapConstructorAccessorImpl(Constructor c) {
BootstrapConstructorAccessorImpl(Constructor<?> c) {
this.constructor = c;
}
......
......@@ -51,8 +51,8 @@ class ClassDefiner {
than would otherwise be possible, decreasing run-time
footprint. </P>
*/
static Class defineClass(String name, byte[] bytes, int off, int len,
final ClassLoader parentClassLoader)
static Class<?> defineClass(String name, byte[] bytes, int off, int len,
final ClassLoader parentClassLoader)
{
ClassLoader newLoader = AccessController.doPrivileged(
new PrivilegedAction<ClassLoader>() {
......
......@@ -34,8 +34,8 @@ import java.lang.reflect.*;
public class ConstantPool {
// Number of entries in this constant pool (= maximum valid constant pool index)
public int getSize() { return getSize0 (constantPoolOop); }
public Class getClassAt (int index) { return getClassAt0 (constantPoolOop, index); }
public Class getClassAtIfLoaded (int index) { return getClassAtIfLoaded0 (constantPoolOop, index); }
public Class<?> getClassAt (int index) { return getClassAt0 (constantPoolOop, index); }
public Class<?> getClassAtIfLoaded (int index) { return getClassAtIfLoaded0 (constantPoolOop, index); }
// Returns either a Method or Constructor.
// Static initializers are returned as Method objects.
public Member getMethodAt (int index) { return getMethodAt0 (constantPoolOop, index); }
......@@ -64,8 +64,8 @@ public class ConstantPool {
private Object constantPoolOop;
private native int getSize0 (Object constantPoolOop);
private native Class getClassAt0 (Object constantPoolOop, int index);
private native Class getClassAtIfLoaded0 (Object constantPoolOop, int index);
private native Class<?> getClassAt0 (Object constantPoolOop, int index);
private native Class<?> getClassAtIfLoaded0 (Object constantPoolOop, int index);
private native Member getMethodAt0 (Object constantPoolOop, int index);
private native Member getMethodAtIfLoaded0(Object constantPoolOop, int index);
private native Field getFieldAt0 (Object constantPoolOop, int index);
......
......@@ -25,7 +25,6 @@
package sun.reflect;
import java.util.Iterator;
import java.util.List;
import java.util.ArrayList;
......@@ -53,7 +52,7 @@ class Label {
short patchBCI;
int stackDepth;
}
private List/*<PatchInfo>*/ patches = new ArrayList();
private List<PatchInfo> patches = new ArrayList<>();
public Label() {
}
......@@ -67,8 +66,7 @@ class Label {
}
public void bind() {
for (Iterator iter = patches.iterator(); iter.hasNext(); ) {
PatchInfo patch = (PatchInfo) iter.next();
for (PatchInfo patch : patches){
short curBCI = patch.asm.getLength();
short offset = (short) (curBCI - patch.instrBCI);
patch.asm.emitShort(patch.patchBCI, offset);
......
......@@ -25,10 +25,8 @@
package sun.reflect;
import java.lang.reflect.*;
import java.security.AccessController;
import java.security.PrivilegedAction;
import sun.misc.Unsafe;
/** Generator for sun.reflect.MethodAccessor and
sun.reflect.ConstructorAccessor objects using bytecodes to
......@@ -50,11 +48,11 @@ class MethodAccessorGenerator extends AccessorGenerator {
private static volatile int constructorSymnum = 0;
private static volatile int serializationConstructorSymnum = 0;
private Class declaringClass;
private Class[] parameterTypes;
private Class returnType;
private boolean isConstructor;
private boolean forSerialization;
private Class<?> declaringClass;
private Class<?>[] parameterTypes;
private Class<?> returnType;
private boolean isConstructor;
private boolean forSerialization;
private short targetMethodRef;
private short invokeIdx;
......@@ -67,11 +65,11 @@ class MethodAccessorGenerator extends AccessorGenerator {
}
/** This routine is not thread-safe */
public MethodAccessor generateMethod(Class declaringClass,
String name,
Class[] parameterTypes,
Class returnType,
Class[] checkedExceptions,
public MethodAccessor generateMethod(Class<?> declaringClass,
String name,
Class<?>[] parameterTypes,
Class<?> returnType,
Class<?>[] checkedExceptions,
int modifiers)
{
return (MethodAccessor) generate(declaringClass,
......@@ -86,9 +84,9 @@ class MethodAccessorGenerator extends AccessorGenerator {
}
/** This routine is not thread-safe */
public ConstructorAccessor generateConstructor(Class declaringClass,
Class[] parameterTypes,
Class[] checkedExceptions,
public ConstructorAccessor generateConstructor(Class<?> declaringClass,
Class<?>[] parameterTypes,
Class<?>[] checkedExceptions,
int modifiers)
{
return (ConstructorAccessor) generate(declaringClass,
......@@ -104,11 +102,11 @@ class MethodAccessorGenerator extends AccessorGenerator {
/** This routine is not thread-safe */
public SerializationConstructorAccessorImpl
generateSerializationConstructor(Class declaringClass,
Class[] parameterTypes,
Class[] checkedExceptions,
generateSerializationConstructor(Class<?> declaringClass,
Class<?>[] parameterTypes,
Class<?>[] checkedExceptions,
int modifiers,
Class targetConstructorClass)
Class<?> targetConstructorClass)
{
return (SerializationConstructorAccessorImpl)
generate(declaringClass,
......@@ -123,15 +121,15 @@ class MethodAccessorGenerator extends AccessorGenerator {
}
/** This routine is not thread-safe */
private MagicAccessorImpl generate(final Class declaringClass,
private MagicAccessorImpl generate(final Class<?> declaringClass,
String name,
Class[] parameterTypes,
Class returnType,
Class[] checkedExceptions,
Class<?>[] parameterTypes,
Class<?> returnType,
Class<?>[] checkedExceptions,
int modifiers,
boolean isConstructor,
boolean forSerialization,
Class serializationTargetClass)
Class<?> serializationTargetClass)
{
ByteVector vec = ByteVectorFactory.create();
asm = new ClassFileAssembler(vec);
......@@ -340,7 +338,7 @@ class MethodAccessorGenerator extends AccessorGenerator {
// Output class information for non-primitive parameter types
nonPrimitiveParametersBaseIdx = add(asm.cpi(), S2);
for (int i = 0; i < parameterTypes.length; i++) {
Class c = parameterTypes[i];
Class<?> c = parameterTypes[i];
if (!isPrimitive(c)) {
asm.emitConstantPoolUTF8(getClassName(c, false));
asm.emitConstantPoolClass(asm.cpi());
......@@ -403,10 +401,8 @@ class MethodAccessorGenerator extends AccessorGenerator {
0,
bytes.length,
declaringClass.getClassLoader()).newInstance();
} catch (InstantiationException e) {
throw (InternalError)
new InternalError().initCause(e);
} catch (IllegalAccessException e) {
} catch (InstantiationException |
IllegalAccessException e) {
throw (InternalError)
new InternalError().initCause(e);
}
......@@ -530,7 +526,7 @@ class MethodAccessorGenerator extends AccessorGenerator {
byte count = 1; // both invokeinterface opcode's "count" as well as
// num args of other invoke bytecodes
for (int i = 0; i < parameterTypes.length; i++) {
Class paramType = parameterTypes[i];
Class<?> paramType = parameterTypes[i];
count += (byte) typeSizeInStackSlots(paramType);
if (nextParamLabel != null) {
nextParamLabel.bind();
......@@ -577,7 +573,7 @@ class MethodAccessorGenerator extends AccessorGenerator {
nextParamLabel = new Label();
for (int j = 0; j < primitiveTypes.length; j++) {
Class c = primitiveTypes[j];
Class<?> c = primitiveTypes[j];
if (canWidenTo(c, paramType)) {
if (l != null) {
l.bind();
......
......@@ -31,11 +31,11 @@ import java.lang.reflect.*;
afterward, switches to bytecode-based implementation */
class NativeConstructorAccessorImpl extends ConstructorAccessorImpl {
private Constructor c;
private Constructor<?> c;
private DelegatingConstructorAccessorImpl parent;
private int numInvocations;
NativeConstructorAccessorImpl(Constructor c) {
NativeConstructorAccessorImpl(Constructor<?> c) {
this.c = c;
}
......@@ -61,7 +61,7 @@ class NativeConstructorAccessorImpl extends ConstructorAccessorImpl {
this.parent = parent;
}
private static native Object newInstance0(Constructor c, Object[] args)
private static native Object newInstance0(Constructor<?> c, Object[] args)
throws InstantiationException,
IllegalArgumentException,
InvocationTargetException;
......
......@@ -26,7 +26,6 @@
package sun.reflect;
import java.lang.reflect.*;
import java.util.Collections;
import java.util.HashMap;
import java.util.Map;
......@@ -39,17 +38,17 @@ public class Reflection {
view, where they are sensitive or they may contain VM-internal objects.
These Maps are updated very rarely. Rather than synchronize on
each access, we use copy-on-write */
private static volatile Map<Class,String[]> fieldFilterMap;
private static volatile Map<Class,String[]> methodFilterMap;
private static volatile Map<Class<?>,String[]> fieldFilterMap;
private static volatile Map<Class<?>,String[]> methodFilterMap;
static {
Map<Class,String[]> map = new HashMap<Class,String[]>();
Map<Class<?>,String[]> map = new HashMap<Class<?>,String[]>();
map.put(Reflection.class,
new String[] {"fieldFilterMap", "methodFilterMap"});
map.put(System.class, new String[] {"security"});
fieldFilterMap = map;
methodFilterMap = new HashMap<Class,String[]>();
methodFilterMap = new HashMap<>();
}
/** Returns the class of the method <code>realFramesToSkip</code>
......@@ -61,7 +60,7 @@ public class Reflection {
java.lang.reflect.Method.invoke() and its implementation are
completely ignored and do not count toward the number of "real"
frames skipped. */
public static native Class getCallerClass(int realFramesToSkip);
public static native Class<?> getCallerClass(int realFramesToSkip);
/** Retrieves the access flags written to the class file. For
inner classes these flags may differ from those returned by
......@@ -71,18 +70,18 @@ public class Reflection {
to compatibility reasons; see 4471811. Only the values of the
low 13 bits (i.e., a mask of 0x1FFF) are guaranteed to be
valid. */
private static native int getClassAccessFlags(Class c);
private static native int getClassAccessFlags(Class<?> c);
/** A quick "fast-path" check to try to avoid getCallerClass()
calls. */
public static boolean quickCheckMemberAccess(Class memberClass,
public static boolean quickCheckMemberAccess(Class<?> memberClass,
int modifiers)
{
return Modifier.isPublic(getClassAccessFlags(memberClass) & modifiers);
}
public static void ensureMemberAccess(Class currentClass,
Class memberClass,
public static void ensureMemberAccess(Class<?> currentClass,
Class<?> memberClass,
Object target,
int modifiers)
throws IllegalAccessException
......@@ -101,13 +100,13 @@ public class Reflection {
}
}
public static boolean verifyMemberAccess(Class currentClass,
public static boolean verifyMemberAccess(Class<?> currentClass,
// Declaring class of field
// or method
Class memberClass,
Class<?> memberClass,
// May be NULL in case of statics
Object target,
int modifiers)
Object target,
int modifiers)
{
// Verify that currentClass can access a field, method, or
// constructor of memberClass, where that member's access bits are
......@@ -162,7 +161,7 @@ public class Reflection {
if (Modifier.isProtected(modifiers)) {
// Additional test for protected members: JLS 6.6.2
Class targetClass = (target == null ? memberClass : target.getClass());
Class<?> targetClass = (target == null ? memberClass : target.getClass());
if (targetClass != currentClass) {
if (!gotIsSameClassPackage) {
isSameClassPackage = isSameClassPackage(currentClass, memberClass);
......@@ -179,7 +178,7 @@ public class Reflection {
return true;
}
private static boolean isSameClassPackage(Class c1, Class c2) {
private static boolean isSameClassPackage(Class<?> c1, Class<?> c2) {
return isSameClassPackage(c1.getClassLoader(), c1.getName(),
c2.getClassLoader(), c2.getName());
}
......@@ -234,8 +233,8 @@ public class Reflection {
}
}
static boolean isSubclassOf(Class queryClass,
Class ofClass)
static boolean isSubclassOf(Class<?> queryClass,
Class<?> ofClass)
{
while (queryClass != null) {
if (queryClass == ofClass) {
......@@ -247,31 +246,31 @@ public class Reflection {
}
// fieldNames must contain only interned Strings
public static synchronized void registerFieldsToFilter(Class containingClass,
public static synchronized void registerFieldsToFilter(Class<?> containingClass,
String ... fieldNames) {
fieldFilterMap =
registerFilter(fieldFilterMap, containingClass, fieldNames);
}
// methodNames must contain only interned Strings
public static synchronized void registerMethodsToFilter(Class containingClass,
public static synchronized void registerMethodsToFilter(Class<?> containingClass,
String ... methodNames) {
methodFilterMap =
registerFilter(methodFilterMap, containingClass, methodNames);
}
private static Map<Class,String[]> registerFilter(Map<Class,String[]> map,
Class containingClass, String ... names) {
private static Map<Class<?>,String[]> registerFilter(Map<Class<?>,String[]> map,
Class<?> containingClass, String ... names) {
if (map.get(containingClass) != null) {
throw new IllegalArgumentException
("Filter already registered: " + containingClass);
}
map = new HashMap<Class,String[]>(map);
map = new HashMap<Class<?>,String[]>(map);
map.put(containingClass, names);
return map;
}
public static Field[] filterFields(Class containingClass,
public static Field[] filterFields(Class<?> containingClass,
Field[] fields) {
if (fieldFilterMap == null) {
// Bootstrapping
......@@ -280,7 +279,7 @@ public class Reflection {
return (Field[])filter(fields, fieldFilterMap.get(containingClass));
}
public static Method[] filterMethods(Class containingClass, Method[] methods) {
public static Method[] filterMethods(Class<?> containingClass, Method[] methods) {
if (methodFilterMap == null) {
// Bootstrapping
return methods;
......
......@@ -161,7 +161,7 @@ public class ReflectionFactory {
}
}
public ConstructorAccessor newConstructorAccessor(Constructor c) {
public ConstructorAccessor newConstructorAccessor(Constructor<?> c) {
checkInitted();
Class<?> declaringClass = c.getDeclaringClass();
......@@ -250,14 +250,14 @@ public class ReflectionFactory {
/** Creates a new java.lang.reflect.Constructor. Access checks as
per java.lang.reflect.AccessibleObject are not overridden. */
public Constructor newConstructor(Class<?> declaringClass,
Class<?>[] parameterTypes,
Class<?>[] checkedExceptions,
int modifiers,
int slot,
String signature,
byte[] annotations,
byte[] parameterAnnotations)
public Constructor<?> newConstructor(Class<?> declaringClass,
Class<?>[] parameterTypes,
Class<?>[] checkedExceptions,
int modifiers,
int slot,
String signature,
byte[] annotations,
byte[] parameterAnnotations)
{
return langReflectAccess().newConstructor(declaringClass,
parameterTypes,
......@@ -281,13 +281,13 @@ public class ReflectionFactory {
/** Gets the ConstructorAccessor object for a
java.lang.reflect.Constructor */
public ConstructorAccessor getConstructorAccessor(Constructor c) {
public ConstructorAccessor getConstructorAccessor(Constructor<?> c) {
return langReflectAccess().getConstructorAccessor(c);
}
/** Sets the ConstructorAccessor object for a
java.lang.reflect.Constructor */
public void setConstructorAccessor(Constructor c,
public void setConstructorAccessor(Constructor<?> c,
ConstructorAccessor accessor)
{
langReflectAccess().setConstructorAccessor(c, accessor);
......@@ -320,8 +320,8 @@ public class ReflectionFactory {
//
//
public Constructor newConstructorForSerialization
(Class<?> classToInstantiate, Constructor constructorToCall)
public Constructor<?> newConstructorForSerialization
(Class<?> classToInstantiate, Constructor<?> constructorToCall)
{
// Fast path
if (constructorToCall.getDeclaringClass() == classToInstantiate) {
......@@ -334,18 +334,18 @@ public class ReflectionFactory {
constructorToCall.getExceptionTypes(),
constructorToCall.getModifiers(),
constructorToCall.getDeclaringClass());
Constructor c = newConstructor(constructorToCall.getDeclaringClass(),
constructorToCall.getParameterTypes(),
constructorToCall.getExceptionTypes(),
constructorToCall.getModifiers(),
langReflectAccess().
getConstructorSlot(constructorToCall),
langReflectAccess().
getConstructorSignature(constructorToCall),
langReflectAccess().
getConstructorAnnotations(constructorToCall),
langReflectAccess().
getConstructorParameterAnnotations(constructorToCall));
Constructor<?> c = newConstructor(constructorToCall.getDeclaringClass(),
constructorToCall.getParameterTypes(),
constructorToCall.getExceptionTypes(),
constructorToCall.getModifiers(),
langReflectAccess().
getConstructorSlot(constructorToCall),
langReflectAccess().
getConstructorSignature(constructorToCall),
langReflectAccess().
getConstructorAnnotations(constructorToCall),
langReflectAccess().
getConstructorParameterAnnotations(constructorToCall));
setConstructorAccessor(c, acc);
return c;
}
......@@ -393,9 +393,7 @@ public class ReflectionFactory {
try {
inflationThreshold = Integer.parseInt(val);
} catch (NumberFormatException e) {
throw (RuntimeException)
new RuntimeException("Unable to parse property sun.reflect.inflationThreshold").
initCause(e);
throw new RuntimeException("Unable to parse property sun.reflect.inflationThreshold", e);
}
}
......
......@@ -30,7 +30,7 @@ import java.lang.reflect.Modifier;
class UnsafeFieldAccessorFactory {
static FieldAccessor newFieldAccessor(Field field, boolean override) {
Class type = field.getType();
Class<?> type = field.getType();
boolean isStatic = Modifier.isStatic(field.getModifiers());
boolean isFinal = Modifier.isFinal(field.getModifiers());
boolean isVolatile = Modifier.isVolatile(field.getModifiers());
......
......@@ -40,12 +40,15 @@ abstract class UnsafeFieldAccessorImpl extends FieldAccessorImpl {
static final Unsafe unsafe = Unsafe.getUnsafe();
protected final Field field;
protected final int fieldOffset;
protected final long fieldOffset;
protected final boolean isFinal;
UnsafeFieldAccessorImpl(Field field) {
this.field = field;
fieldOffset = unsafe.fieldOffset(field);
if (Modifier.isStatic(field.getModifiers()))
fieldOffset = unsafe.staticFieldOffset(field);
else
fieldOffset = unsafe.objectFieldOffset(field);
isFinal = Modifier.isFinal(field.getModifiers());
}
......
......@@ -187,6 +187,7 @@ public class AnnotationParser {
* TypeNotPresentException if a referenced annotation type is not
* available at runtime
*/
@SuppressWarnings("unchecked")
private static Annotation parseAnnotation(ByteBuffer buf,
ConstantPool constPool,
Class<?> container,
......@@ -200,7 +201,7 @@ public class AnnotationParser {
annotationClass = (Class<? extends Annotation>)parseSig(sig, container);
} catch (IllegalArgumentException ex) {
// support obsolete early jsr175 format class files
annotationClass = constPool.getClassAt(typeIndex);
annotationClass = (Class<? extends Annotation>)constPool.getClassAt(typeIndex);
}
} catch (NoClassDefFoundError e) {
if (exceptionOnMissingAnnotationClass)
......@@ -256,7 +257,7 @@ public class AnnotationParser {
Class<? extends Annotation> type, Map<String, Object> memberValues)
{
return (Annotation) Proxy.newProxyInstance(
type.getClassLoader(), new Class[] { type },
type.getClassLoader(), new Class<?>[] { type },
new AnnotationInvocationHandler(type, memberValues));
}
......@@ -287,6 +288,7 @@ public class AnnotationParser {
* The member must be of the indicated type. If it is not, this
* method returns an AnnotationTypeMismatchExceptionProxy.
*/
@SuppressWarnings("unchecked")
public static Object parseMemberValue(Class<?> memberType,
ByteBuffer buf,
ConstantPool constPool,
......@@ -411,6 +413,7 @@ public class AnnotationParser {
* u2 const_name_index;
* } enum_const_value;
*/
@SuppressWarnings({"rawtypes", "unchecked"})
private static Object parseEnumValue(Class<? extends Enum> enumType, ByteBuffer buf,
ConstantPool constPool,
Class<?> container) {
......@@ -433,7 +436,7 @@ public class AnnotationParser {
return Enum.valueOf(enumType, constName);
} catch(IllegalArgumentException e) {
return new EnumConstantNotPresentExceptionProxy(
(Class<? extends Enum>)enumType, constName);
(Class<? extends Enum<?>>)enumType, constName);
}
}
......@@ -451,6 +454,7 @@ public class AnnotationParser {
* If the array values do not match arrayType, an
* AnnotationTypeMismatchExceptionProxy will be returned.
*/
@SuppressWarnings("unchecked")
private static Object parseArray(Class<?> arrayType,
ByteBuffer buf,
ConstantPool constPool,
......@@ -479,7 +483,7 @@ public class AnnotationParser {
} else if (componentType == Class.class) {
return parseClassArray(length, buf, constPool, container);
} else if (componentType.isEnum()) {
return parseEnumArray(length, (Class<? extends Enum>)componentType, buf,
return parseEnumArray(length, (Class<? extends Enum<?>>)componentType, buf,
constPool, container);
} else {
assert componentType.isAnnotation();
......@@ -679,7 +683,7 @@ public class AnnotationParser {
return typeMismatch ? exceptionProxy(tag) : result;
}
private static Object parseEnumArray(int length, Class<? extends Enum> enumType,
private static Object parseEnumArray(int length, Class<? extends Enum<?>> enumType,
ByteBuffer buf,
ConstantPool constPool,
Class<?> container) {
......
......@@ -24,7 +24,6 @@
*/
package sun.reflect.annotation;
import java.lang.annotation.*;
/**
* ExceptionProxy for EnumConstantNotPresentException.
......@@ -33,10 +32,10 @@ import java.lang.annotation.*;
* @since 1.5
*/
public class EnumConstantNotPresentExceptionProxy extends ExceptionProxy {
Class<? extends Enum> enumType;
Class<? extends Enum<?>> enumType;
String constName;
public EnumConstantNotPresentExceptionProxy(Class<? extends Enum> enumType,
public EnumConstantNotPresentExceptionProxy(Class<? extends Enum<?>> enumType,
String constName) {
this.enumType = enumType;
this.constName = constName;
......
......@@ -157,7 +157,7 @@ public class TypeVariableImpl<D extends GenericDeclaration>
@Override
public boolean equals(Object o) {
if (o instanceof TypeVariable) {
TypeVariable that = (TypeVariable) o;
TypeVariable<?> that = (TypeVariable<?>) o;
GenericDeclaration thatDecl = that.getGenericDeclaration();
String thatName = that.getName();
......
......@@ -69,7 +69,7 @@ public abstract class GenericDeclRepository<S extends Signature>
// first, extract type parameter subtree(s) from AST
FormalTypeParameter[] ftps = getTree().getFormalTypeParameters();
// create array to store reified subtree(s)
TypeVariable[] tps = new TypeVariable[ftps.length];
TypeVariable<?>[] tps = new TypeVariable<?>[ftps.length];
// reify all subtrees
for (int i = 0; i < ftps.length; i++) {
Reifier r = getReifier(); // obtain visitor
......
......@@ -83,8 +83,8 @@ public abstract class AbstractScope<D extends GenericDeclaration>
* @return the requested type variable, if found
*/
public TypeVariable<?> lookup(String name) {
TypeVariable[] tas = getRecvr().getTypeParameters();
for (TypeVariable/*<?>*/ tv : tas) {
TypeVariable<?>[] tas = getRecvr().getTypeParameters();
for (TypeVariable<?> tv : tas) {
if (tv.getName().equals(name)) {return tv;}
}
return getEnclosingScope().lookup(name);
......
......@@ -32,10 +32,10 @@ import java.lang.reflect.Constructor;
* This class represents the scope containing the type variables of
* a constructor.
*/
public class ConstructorScope extends AbstractScope<Constructor> {
public class ConstructorScope extends AbstractScope<Constructor<?>> {
// constructor is private to enforce use of factory method
private ConstructorScope(Constructor c){
private ConstructorScope(Constructor<?> c){
super(c);
}
......@@ -61,7 +61,7 @@ public class ConstructorScope extends AbstractScope<Constructor> {
* @param m - A Constructor whose scope we want to obtain
* @return The type-variable scope for the constructor m
*/
public static ConstructorScope make(Constructor c) {
public static ConstructorScope make(Constructor<?> c) {
return new ConstructorScope(c);
}
}
......@@ -52,5 +52,5 @@ public class ClassSignature implements Signature {
public ClassTypeSignature getSuperclass(){return superclass;}
public ClassTypeSignature[] getSuperInterfaces(){return superInterfaces;}
public void accept(Visitor v){v.visitClassSignature(this);}
public void accept(Visitor<?> v){v.visitClassSignature(this);}
}
......@@ -57,5 +57,5 @@ public class MethodTypeSignature implements Signature {
public ReturnType getReturnType(){return returnType;}
public FieldTypeSignature[] getExceptionTypes(){return exceptionTypes;}
public void accept(Visitor v){v.visitMethodTypeSignature(this);}
public void accept(Visitor<?> v){v.visitMethodTypeSignature(this);}
}
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册