diff --git a/make/java/java/Makefile b/make/java/java/Makefile index a9c5d8373f18c5a0ee8833e7fde462497ff6daf1..632cd3960ce1e7f65666e9ecea3c8fbbd2fad420 100644 --- a/make/java/java/Makefile +++ b/make/java/java/Makefile @@ -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 diff --git a/src/share/classes/java/lang/reflect/Array.java b/src/share/classes/java/lang/reflect/Array.java index 186a428fa52ebcc449c40b7749fcbf4f03fcaf0d..07ec7f0fe62aa2348d7d5d1e787afdd060f7272a 100644 --- a/src/share/classes/java/lang/reflect/Array.java +++ b/src/share/classes/java/lang/reflect/Array.java @@ -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; diff --git a/src/share/classes/java/lang/reflect/Constructor.java b/src/share/classes/java/lang/reflect/Constructor.java index ba4231c046d88d8bbe057e478b6ae2f42b2d0506..fbf300b7fac34dfb57051cab3dc67d0c4adb3870 100644 --- a/src/share/classes/java/lang/reflect/Constructor.java +++ b/src/share/classes/java/lang/reflect/Constructor.java @@ -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 extends Executable { * @since 1.5 */ @Override + @SuppressWarnings({ "rawtypes", "unchecked" }) public TypeVariable>[] getTypeParameters() { if (getSignature() != null) { return (TypeVariable>[])getGenericInfo().getTypeParameters(); @@ -197,7 +196,7 @@ public final class Constructor extends Executable { */ @Override public Class[] getParameterTypes() { - return (Class[]) parameterTypes.clone(); + return parameterTypes.clone(); } /** @@ -217,7 +216,7 @@ public final class Constructor extends Executable { */ @Override public Class[] getExceptionTypes() { - return (Class[])exceptionTypes.clone(); + return exceptionTypes.clone(); } @@ -392,7 +391,9 @@ public final class Constructor extends Executable { if (ca == null) { ca = acquireConstructorAccessor(); } - return (T) ca.newInstance(initargs); + @SuppressWarnings("unchecked") + T inst = (T) ca.newInstance(initargs); + return inst; } /** diff --git a/src/share/classes/java/lang/reflect/Executable.java b/src/share/classes/java/lang/reflect/Executable.java index 21ce2d80651edd0380d39ee45fd759b9106447f9..915918b0c0cc75a68381b78407078030dd6ffea5 100644 --- a/src/share/classes/java/lang/reflect/Executable.java +++ b/src/share/classes/java/lang/reflect/Executable.java @@ -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 getAnnotation(Class annotationClass) { + @SuppressWarnings("unchecked") + public T getAnnotation(Class annotationClass) { if (annotationClass == null) throw new NullPointerException(); diff --git a/src/share/classes/java/lang/reflect/Field.java b/src/share/classes/java/lang/reflect/Field.java index 1e6441aa94e9e68185d8d0369e10a499f2d1fd8a..de5a4153192d373a2b9674fa34d94eaab1aac915 100644 --- a/src/share/classes/java/lang/reflect/Field.java +++ b/src/share/classes/java/lang/reflect/Field.java @@ -1012,6 +1012,7 @@ class Field extends AccessibleObject implements Member { * @throws NullPointerException {@inheritDoc} * @since 1.5 */ + @SuppressWarnings("unchecked") public T getAnnotation(Class annotationClass) { if (annotationClass == null) throw new NullPointerException(); diff --git a/src/share/classes/java/lang/reflect/Method.java b/src/share/classes/java/lang/reflect/Method.java index 2edd6c018d88adc106dd68d699c2e11db2e6bcba..b940e23de42bd2b7bd98c309a2c36f8c27b2e7b6 100644 --- a/src/share/classes/java/lang/reflect/Method.java +++ b/src/share/classes/java/lang/reflect/Method.java @@ -194,6 +194,7 @@ public final class Method extends Executable { * @since 1.5 */ @Override + @SuppressWarnings({ "rawtypes", "unchecked" }) public TypeVariable[] getTypeParameters() { if (getGenericSignature() != null) return (TypeVariable[])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(); } /** diff --git a/src/share/classes/java/lang/reflect/Proxy.java b/src/share/classes/java/lang/reflect/Proxy.java index d25b7c8af7c80ef5d2a48b67765abcb2e4fe3af4..e83ab4085e06f0da61d17fdab737fac948420ddc 100644 --- a/src/share/classes/java/lang/reflect/Proxy.java +++ b/src/share/classes/java/lang/reflect/Proxy.java @@ -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); } diff --git a/src/share/classes/sun/reflect/AccessorGenerator.java b/src/share/classes/sun/reflect/AccessorGenerator.java index c4c33378c16769df0509b087e41d1b8610f4a594..e4bb2919571710a97abfa2714fb1988d39c18165 100644 --- a/src/share/classes/sun/reflect/AccessorGenerator.java +++ b/src/share/classes/sun/reflect/AccessorGenerator.java @@ -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; } diff --git a/src/share/classes/sun/reflect/BootstrapConstructorAccessorImpl.java b/src/share/classes/sun/reflect/BootstrapConstructorAccessorImpl.java index 62bf88602d4804aba723721a7e6fea1bf65ca4b2..a889f03a3ca2404ec8d4e672d8b339a0f213564c 100644 --- a/src/share/classes/sun/reflect/BootstrapConstructorAccessorImpl.java +++ b/src/share/classes/sun/reflect/BootstrapConstructorAccessorImpl.java @@ -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; } diff --git a/src/share/classes/sun/reflect/ClassDefiner.java b/src/share/classes/sun/reflect/ClassDefiner.java index 9ec40152509649fb3490077b4fa024bcc1e922f7..3d182b893ada23d6a5228727c7974dfc9a29bb00 100644 --- a/src/share/classes/sun/reflect/ClassDefiner.java +++ b/src/share/classes/sun/reflect/ClassDefiner.java @@ -51,8 +51,8 @@ class ClassDefiner { than would otherwise be possible, decreasing run-time footprint.

*/ - 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() { diff --git a/src/share/classes/sun/reflect/ConstantPool.java b/src/share/classes/sun/reflect/ConstantPool.java index 5df2344af9795d04334314beb2c39c6ca5279e59..1374bf29004437c156addb0ff2ae97c244ee114d 100644 --- a/src/share/classes/sun/reflect/ConstantPool.java +++ b/src/share/classes/sun/reflect/ConstantPool.java @@ -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); diff --git a/src/share/classes/sun/reflect/Label.java b/src/share/classes/sun/reflect/Label.java index e4092d8ccd46d300ffbf22e8a762d8a201fce36d..785172de4aba77d056f3cb994452d518b796a2e8 100644 --- a/src/share/classes/sun/reflect/Label.java +++ b/src/share/classes/sun/reflect/Label.java @@ -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/**/ patches = new ArrayList(); + private List 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); diff --git a/src/share/classes/sun/reflect/MethodAccessorGenerator.java b/src/share/classes/sun/reflect/MethodAccessorGenerator.java index f312f3eaad13eebf843b9104b219eece77753e2e..551beb027161011e592d2167fb366c99e3bca0cb 100644 --- a/src/share/classes/sun/reflect/MethodAccessorGenerator.java +++ b/src/share/classes/sun/reflect/MethodAccessorGenerator.java @@ -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(); diff --git a/src/share/classes/sun/reflect/NativeConstructorAccessorImpl.java b/src/share/classes/sun/reflect/NativeConstructorAccessorImpl.java index 91d3d6db6f96a04928b6d7fd1ced02b72fa3f07b..85d3a039d19b71fb33fbc72b0f497f74fb28706b 100644 --- a/src/share/classes/sun/reflect/NativeConstructorAccessorImpl.java +++ b/src/share/classes/sun/reflect/NativeConstructorAccessorImpl.java @@ -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; diff --git a/src/share/classes/sun/reflect/Reflection.java b/src/share/classes/sun/reflect/Reflection.java index 64953cae423451fc22ad1b76fa43e2fad508c713..12bdd6a4fb5e9d2a5272b4b87ed63f8f7a7032b4 100644 --- a/src/share/classes/sun/reflect/Reflection.java +++ b/src/share/classes/sun/reflect/Reflection.java @@ -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 fieldFilterMap; - private static volatile Map methodFilterMap; + private static volatile Map,String[]> fieldFilterMap; + private static volatile Map,String[]> methodFilterMap; static { - Map map = new HashMap(); + Map,String[]> map = new HashMap,String[]>(); map.put(Reflection.class, new String[] {"fieldFilterMap", "methodFilterMap"}); map.put(System.class, new String[] {"security"}); fieldFilterMap = map; - methodFilterMap = new HashMap(); + methodFilterMap = new HashMap<>(); } /** Returns the class of the method realFramesToSkip @@ -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 registerFilter(Map map, - Class containingClass, String ... names) { + private static Map,String[]> registerFilter(Map,String[]> map, + Class containingClass, String ... names) { if (map.get(containingClass) != null) { throw new IllegalArgumentException ("Filter already registered: " + containingClass); } - map = new HashMap(map); + map = new HashMap,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; diff --git a/src/share/classes/sun/reflect/ReflectionFactory.java b/src/share/classes/sun/reflect/ReflectionFactory.java index 8f952eb0e9038ff84ab53e7ba2cc21774e776c58..0422f6c1af98aa63a38ef62637dfe38716ab5aff 100644 --- a/src/share/classes/sun/reflect/ReflectionFactory.java +++ b/src/share/classes/sun/reflect/ReflectionFactory.java @@ -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); } } diff --git a/src/share/classes/sun/reflect/UnsafeFieldAccessorFactory.java b/src/share/classes/sun/reflect/UnsafeFieldAccessorFactory.java index 0da248051b38c3bb628da6a9fd9b0efef8ad45b2..b40dc081281a7e37fcee15a7515b66c3e6051b45 100644 --- a/src/share/classes/sun/reflect/UnsafeFieldAccessorFactory.java +++ b/src/share/classes/sun/reflect/UnsafeFieldAccessorFactory.java @@ -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()); diff --git a/src/share/classes/sun/reflect/UnsafeFieldAccessorImpl.java b/src/share/classes/sun/reflect/UnsafeFieldAccessorImpl.java index f8d474c2408487fb70c7f3affef9a88f2019e481..54c0d6d5c95a770ddb7e758f652af33b61e2bf8e 100644 --- a/src/share/classes/sun/reflect/UnsafeFieldAccessorImpl.java +++ b/src/share/classes/sun/reflect/UnsafeFieldAccessorImpl.java @@ -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()); } diff --git a/src/share/classes/sun/reflect/annotation/AnnotationParser.java b/src/share/classes/sun/reflect/annotation/AnnotationParser.java index d42bb9054a6ad8e281c50d06f4bf50fae33abfe2..f8a36dec1a2d7c1419fcb6d61ed78bc747836f8a 100644 --- a/src/share/classes/sun/reflect/annotation/AnnotationParser.java +++ b/src/share/classes/sun/reflect/annotation/AnnotationParser.java @@ -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)parseSig(sig, container); } catch (IllegalArgumentException ex) { // support obsolete early jsr175 format class files - annotationClass = constPool.getClassAt(typeIndex); + annotationClass = (Class)constPool.getClassAt(typeIndex); } } catch (NoClassDefFoundError e) { if (exceptionOnMissingAnnotationClass) @@ -256,7 +257,7 @@ public class AnnotationParser { Class type, Map 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 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)enumType, constName); + (Class>)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)componentType, buf, + return parseEnumArray(length, (Class>)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 enumType, + private static Object parseEnumArray(int length, Class> enumType, ByteBuffer buf, ConstantPool constPool, Class container) { diff --git a/src/share/classes/sun/reflect/annotation/EnumConstantNotPresentExceptionProxy.java b/src/share/classes/sun/reflect/annotation/EnumConstantNotPresentExceptionProxy.java index 34666e13d86013aa6b6ac6ed0ea72abfc0cf330d..67e9645867b30ff00cd325dafb5031f00f1bc70c 100644 --- a/src/share/classes/sun/reflect/annotation/EnumConstantNotPresentExceptionProxy.java +++ b/src/share/classes/sun/reflect/annotation/EnumConstantNotPresentExceptionProxy.java @@ -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 enumType; + Class> enumType; String constName; - public EnumConstantNotPresentExceptionProxy(Class enumType, + public EnumConstantNotPresentExceptionProxy(Class> enumType, String constName) { this.enumType = enumType; this.constName = constName; diff --git a/src/share/classes/sun/reflect/generics/reflectiveObjects/TypeVariableImpl.java b/src/share/classes/sun/reflect/generics/reflectiveObjects/TypeVariableImpl.java index 6f0dc6d96e036c539195ea36b0975f5514dce9be..20f94755b0f17626eae28039becd4d6772923032 100644 --- a/src/share/classes/sun/reflect/generics/reflectiveObjects/TypeVariableImpl.java +++ b/src/share/classes/sun/reflect/generics/reflectiveObjects/TypeVariableImpl.java @@ -157,7 +157,7 @@ public class TypeVariableImpl @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(); diff --git a/src/share/classes/sun/reflect/generics/repository/GenericDeclRepository.java b/src/share/classes/sun/reflect/generics/repository/GenericDeclRepository.java index 2a22803b5cb1d10035326e3015cdf79fd4c735f2..2178a3c289efcb7f554f7d586bc838ccbd59015e 100644 --- a/src/share/classes/sun/reflect/generics/repository/GenericDeclRepository.java +++ b/src/share/classes/sun/reflect/generics/repository/GenericDeclRepository.java @@ -69,7 +69,7 @@ public abstract class GenericDeclRepository // 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 diff --git a/src/share/classes/sun/reflect/generics/scope/AbstractScope.java b/src/share/classes/sun/reflect/generics/scope/AbstractScope.java index 3eee4bd7ad013d12c4cf078e67beb5a8fc970c68..e040eb2c1abfb793b383ae51f7c181275a6820da 100644 --- a/src/share/classes/sun/reflect/generics/scope/AbstractScope.java +++ b/src/share/classes/sun/reflect/generics/scope/AbstractScope.java @@ -83,8 +83,8 @@ public abstract class AbstractScope * @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); diff --git a/src/share/classes/sun/reflect/generics/scope/ConstructorScope.java b/src/share/classes/sun/reflect/generics/scope/ConstructorScope.java index 29530377b7a84b0b20c5fc81e958046c79874d59..0b0c8b16618a30b9c34295ba67a100f7607f5872 100644 --- a/src/share/classes/sun/reflect/generics/scope/ConstructorScope.java +++ b/src/share/classes/sun/reflect/generics/scope/ConstructorScope.java @@ -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 { +public class ConstructorScope extends AbstractScope> { // 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 { * @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); } } diff --git a/src/share/classes/sun/reflect/generics/tree/ClassSignature.java b/src/share/classes/sun/reflect/generics/tree/ClassSignature.java index 7856dd2c759cb183beb5c61b5bc78774e7866d08..dde4f6150decb61f88270102fd949f7bb1c2e3d1 100644 --- a/src/share/classes/sun/reflect/generics/tree/ClassSignature.java +++ b/src/share/classes/sun/reflect/generics/tree/ClassSignature.java @@ -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);} } diff --git a/src/share/classes/sun/reflect/generics/tree/MethodTypeSignature.java b/src/share/classes/sun/reflect/generics/tree/MethodTypeSignature.java index e741905f6cefa9a26a63fb4c4cec9f42c6c1824b..7d65d6edbf93031ebc7cab6f351433c327cfd2d2 100644 --- a/src/share/classes/sun/reflect/generics/tree/MethodTypeSignature.java +++ b/src/share/classes/sun/reflect/generics/tree/MethodTypeSignature.java @@ -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);} }