Blob Blame History Raw

# HG changeset patch
# User alanb
# Date 1375374329 -3600
# Node ID a1ec65ac926d41ccca2545dbc3b62bb7c12282af
# Parent  6f1a1e26f52119ee7b8ce91bf425a726935e02c3
8021946: Disabling sun.reflect.Reflection.getCallerCaller(int) by default breaks several frameworks and libraries
Reviewed-by: chegar, dholmes, dfuchs

diff -r 6f1a1e26f521 -r a1ec65ac926d src/share/classes/sun/misc/VM.java
--- openjdk/jdk/src/share/classes/sun/misc/VM.java	Thu Aug 08 01:48:56 2013 +0100
+++ openjdk/jdk/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
diff -r 6f1a1e26f521 -r a1ec65ac926d src/share/classes/sun/reflect/Reflection.java
--- openjdk/jdk/src/share/classes/sun/reflect/Reflection.java	Thu Aug 08 01:48:56 2013 +0100
+++ openjdk/jdk/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,
diff -r 6f1a1e26f521 -r a1ec65ac926d test/java/util/logging/bundlesearch/ResourceBundleSearchTest.java
--- openjdk/jdk/test/java/util/logging/bundlesearch/ResourceBundleSearchTest.java	Thu Aug 08 01:48:56 2013 +0100
+++ openjdk/jdk/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;
diff -r 6f1a1e26f521 -r a1ec65ac926d test/sun/reflect/GetCallerClass.java
--- openjdk/jdk/test/sun/reflect/GetCallerClass.java	Thu Aug 08 01:48:56 2013 +0100
+++ openjdk/jdk/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");
         }