8179424: Remove terminally deprecated sun.reflect.Reflection.getCallerClass

Reviewed-by: alanb, dfuchs, dholmes, lancea, mchung, rriggs
This commit is contained in:
Chris Hegarty 2017-12-22 15:55:29 +00:00
parent df559fe00e
commit a2000f8720
13 changed files with 22 additions and 247 deletions

View File

@ -257,7 +257,6 @@ SUNWprivate_1.1 {
Java_jdk_internal_reflect_NativeConstructorAccessorImpl_newInstance0;
Java_jdk_internal_reflect_NativeMethodAccessorImpl_invoke0;
Java_jdk_internal_reflect_Reflection_getCallerClass__;
Java_jdk_internal_reflect_Reflection_getCallerClass__I;
Java_jdk_internal_reflect_Reflection_getClassAccessFlags;
Java_jdk_internal_misc_VM_latestUserDefinedLoader0;
Java_jdk_internal_misc_VM_getuid;

View File

@ -27,7 +27,6 @@ text: .text%Java_java_io_FileDescriptor_initIDs;
text: .text%Java_java_io_FileOutputStream_initIDs;
text: .text%Java_java_lang_System_setIn0;
text: .text%Java_sun_reflect_Reflection_getCallerClass__;
text: .text%Java_sun_reflect_Reflection_getCallerClass__I;
text: .text%Java_java_lang_Class_forName0;
text: .text%Java_java_lang_Object_getClass;
text: .text%Java_sun_reflect_Reflection_getClassAccessFlags;

View File

@ -26,7 +26,6 @@ text: .text%Java_java_io_FileDescriptor_initIDs;
text: .text%Java_java_io_FileOutputStream_initIDs;
text: .text%Java_java_lang_System_setIn0;
text: .text%Java_sun_reflect_Reflection_getCallerClass__;
text: .text%Java_sun_reflect_Reflection_getCallerClass__I;
text: .text%Java_java_lang_Class_forName0;
text: .text%Java_java_lang_String_intern;
text: .text%Java_java_lang_StringUTF16_isBigEndian;

View File

@ -27,7 +27,6 @@ text: .text%Java_java_io_FileDescriptor_initIDs;
text: .text%Java_java_io_FileOutputStream_initIDs;
text: .text%Java_java_lang_System_setIn0;
text: .text%Java_sun_reflect_Reflection_getCallerClass__;
text: .text%Java_sun_reflect_Reflection_getCallerClass__I;
text: .text%Java_java_lang_Class_forName0;
text: .text%Java_java_lang_String_intern;
text: .text%Java_java_lang_StringUTF16_isBigEndian;

View File

@ -317,23 +317,18 @@ JVM_NewArray(JNIEnv *env, jclass eltClass, jint length);
JNIEXPORT jobject JNICALL
JVM_NewMultiArray(JNIEnv *env, jclass eltClass, jintArray dim);
/*
* java.lang.Class and java.lang.ClassLoader
*/
#define JVM_CALLER_DEPTH -1
/*
* Returns the immediate caller class of the native method invoking
* JVM_GetCallerClass. The Method.invoke and other frames due to
* reflection machinery are skipped.
*
* The depth parameter must be -1 (JVM_DEPTH). The caller is expected
* to be marked with sun.reflect.CallerSensitive. The JVM will throw
* an error if it is not marked propertly.
* The caller is expected to be marked with
* jdk.internal.reflect.CallerSensitive. The JVM will throw an
* error if it is not marked properly.
*/
JNIEXPORT jclass JNICALL
JVM_GetCallerClass(JNIEnv *env, int depth);
JVM_GetCallerClass(JNIEnv *env);
/*

View File

@ -678,17 +678,9 @@ JVM_END
// Misc. class handling ///////////////////////////////////////////////////////////
JVM_ENTRY(jclass, JVM_GetCallerClass(JNIEnv* env, int depth))
JVM_ENTRY(jclass, JVM_GetCallerClass(JNIEnv* env))
JVMWrapper("JVM_GetCallerClass");
// Pre-JDK 8 and early builds of JDK 8 don't have a CallerSensitive annotation; or
// sun.reflect.Reflection.getCallerClass with a depth parameter is provided
// temporarily for existing code to use until a replacement API is defined.
if (SystemDictionary::reflect_CallerSensitive_klass() == NULL || depth != JVM_CALLER_DEPTH) {
Klass* k = thread->security_get_caller_class(depth);
return (k == NULL) ? NULL : (jclass) JNIHandles::make_local(env, k->java_mirror());
}
// Getting the class of the caller frame.
//
// The call stack at this point looks something like this:

View File

@ -64,14 +64,6 @@ public class Reflection {
@HotSpotIntrinsicCandidate
public static native Class<?> getCallerClass();
/**
* @deprecated This method will be removed.
* This method is a private JDK API and retained temporarily to
* simplify the implementation of sun.misc.Reflection.getCallerClass.
*/
@Deprecated(forRemoval=true)
public static native Class<?> getCallerClass(int depth);
/** Retrieves the access flags written to the class file. For
inner classes these flags may differ from those returned by
Class.getModifiers(), which searches the InnerClasses

View File

@ -30,13 +30,7 @@
JNIEXPORT jclass JNICALL
Java_jdk_internal_reflect_Reflection_getCallerClass__(JNIEnv *env, jclass unused)
{
return JVM_GetCallerClass(env, JVM_CALLER_DEPTH);
}
JNIEXPORT jclass JNICALL
Java_jdk_internal_reflect_Reflection_getCallerClass__I(JNIEnv *env, jclass unused, jint depth)
{
return JVM_GetCallerClass(env, depth);
return JVM_GetCallerClass(env);
}
JNIEXPORT jint JNICALL

View File

@ -1,95 +0,0 @@
/*
* Copyright (c) 2013, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
/*
* @test
* @bug 8025799
* @summary Reflection.getCallerClass(int)
* @modules java.base/jdk.internal.reflect
* @run main GetCallerClassWithDepth
*/
import jdk.internal.reflect.Reflection;
public class GetCallerClassWithDepth {
public static void main(String[] args) throws Exception {
Class<?> c = Test.test();
assertEquals(c, GetCallerClassWithDepth.class);
Class<?> caller = Test.caller();
assertEquals(caller, GetCallerClassWithDepth.class);
Test.selfTest();
try {
Reflection.getCallerClass(-1);
throw new RuntimeException("getCallerClass(-1) should fail");
} catch (Error e) {
System.out.println("Expected: " + e.getMessage());
}
}
public Class<?> getCallerClass() {
// 0: Reflection 1: getCallerClass 2: Test.test 3: main
return Reflection.getCallerClass(3);
}
static void assertEquals(Class<?> c, Class<?> expected) {
if (c != expected) {
throw new RuntimeException("Incorrect caller: " + c);
}
}
static class Test {
// Returns the caller of this method
public static Class<?> test() {
return new GetCallerClassWithDepth().getCallerClass();
}
// Returns the caller of this method
public static Class<?> caller() {
// 0: Reflection 1: Test.caller 2: main
return Reflection.getCallerClass(2);
}
public static void selfTest() {
// 0: Reflection 1: Test.selfTest
Class<?> c = Reflection.getCallerClass(1);
assertEquals(c, Test.class);
Inner1.deep();
}
static class Inner1 {
static void deep() {
deeper();
}
static void deeper() {
Inner2.deepest();
}
static class Inner2 {
static void deepest() {
// 0: Reflection 1: deepest 2: deeper 3: deep 4: Test.selfTest
Class<?> c = Reflection.getCallerClass(4);
assertEquals(c, Test.class);
}
}
}
}
}

View File

@ -1,94 +0,0 @@
/*
* Copyright (c) 2013, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
/*
* @test
* @bug 8137058
* @summary Basic test for the unsupported Reflection.getCallerClass(int)
* @modules jdk.unsupported
*/
import sun.reflect.Reflection;
public class GetCallerClassWithDepth {
public static void main(String[] args) throws Exception {
Class<?> c = Test.test();
assertEquals(c, GetCallerClassWithDepth.class);
Class<?> caller = Test.caller();
assertEquals(caller, GetCallerClassWithDepth.class);
Test.selfTest();
try {
Reflection.getCallerClass(-1);
throw new RuntimeException("getCallerClass(-1) should fail");
} catch (Error e) {
System.out.println("Expected: " + e.getMessage());
}
}
public Class<?> getCallerClass() {
// 0: Reflection 1: getCallerClass 2: Test.test 3: main
return Reflection.getCallerClass(3);
}
static void assertEquals(Class<?> c, Class<?> expected) {
if (c != expected) {
throw new RuntimeException("Incorrect caller: " + c);
}
}
static class Test {
// Returns the caller of this method
public static Class<?> test() {
return new GetCallerClassWithDepth().getCallerClass();
}
// Returns the caller of this method
public static Class<?> caller() {
// 0: Reflection 1: Test.caller 2: main
return Reflection.getCallerClass(2);
}
public static void selfTest() {
// 0: Reflection 1: Test.selfTest
Class<?> c = Reflection.getCallerClass(1);
assertEquals(c, Test.class);
Inner1.deep();
}
static class Inner1 {
static void deep() {
deeper();
}
static void deeper() {
Inner2.deepest();
}
static class Inner2 {
static void deepest() {
// 0: Reflection 1: deepest 2: deeper 3: deep 4: Test.selfTest
Class<?> c = Reflection.getCallerClass(4);
assertEquals(c, Test.class);
}
}
}
}
}

View File

@ -85,7 +85,8 @@ public class RemovedJDKInternals {
.reference("p.Main", "java.lang.Object", "java.base")
.reference("p.Main", "java.util.Iterator", "java.base")
.reference("p.S", "java.lang.Object", "java.base")
.jdkInternal("p.Main", "sun.reflect.Reflection", "jdk.unsupported")
.jdkInternal("p.Main", "sun.reflect.ReflectionFactory", "jdk.unsupported")
.removedJdkInternal("p.Main", "sun.reflect.Reflection")
.removedJdkInternal("p.Main", "com.sun.image.codec.jpeg.JPEGCodec")
.removedJdkInternal("p.Main", "sun.misc.Service")
.removedJdkInternal("p.Main", "sun.misc.SoftCache")
@ -118,7 +119,8 @@ public class RemovedJDKInternals {
"com.sun.image.codec.jpeg.JPEGCodec", "Use javax.imageio @since 1.4",
"sun.misc.Service", "Use java.util.ServiceLoader @since 1.6",
"sun.misc.SoftCache", "Removed. See http://openjdk.java.net/jeps/260",
"sun.reflect.Reflection", "Use java.lang.StackWalker @since 9"
"sun.reflect.Reflection", "Use java.lang.StackWalker @since 9",
"sun.reflect.ReflectionFactory", "See http://openjdk.java.net/jeps/260"
);
@Test
@ -139,6 +141,8 @@ public class RemovedJDKInternals {
int pos = line.indexOf("Use ");
if (pos < 0)
pos = line.indexOf("Removed. ");
if (pos < 0)
pos = line.indexOf("See ");
assertTrue(pos > 0);
String name = line.substring(0, pos).trim();

View File

@ -1,12 +1,10 @@
/*
* Copyright (c) 2001, 2017, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2017, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
* published by the Free Software Foundation.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
@ -25,22 +23,11 @@
package sun.reflect;
/*
* JDK removed internal API
*/
public class Reflection {
private Reflection() { }
/**
* @deprecated This method is an internal API and will be removed.
* Use {@link StackWalker} to walk the stack and obtain the caller class
* with {@link StackWalker.StackFrame#getDeclaringClass} instead.
*/
@Deprecated(forRemoval=true)
@SuppressWarnings("removal") // Reflection.getCallerClass
public static Class<?> getCallerClass(int depth) {
if (depth < 0)
throw new InternalError("depth must be positive");
// increase depth to account for delegation to the internal impl
return jdk.internal.reflect.Reflection.getCallerClass(depth + 1);
return null;
}
}

View File

@ -27,10 +27,14 @@ import com.sun.image.codec.jpeg.JPEGCodec;
import sun.misc.Service;
import sun.misc.SoftCache;
import sun.reflect.Reflection;
import sun.reflect.ReflectionFactory;
public class Main {
public static void main() {
// in jdk.unsupported
ReflectionFactory factory = ReflectionFactory.getReflectionFactory();
// removed from jdk.unsupported in JDK 11
Class<?> caller = Reflection.getCallerClass(2);
// removed