Mercurial > hg > release > icedtea7-forest-2.3 > jdk
changeset 6309:a1ec65ac926d
8021946: Disabling sun.reflect.Reflection.getCallerCaller(int) by default breaks several frameworks and libraries
Reviewed-by: chegar, dholmes, dfuchs
author | alanb |
---|---|
date | Thu, 01 Aug 2013 17:25:29 +0100 |
parents | 6f1a1e26f521 |
children | 1dad45fa401d |
files | src/share/classes/sun/misc/VM.java src/share/classes/sun/reflect/Reflection.java test/java/util/logging/bundlesearch/ResourceBundleSearchTest.java test/sun/reflect/GetCallerClass.java |
diffstat | 4 files changed, 19 insertions(+), 22 deletions(-) [+] |
line wrap: on
line diff
--- a/src/share/classes/sun/misc/VM.java Thu Aug 08 01:48:56 2013 +0100 +++ b/src/share/classes/sun/misc/VM.java Thu Aug 01 17:25:29 2013 +0100 @@ -216,12 +216,13 @@ return allowArraySyntax; } - private static boolean allowGetCallerClass = false; + private static boolean allowGetCallerClass = true; - // Reflection.getCallerClass(int) is disabled by default. - // It can be enabled by setting the system property - // "jdk.reflect.allowGetCallerClass" and also used by - // logging stack walk of a resource bundle if it is turned on. + // Reflection.getCallerClass(int) is enabled by default. + // It can be disabled by setting the system property + // "jdk.reflect.allowGetCallerClass" to "false". It cannot be + // disabled if the logging stack walk (to find resource bundles) + // is enabled. public static boolean allowGetCallerClass() { return allowGetCallerClass; } @@ -290,14 +291,13 @@ ? defaultAllowArraySyntax : Boolean.parseBoolean(s)); - // Reflection.getCallerClass(int) is disabled by default. - // It can be enabled by setting the system property - // "jdk.reflect.allowGetCallerClass" and also used by - // logging stack walk of a resource bundle if it is turned on. + // Reflection.getCallerClass(int) is enabled by default. + // It can be disabled by setting a system property (but only if + // the logging stack walk is not enabled) s = props.getProperty("jdk.reflect.allowGetCallerClass"); allowGetCallerClass = (s != null ? (s.isEmpty() || Boolean.parseBoolean(s)) - : false) || + : true) || Boolean.valueOf(props.getProperty("jdk.logging.allowStackWalkSearch")); // Remove other private system properties
--- a/src/share/classes/sun/reflect/Reflection.java Thu Aug 08 01:48:56 2013 +0100 +++ b/src/share/classes/sun/reflect/Reflection.java Thu Aug 01 17:25:29 2013 +0100 @@ -59,8 +59,8 @@ public static native Class getCallerClass(); /** - * @deprecated No replacement. This method will be removed in the next - * JDK 7 update release. + * @deprecated No replacement. This method will be removed in a future + * release. */ @Deprecated @CallerSensitive @@ -68,12 +68,8 @@ if (sun.misc.VM.allowGetCallerClass()) { return getCallerClass0(depth+1); } - throw new UnsupportedOperationException("This method is in the sun.* " + - "namespace so it is not a supported, public interface. " + - "The 7u40 release notes describe a temporary mechanism " + - "to reenable the historical functionality of this method. " + - "Update code to function properly and this method will be " + - "removed without further warning in a subsequent 7 update release."); + throw new UnsupportedOperationException("This method has been disabled by a " + + "system property"); } // If the VM enforces getting caller class with @CallerSensitive,
--- a/test/java/util/logging/bundlesearch/ResourceBundleSearchTest.java Thu Aug 08 01:48:56 2013 +0100 +++ b/test/java/util/logging/bundlesearch/ResourceBundleSearchTest.java Thu Aug 01 17:25:29 2013 +0100 @@ -29,6 +29,7 @@ * @build ResourceBundleSearchTest IndirectlyLoadABundle LoadItUp1 LoadItUp2 TwiceIndirectlyLoadABundle LoadItUp2Invoker * @run main/othervm ResourceBundleSearchTest * @run main/othervm -Djdk.logging.allowStackWalkSearch=true ResourceBundleSearchTest + * @run main/othervm -Djdk.reflect.allowGetCallerClass=false -Djdk.logging.allowStackWalkSearch=true ResourceBundleSearchTest */ import java.net.URL; import java.net.URLClassLoader;
--- a/test/sun/reflect/GetCallerClass.java Thu Aug 08 01:48:56 2013 +0100 +++ b/test/sun/reflect/GetCallerClass.java Thu Aug 01 17:25:29 2013 +0100 @@ -23,7 +23,7 @@ /* * @test - * @bug 8016814 8014925 + * @bug 8016814 8014925 8021946 * @summary Test sun.reflect.Reflection.getCallerClass(int) disabled by default * @compile -XDignore.symbol.file GetCallerClass.java * @run main/othervm GetCallerClass @@ -36,10 +36,10 @@ public static void main(String[] args) throws Exception { String s = System.getProperty("jdk.reflect.allowGetCallerClass"); boolean allowed; - if (s == null || s.equals("false")) { + if (s == null || s.equals("") || s.equals("true")) { + allowed = true; + } else if (s.equals("false")) { allowed = false; - } else if (s.equals("") || s.equals("true")) { - allowed = true; } else { throw new RuntimeException("Unsupported test setting"); }