# HG changeset patch # User chegar # Date 1366625307 -3600 # Node ID d1ed51b53296ccdc285a3bb0da5f408a5f346450 # Parent 54af2a0e06da36b58f2bf50acd4b59b4e9fe5904 8012917: ObjectStreamClass and ObjectStreamField should be CallerSensitive aware Reviewed-by: mchung diff -r 54af2a0e06da -r d1ed51b53296 jdk/src/share/classes/java/io/ObjectStreamClass.java --- a/jdk/src/share/classes/java/io/ObjectStreamClass.java Mon Apr 22 10:55:14 2013 +0100 +++ b/jdk/src/share/classes/java/io/ObjectStreamClass.java Mon Apr 22 11:08:27 2013 +0100 @@ -49,6 +49,8 @@ import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.ConcurrentMap; import sun.misc.Unsafe; +import sun.reflect.CallerSensitive; +import sun.reflect.Reflection; import sun.reflect.ReflectionFactory; import sun.reflect.misc.ReflectUtil; @@ -259,12 +261,13 @@ * * @return the Class instance that this descriptor represents */ + @CallerSensitive public Class forClass() { if (cl == null) { return null; } - ClassLoader ccl = ObjectStreamField.getCallerClassLoader(); - if (ReflectUtil.needsPackageAccessCheck(ccl, cl.getClassLoader())) { + Class caller = Reflection.getCallerClass(); + if (ReflectUtil.needsPackageAccessCheck(caller.getClassLoader(), cl.getClassLoader())) { ReflectUtil.checkPackageAccess(cl); } return cl; diff -r 54af2a0e06da -r d1ed51b53296 jdk/src/share/classes/java/io/ObjectStreamField.java --- a/jdk/src/share/classes/java/io/ObjectStreamField.java Mon Apr 22 10:55:14 2013 +0100 +++ b/jdk/src/share/classes/java/io/ObjectStreamField.java Mon Apr 22 11:08:27 2013 +0100 @@ -26,6 +26,7 @@ package java.io; import java.lang.reflect.Field; +import sun.reflect.CallerSensitive; import sun.reflect.Reflection; import sun.reflect.misc.ReflectUtil; @@ -159,32 +160,15 @@ * @return a Class object representing the type of the * serializable field */ + @CallerSensitive public Class getType() { - ClassLoader ccl = getCallerClassLoader(); - if (ReflectUtil.needsPackageAccessCheck(ccl, type.getClassLoader())) { + Class caller = Reflection.getCallerClass(); + if (ReflectUtil.needsPackageAccessCheck(caller.getClassLoader(), type.getClassLoader())) { ReflectUtil.checkPackageAccess(type); } return type; } - // Returns the invoker's class loader. - // This is package private because it is accessed from ObjectStreamClass. - // NOTE: This must always be invoked when there is exactly one intervening - // frame from the core libraries on the stack between this method's - // invocation and the desired invoker. The frame count of 3 is determined - // as follows: - // - // 0: Reflection.getCallerClass - // 1: getCallerClassLoader() - // 2: ObjectStreamField.getType() or ObjectStreamClass.forClass() - // 3: the caller we want to check - // - // NOTE: copied from java.lang.ClassLoader and modified. - static ClassLoader getCallerClassLoader() { - Class caller = Reflection.getCallerClass(3); - return caller.getClassLoader(); - } - /** * Returns character encoding of field type. The encoding is as follows: *