8266459: Implement JEP 411: Deprecate the Security Manager for Removal

Co-authored-by: Sean Mullan <mullan@openjdk.org>
Co-authored-by: Lance Andersen <lancea@openjdk.org>
Co-authored-by: Weijun Wang <weijun@openjdk.org>
Reviewed-by: erikj, darcy, chegar, naoto, joehw, alanb, mchung, kcr, prr, lancea
This commit is contained in:
Weijun Wang 2021-06-02 11:57:31 +00:00
parent 19450b9951
commit 6765f90250
826 changed files with 2734 additions and 757 deletions

View file

@ -450,6 +450,7 @@ public final class Class<T> implements java.io.Serializable,
throws ClassNotFoundException
{
Class<?> caller = null;
@SuppressWarnings("removal")
SecurityManager sm = System.getSecurityManager();
if (sm != null) {
// Reflective call to get caller class is only needed if a security manager
@ -519,6 +520,7 @@ public final class Class<T> implements java.io.Serializable,
* @jls 12.3 Linking of Classes and Interfaces
* @since 9
*/
@SuppressWarnings("removal")
@CallerSensitive
public static Class<?> forName(Module module, String name) {
Objects.requireNonNull(module);
@ -599,6 +601,7 @@ public final class Class<T> implements java.io.Serializable,
* s.checkPackageAccess()} denies access to the package
* of this class.
*/
@SuppressWarnings("removal")
@CallerSensitive
@Deprecated(since="9")
public T newInstance()
@ -892,6 +895,7 @@ public final class Class<T> implements java.io.Serializable,
ClassLoader cl = getClassLoader0();
if (cl == null)
return null;
@SuppressWarnings("removal")
SecurityManager sm = System.getSecurityManager();
if (sm != null) {
ClassLoader.checkClassLoaderPermission(cl, Reflection.getCallerClass());
@ -1357,6 +1361,7 @@ public final class Class<T> implements java.io.Serializable,
// Perform access check
final Class<?> enclosingCandidate = enclosingInfo.getEnclosingClass();
@SuppressWarnings("removal")
SecurityManager sm = System.getSecurityManager();
if (sm != null) {
enclosingCandidate.checkMemberAccess(sm, Member.DECLARED,
@ -1513,6 +1518,7 @@ public final class Class<T> implements java.io.Serializable,
// Perform access check
final Class<?> enclosingCandidate = enclosingInfo.getEnclosingClass();
@SuppressWarnings("removal")
SecurityManager sm = System.getSecurityManager();
if (sm != null) {
enclosingCandidate.checkMemberAccess(sm, Member.DECLARED,
@ -1560,6 +1566,7 @@ public final class Class<T> implements java.io.Serializable,
final Class<?> candidate = getDeclaringClass0();
if (candidate != null) {
@SuppressWarnings("removal")
SecurityManager sm = System.getSecurityManager();
if (sm != null) {
candidate.checkPackageAccess(sm,
@ -1614,6 +1621,7 @@ public final class Class<T> implements java.io.Serializable,
}
if (enclosingCandidate != null) {
@SuppressWarnings("removal")
SecurityManager sm = System.getSecurityManager();
if (sm != null) {
enclosingCandidate.checkPackageAccess(sm,
@ -1840,6 +1848,7 @@ public final class Class<T> implements java.io.Serializable,
*
* @since 1.1
*/
@SuppressWarnings("removal")
@CallerSensitive
public Class<?>[] getClasses() {
SecurityManager sm = System.getSecurityManager();
@ -1911,6 +1920,7 @@ public final class Class<T> implements java.io.Serializable,
*/
@CallerSensitive
public Field[] getFields() throws SecurityException {
@SuppressWarnings("removal")
SecurityManager sm = System.getSecurityManager();
if (sm != null) {
checkMemberAccess(sm, Member.PUBLIC, Reflection.getCallerClass(), true);
@ -2001,6 +2011,7 @@ public final class Class<T> implements java.io.Serializable,
*/
@CallerSensitive
public Method[] getMethods() throws SecurityException {
@SuppressWarnings("removal")
SecurityManager sm = System.getSecurityManager();
if (sm != null) {
checkMemberAccess(sm, Member.PUBLIC, Reflection.getCallerClass(), true);
@ -2041,6 +2052,7 @@ public final class Class<T> implements java.io.Serializable,
*/
@CallerSensitive
public Constructor<?>[] getConstructors() throws SecurityException {
@SuppressWarnings("removal")
SecurityManager sm = System.getSecurityManager();
if (sm != null) {
checkMemberAccess(sm, Member.PUBLIC, Reflection.getCallerClass(), true);
@ -2095,6 +2107,7 @@ public final class Class<T> implements java.io.Serializable,
public Field getField(String name)
throws NoSuchFieldException, SecurityException {
Objects.requireNonNull(name);
@SuppressWarnings("removal")
SecurityManager sm = System.getSecurityManager();
if (sm != null) {
checkMemberAccess(sm, Member.PUBLIC, Reflection.getCallerClass(), true);
@ -2204,6 +2217,7 @@ public final class Class<T> implements java.io.Serializable,
public Method getMethod(String name, Class<?>... parameterTypes)
throws NoSuchMethodException, SecurityException {
Objects.requireNonNull(name);
@SuppressWarnings("removal")
SecurityManager sm = System.getSecurityManager();
if (sm != null) {
checkMemberAccess(sm, Member.PUBLIC, Reflection.getCallerClass(), true);
@ -2248,6 +2262,7 @@ public final class Class<T> implements java.io.Serializable,
public Constructor<T> getConstructor(Class<?>... parameterTypes)
throws NoSuchMethodException, SecurityException
{
@SuppressWarnings("removal")
SecurityManager sm = System.getSecurityManager();
if (sm != null) {
checkMemberAccess(sm, Member.PUBLIC, Reflection.getCallerClass(), true);
@ -2295,6 +2310,7 @@ public final class Class<T> implements java.io.Serializable,
*/
@CallerSensitive
public Class<?>[] getDeclaredClasses() throws SecurityException {
@SuppressWarnings("removal")
SecurityManager sm = System.getSecurityManager();
if (sm != null) {
checkMemberAccess(sm, Member.DECLARED, Reflection.getCallerClass(), false);
@ -2347,6 +2363,7 @@ public final class Class<T> implements java.io.Serializable,
*/
@CallerSensitive
public Field[] getDeclaredFields() throws SecurityException {
@SuppressWarnings("removal")
SecurityManager sm = System.getSecurityManager();
if (sm != null) {
checkMemberAccess(sm, Member.DECLARED, Reflection.getCallerClass(), true);
@ -2408,6 +2425,7 @@ public final class Class<T> implements java.io.Serializable,
*/
@CallerSensitive
public RecordComponent[] getRecordComponents() {
@SuppressWarnings("removal")
SecurityManager sm = System.getSecurityManager();
if (sm != null) {
checkMemberAccess(sm, Member.DECLARED, Reflection.getCallerClass(), true);
@ -2478,6 +2496,7 @@ public final class Class<T> implements java.io.Serializable,
*/
@CallerSensitive
public Method[] getDeclaredMethods() throws SecurityException {
@SuppressWarnings("removal")
SecurityManager sm = System.getSecurityManager();
if (sm != null) {
checkMemberAccess(sm, Member.DECLARED, Reflection.getCallerClass(), true);
@ -2528,6 +2547,7 @@ public final class Class<T> implements java.io.Serializable,
*/
@CallerSensitive
public Constructor<?>[] getDeclaredConstructors() throws SecurityException {
@SuppressWarnings("removal")
SecurityManager sm = System.getSecurityManager();
if (sm != null) {
checkMemberAccess(sm, Member.DECLARED, Reflection.getCallerClass(), true);
@ -2580,6 +2600,7 @@ public final class Class<T> implements java.io.Serializable,
public Field getDeclaredField(String name)
throws NoSuchFieldException, SecurityException {
Objects.requireNonNull(name);
@SuppressWarnings("removal")
SecurityManager sm = System.getSecurityManager();
if (sm != null) {
checkMemberAccess(sm, Member.DECLARED, Reflection.getCallerClass(), true);
@ -2644,6 +2665,7 @@ public final class Class<T> implements java.io.Serializable,
public Method getDeclaredMethod(String name, Class<?>... parameterTypes)
throws NoSuchMethodException, SecurityException {
Objects.requireNonNull(name);
@SuppressWarnings("removal")
SecurityManager sm = System.getSecurityManager();
if (sm != null) {
checkMemberAccess(sm, Member.DECLARED, Reflection.getCallerClass(), true);
@ -2722,6 +2744,7 @@ public final class Class<T> implements java.io.Serializable,
public Constructor<T> getDeclaredConstructor(Class<?>... parameterTypes)
throws NoSuchMethodException, SecurityException
{
@SuppressWarnings("removal")
SecurityManager sm = System.getSecurityManager();
if (sm != null) {
checkMemberAccess(sm, Member.DECLARED, Reflection.getCallerClass(), true);
@ -2968,6 +2991,7 @@ public final class Class<T> implements java.io.Serializable,
* @since 1.2
*/
public java.security.ProtectionDomain getProtectionDomain() {
@SuppressWarnings("removal")
SecurityManager sm = System.getSecurityManager();
if (sm != null) {
sm.checkPermission(SecurityConstants.GET_PD_PERMISSION);
@ -3013,7 +3037,7 @@ public final class Class<T> implements java.io.Serializable,
*
* <p> NOTE: should only be called if a SecurityManager is installed
*/
private void checkMemberAccess(SecurityManager sm, int which,
private void checkMemberAccess(@SuppressWarnings("removal") SecurityManager sm, int which,
Class<?> caller, boolean checkProxyInterfaces) {
/* Default policy allows access to all {@link Member#PUBLIC} members,
* as well as access to classes that have the same class loader as the caller.
@ -3037,7 +3061,7 @@ public final class Class<T> implements java.io.Serializable,
*
* NOTE: this method should only be called if a SecurityManager is active
*/
private void checkPackageAccess(SecurityManager sm, final ClassLoader ccl,
private void checkPackageAccess(@SuppressWarnings("removal") SecurityManager sm, final ClassLoader ccl,
boolean checkProxyInterfaces) {
final ClassLoader cl = getClassLoader0();
@ -3066,7 +3090,7 @@ public final class Class<T> implements java.io.Serializable,
* all classes provided must be loaded by the same ClassLoader
* NOTE: this method does not support Proxy classes
*/
private static void checkPackageAccessForPermittedSubclasses(SecurityManager sm,
private static void checkPackageAccessForPermittedSubclasses(@SuppressWarnings("removal") SecurityManager sm,
final ClassLoader ccl, Class<?>[] subClasses) {
final ClassLoader cl = subClasses[0].getClassLoader0();
@ -3762,6 +3786,7 @@ public final class Class<T> implements java.io.Serializable,
}
// Fetches the factory for reflective objects
@SuppressWarnings("removal")
private static ReflectionFactory getReflectionFactory() {
if (reflectionFactory == null) {
reflectionFactory =
@ -3794,6 +3819,7 @@ public final class Class<T> implements java.io.Serializable,
* identical to getEnumConstants except that the result is
* uncloned, cached, and shared by all callers.
*/
@SuppressWarnings("removal")
T[] getEnumConstantsShared() {
T[] constants = enumConstants;
if (constants == null) {
@ -4204,6 +4230,7 @@ public final class Class<T> implements java.io.Serializable,
return this;
}
// returning a different class requires a security check
@SuppressWarnings("removal")
SecurityManager sm = System.getSecurityManager();
if (sm != null) {
checkPackageAccess(sm,
@ -4296,6 +4323,7 @@ public final class Class<T> implements java.io.Serializable,
if (members.length > 1) {
// If we return anything other than the current class we need
// a security check
@SuppressWarnings("removal")
SecurityManager sm = System.getSecurityManager();
if (sm != null) {
checkPackageAccess(sm,
@ -4492,6 +4520,7 @@ public final class Class<T> implements java.io.Serializable,
}
if (subClasses.length > 0) {
// If we return some classes we need a security check:
@SuppressWarnings("removal")
SecurityManager sm = System.getSecurityManager();
if (sm != null) {
checkPackageAccessForPermittedSubclasses(sm,