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

@ -1,5 +1,5 @@
/*
* Copyright (c) 1997, 2020, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 1997, 2021, 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
@ -985,6 +985,7 @@ public class Arrays {
* circular dependencies. To be removed in a future release.
*/
static final class LegacyMergeSort {
@SuppressWarnings("removal")
private static final boolean userRequested =
java.security.AccessController.doPrivileged(
new sun.security.action.GetBooleanAction(

View file

@ -1,5 +1,5 @@
/*
* Copyright (c) 1996, 2020, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 1996, 2021, 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
@ -3547,6 +3547,7 @@ public abstract class Calendar implements Serializable, Cloneable, Comparable<Ca
}
}
@SuppressWarnings("removal")
private static class CalendarAccessControlContext {
private static final AccessControlContext INSTANCE;
static {
@ -3564,6 +3565,7 @@ public abstract class Calendar implements Serializable, Cloneable, Comparable<Ca
/**
* Reconstitutes this object from a stream (i.e., deserialize it).
*/
@SuppressWarnings("removal")
@java.io.Serial
private void readObject(ObjectInputStream stream)
throws IOException, ClassNotFoundException

View file

@ -1,5 +1,5 @@
/*
* Copyright (c) 2000, 2020, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2000, 2021, 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
@ -111,6 +111,7 @@ import sun.util.logging.PlatformLogger;
* @see java.math.BigDecimal
* @since 1.4
*/
@SuppressWarnings("removal")
public final class Currency implements Serializable {
@java.io.Serial

View file

@ -1103,6 +1103,7 @@ public final class Locale implements Cloneable, Serializable {
if (newLocale == null)
throw new NullPointerException("Can't set default locale to NULL");
@SuppressWarnings("removal")
SecurityManager sm = System.getSecurityManager();
if (sm != null) sm.checkPermission(new PropertyPermission
("user.language", "write"));

View file

@ -579,6 +579,7 @@ public abstract class ResourceBundle {
return locale;
}
@SuppressWarnings("removal")
private static ClassLoader getLoader(Module module) {
PrivilegedAction<ClassLoader> pa = module::getClassLoader;
return AccessController.doPrivileged(pa);
@ -1520,6 +1521,7 @@ public abstract class ResourceBundle {
.map(ServiceLoader.Provider::get)
.toList();
@SuppressWarnings("removal")
private static final List<ResourceBundleControlProvider> CONTROL_PROVIDERS =
AccessController.doPrivileged(pa);
@ -1592,6 +1594,7 @@ public abstract class ResourceBundle {
Objects.requireNonNull(module);
Module callerModule = caller.getModule();
if (callerModule != module) {
@SuppressWarnings("removal")
SecurityManager sm = System.getSecurityManager();
if (sm != null) {
sm.checkPermission(GET_CLASSLOADER_PERMISSION);
@ -1881,6 +1884,7 @@ public abstract class ResourceBundle {
* Returns the service type of the given baseName that is visible
* to the given class loader
*/
@SuppressWarnings("removal")
private static Class<ResourceBundleProvider>
getResourceBundleProviderType(String baseName, ClassLoader loader)
{
@ -1915,6 +1919,7 @@ public abstract class ResourceBundle {
/**
* Loads ResourceBundle from service providers.
*/
@SuppressWarnings("removal")
private static ResourceBundle loadBundleFromProviders(String baseName,
Locale locale,
ServiceLoader<ResourceBundleProvider> providers,
@ -3155,6 +3160,7 @@ public abstract class ResourceBundle {
return bundle;
}
@SuppressWarnings("removal")
private ResourceBundle newBundle0(String bundleName, String format,
ClassLoader loader, boolean reload)
throws IllegalAccessException, InstantiationException, IOException {
@ -3564,6 +3570,7 @@ public abstract class ResourceBundle {
/**
* Returns a new ResourceBundle instance of the given bundleClass
*/
@SuppressWarnings("removal")
static ResourceBundle newResourceBundle(Class<? extends ResourceBundle> bundleClass) {
try {
@SuppressWarnings("unchecked")
@ -3603,6 +3610,7 @@ public abstract class ResourceBundle {
String bundleName = Control.INSTANCE.toBundleName(baseName, locale);
try {
PrivilegedAction<Class<?>> pa = () -> Class.forName(module, bundleName);
@SuppressWarnings("removal")
Class<?> c = AccessController.doPrivileged(pa, null, GET_CLASSLOADER_PERMISSION);
trace("local in %s %s caller %s: %s%n", module, bundleName, callerModule, c);
@ -3703,7 +3711,7 @@ public abstract class ResourceBundle {
}
};
try (InputStream stream = AccessController.doPrivileged(pa)) {
try (@SuppressWarnings("removal") InputStream stream = AccessController.doPrivileged(pa)) {
if (stream != null) {
return new PropertyResourceBundle(stream);
} else {

View file

@ -407,6 +407,7 @@ public final class ServiceLoader<S>
private final ClassLoader loader;
// The access control context taken when the ServiceLoader is created
@SuppressWarnings("removal")
private final AccessControlContext acc;
// The lazy-lookup iterator for iterator operations
@ -474,6 +475,7 @@ public final class ServiceLoader<S>
* If {@code svc} is not accessible to {@code caller} or the caller
* module does not use the service type.
*/
@SuppressWarnings("removal")
private ServiceLoader(Class<?> caller, ModuleLayer layer, Class<S> svc) {
Objects.requireNonNull(caller);
Objects.requireNonNull(layer);
@ -497,6 +499,7 @@ public final class ServiceLoader<S>
* If {@code svc} is not accessible to {@code caller} or the caller
* module does not use the service type.
*/
@SuppressWarnings("removal")
private ServiceLoader(Class<?> caller, Class<S> svc, ClassLoader cl) {
Objects.requireNonNull(svc);
@ -539,6 +542,7 @@ public final class ServiceLoader<S>
* @throws ServiceConfigurationError
* If the caller module does not use the service type.
*/
@SuppressWarnings("removal")
private ServiceLoader(Module callerModule, Class<S> svc, ClassLoader cl) {
if (!callerModule.canUse(svc)) {
fail(svc, callerModule + " does not declare `uses`");
@ -610,6 +614,7 @@ public final class ServiceLoader<S>
* provider method or there is more than one public static
* provider method
*/
@SuppressWarnings("removal")
private Method findStaticProviderMethod(Class<?> clazz) {
List<Method> methods = null;
try {
@ -652,6 +657,7 @@ public final class ServiceLoader<S>
* @throws ServiceConfigurationError if the class does not have
* public no-arg constructor
*/
@SuppressWarnings("removal")
private Constructor<?> getConstructor(Class<?> clazz) {
PrivilegedExceptionAction<Constructor<?>> pa
= new PrivilegedExceptionAction<>() {
@ -685,12 +691,13 @@ public final class ServiceLoader<S>
final Class<? extends S> type;
final Method factoryMethod; // factory method or null
final Constructor<? extends S> ctor; // public no-args constructor or null
@SuppressWarnings("removal")
final AccessControlContext acc;
ProviderImpl(Class<S> service,
Class<? extends S> type,
Method factoryMethod,
AccessControlContext acc) {
@SuppressWarnings("removal") AccessControlContext acc) {
this.service = service;
this.type = type;
this.factoryMethod = factoryMethod;
@ -701,7 +708,7 @@ public final class ServiceLoader<S>
ProviderImpl(Class<S> service,
Class<? extends S> type,
Constructor<? extends S> ctor,
AccessControlContext acc) {
@SuppressWarnings("removal") AccessControlContext acc) {
this.service = service;
this.type = type;
this.factoryMethod = null;
@ -729,6 +736,7 @@ public final class ServiceLoader<S>
* permissions that are restricted by the security context of whatever
* created this loader.
*/
@SuppressWarnings("removal")
private S invokeFactoryMethod() {
Object result = null;
Throwable exc = null;
@ -772,6 +780,7 @@ public final class ServiceLoader<S>
* with a security manager then the constructor runs with permissions that
* are restricted by the security context of whatever created this loader.
*/
@SuppressWarnings("removal")
private S newInstance() {
S p = null;
Throwable exc = null;
@ -835,6 +844,7 @@ public final class ServiceLoader<S>
* isn't the expected sub-type (or doesn't define a provider
* factory method that returns the expected type)
*/
@SuppressWarnings("removal")
private Provider<S> loadProvider(ServiceProvider provider) {
Module module = provider.module();
if (!module.canRead(service.getModule())) {
@ -1003,6 +1013,7 @@ public final class ServiceLoader<S>
/**
* Returns the class loader that a module is defined to
*/
@SuppressWarnings("removal")
private ClassLoader loaderFor(Module module) {
SecurityManager sm = System.getSecurityManager();
if (sm == null) {
@ -1255,6 +1266,7 @@ public final class ServiceLoader<S>
}
}
@SuppressWarnings("removal")
@Override
public boolean hasNext() {
if (acc == null) {
@ -1267,6 +1279,7 @@ public final class ServiceLoader<S>
}
}
@SuppressWarnings("removal")
@Override
public Provider<T> next() {
if (acc == null) {

View file

@ -1,5 +1,5 @@
/*
* Copyright (c) 1996, 2019, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 1996, 2021, 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
@ -716,6 +716,7 @@ public abstract class TimeZone implements Serializable, Cloneable {
*/
public static void setDefault(TimeZone zone)
{
@SuppressWarnings("removal")
SecurityManager sm = System.getSecurityManager();
if (sm != null) {
sm.checkPermission(new PropertyPermission

View file

@ -1,5 +1,5 @@
/*
* Copyright (c) 2012, 2013, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2012, 2021, 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
@ -49,6 +49,7 @@ final class Tripwire {
private static final String TRIPWIRE_PROPERTY = "org.openjdk.java.util.stream.tripwire";
/** Should debugging checks be enabled? */
@SuppressWarnings("removal")
static final boolean ENABLED = AccessController.doPrivileged(
(PrivilegedAction<Boolean>) () -> Boolean.getBoolean(TRIPWIRE_PROPERTY));

View file

@ -506,6 +506,7 @@ public class ConcurrentSkipListSet<E>
/** Initializes map field; for use in clone. */
private void setMap(ConcurrentNavigableMap<E,Object> map) {
@SuppressWarnings("removal")
Field mapField = java.security.AccessController.doPrivileged(
(java.security.PrivilegedAction<Field>) () -> {
try {

View file

@ -1591,6 +1591,7 @@ public class CopyOnWriteArrayList<E>
/** Initializes the lock; for use when deserializing or cloning. */
private void resetLock() {
@SuppressWarnings("removal")
Field lockField = java.security.AccessController.doPrivileged(
(java.security.PrivilegedAction<Field>) () -> {
try {

View file

@ -389,7 +389,15 @@ public class Executors {
* @throws AccessControlException if the current access control
* context does not have permission to both get and set context
* class loader
*
* @deprecated This method is only useful in conjunction with
* {@linkplain SecurityManager the Security Manager}, which is
* deprecated and subject to removal in a future release.
* Consequently, this method is also deprecated and subject to
* removal. There is no replacement for the Security Manager or this
* method.
*/
@Deprecated(since="17", forRemoval=true)
public static ThreadFactory privilegedThreadFactory() {
return new PrivilegedThreadFactory();
}
@ -466,7 +474,15 @@ public class Executors {
* @param <T> the type of the callable's result
* @return a callable object
* @throws NullPointerException if callable null
*
* @deprecated This method is only useful in conjunction with
* {@linkplain SecurityManager the Security Manager}, which is
* deprecated and subject to removal in a future release.
* Consequently, this method is also deprecated and subject to
* removal. There is no replacement for the Security Manager or this
* method.
*/
@Deprecated(since="17", forRemoval=true)
public static <T> Callable<T> privilegedCallable(Callable<T> callable) {
if (callable == null)
throw new NullPointerException();
@ -492,7 +508,15 @@ public class Executors {
* @throws AccessControlException if the current access control
* context does not have permission to both set and get context
* class loader
*
* @deprecated This method is only useful in conjunction with
* {@linkplain SecurityManager the Security Manager}, which is
* deprecated and subject to removal in a future release.
* Consequently, this method is also deprecated and subject to
* removal. There is no replacement for the Security Manager or this
* method.
*/
@Deprecated(since="17", forRemoval=true)
public static <T> Callable<T> privilegedCallableUsingCurrentClassLoader(Callable<T> callable) {
if (callable == null)
throw new NullPointerException();
@ -525,13 +549,16 @@ public class Executors {
*/
private static final class PrivilegedCallable<T> implements Callable<T> {
final Callable<T> task;
@SuppressWarnings("removal")
final AccessControlContext acc;
@SuppressWarnings("removal")
PrivilegedCallable(Callable<T> task) {
this.task = task;
this.acc = AccessController.getContext();
}
@SuppressWarnings("removal")
public T call() throws Exception {
try {
return AccessController.doPrivileged(
@ -557,9 +584,11 @@ public class Executors {
private static final class PrivilegedCallableUsingCurrentClassLoader<T>
implements Callable<T> {
final Callable<T> task;
@SuppressWarnings("removal")
final AccessControlContext acc;
final ClassLoader ccl;
@SuppressWarnings("removal")
PrivilegedCallableUsingCurrentClassLoader(Callable<T> task) {
SecurityManager sm = System.getSecurityManager();
if (sm != null) {
@ -577,6 +606,7 @@ public class Executors {
this.ccl = Thread.currentThread().getContextClassLoader();
}
@SuppressWarnings("removal")
public T call() throws Exception {
try {
return AccessController.doPrivileged(
@ -616,6 +646,7 @@ public class Executors {
private final String namePrefix;
DefaultThreadFactory() {
@SuppressWarnings("removal")
SecurityManager s = System.getSecurityManager();
group = (s != null) ? s.getThreadGroup() :
Thread.currentThread().getThreadGroup();
@ -640,9 +671,11 @@ public class Executors {
* Thread factory capturing access control context and class loader.
*/
private static class PrivilegedThreadFactory extends DefaultThreadFactory {
@SuppressWarnings("removal")
final AccessControlContext acc;
final ClassLoader ccl;
@SuppressWarnings("removal")
PrivilegedThreadFactory() {
super();
SecurityManager sm = System.getSecurityManager();
@ -661,6 +694,7 @@ public class Executors {
public Thread newThread(final Runnable r) {
return super.newThread(new Runnable() {
@SuppressWarnings("removal")
public void run() {
AccessController.doPrivileged(new PrivilegedAction<>() {
public Void run() {

View file

@ -178,6 +178,7 @@ import java.util.concurrent.locks.Condition;
* @since 1.7
* @author Doug Lea
*/
@SuppressWarnings("removal")
public class ForkJoinPool extends AbstractExecutorService {
/*

View file

@ -186,6 +186,7 @@ public class ForkJoinWorkerThread extends Thread {
*/
static final class InnocuousForkJoinWorkerThread extends ForkJoinWorkerThread {
/** The ThreadGroup for all InnocuousForkJoinWorkerThreads */
@SuppressWarnings("removal")
private static final ThreadGroup innocuousThreadGroup =
AccessController.doPrivileged(new PrivilegedAction<>() {
public ThreadGroup run() {

View file

@ -303,7 +303,7 @@ public class ThreadLocalRandom extends Random {
}
static final void setInheritedAccessControlContext(Thread thread,
AccessControlContext acc) {
@SuppressWarnings("removal") AccessControlContext acc) {
U.putReferenceRelease(thread, INHERITEDACCESSCONTROLCONTEXT, acc);
}

View file

@ -750,6 +750,7 @@ public class ThreadPoolExecutor extends AbstractExecutorService {
*/
private void checkShutdownAccess() {
// assert mainLock.isHeldByCurrentThread();
@SuppressWarnings("removal")
SecurityManager security = System.getSecurityManager();
if (security != null) {
security.checkPermission(shutdownPerm);

View file

@ -385,6 +385,7 @@ public abstract class AtomicIntegerFieldUpdater<T> {
/** class holding the field */
private final Class<T> tclass;
@SuppressWarnings("removal")
AtomicIntegerFieldUpdaterImpl(final Class<T> tclass,
final String fieldName,
final Class<?> caller) {

View file

@ -384,6 +384,7 @@ public abstract class AtomicLongFieldUpdater<T> {
/** class holding the field */
private final Class<T> tclass;
@SuppressWarnings("removal")
CASUpdater(final Class<T> tclass, final String fieldName,
final Class<?> caller) {
final Field field;
@ -525,6 +526,7 @@ public abstract class AtomicLongFieldUpdater<T> {
/** class holding the field */
private final Class<T> tclass;
@SuppressWarnings("removal")
LockedUpdater(final Class<T> tclass, final String fieldName,
final Class<?> caller) {
final Field field;

View file

@ -330,6 +330,7 @@ public class AtomicReferenceArray<E> implements java.io.Serializable {
throw new java.io.InvalidObjectException("Not array type");
if (a.getClass() != Object[].class)
a = Arrays.copyOf((Object[])a, Array.getLength(a), Object[].class);
@SuppressWarnings("removal")
Field arrayField = java.security.AccessController.doPrivileged(
(java.security.PrivilegedAction<Field>) () -> {
try {

View file

@ -320,6 +320,7 @@ public abstract class AtomicReferenceFieldUpdater<T,V> {
* screenings fail.
*/
@SuppressWarnings("removal")
AtomicReferenceFieldUpdaterImpl(final Class<T> tclass,
final Class<V> vclass,
final String fieldName,

View file

@ -47,7 +47,7 @@ import java.util.function.LongBinaryOperator;
* for classes supporting dynamic striping on 64bit values. The class
* extends Number so that concrete subclasses must publicly do so.
*/
@SuppressWarnings("serial")
@SuppressWarnings({"removal","serial"})
abstract class Striped64 extends Number {
/*
* This class maintains a lazily-initialized table of atomically

View file

@ -284,6 +284,7 @@ public final class RandomGeneratorFactory<T extends RandomGenerator> {
if (ctor == null) {
PrivilegedExceptionAction<Constructor<?>[]> ctorAction = randomGeneratorClass::getConstructors;
try {
@SuppressWarnings("removal")
Constructor<?>[] ctors = AccessController.doPrivileged(ctorAction);
Constructor<T> tmpCtor = null;

View file

@ -225,6 +225,7 @@ public abstract class AbstractResourceBundleProvider implements ResourceBundlePr
private static ResourceBundle loadResourceBundle(Module module, String bundleName)
{
PrivilegedAction<Class<?>> pa = () -> Class.forName(module, bundleName);
@SuppressWarnings("removal")
Class<?> c = AccessController.doPrivileged(pa, null, GET_CLASSLOADER_PERMISSION);
if (c != null && ResourceBundle.class.isAssignableFrom(c)) {
@SuppressWarnings("unchecked")
@ -254,7 +255,7 @@ public abstract class AbstractResourceBundleProvider implements ResourceBundlePr
throw new UncheckedIOException(e);
}
};
try (InputStream stream = AccessController.doPrivileged(pa)) {
try (@SuppressWarnings("removal") InputStream stream = AccessController.doPrivileged(pa)) {
if (stream != null) {
return new PropertyResourceBundle(stream);
} else {

View file

@ -1,5 +1,5 @@
/*
* Copyright (c) 2005, 2019, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2005, 2021, 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
@ -152,6 +152,7 @@ import java.util.Locale;
public abstract class LocaleServiceProvider {
private static Void checkPermission() {
@SuppressWarnings("removal")
SecurityManager sm = System.getSecurityManager();
if (sm != null) {
sm.checkPermission(new RuntimePermission("localeServiceProvider"));

View file

@ -1,5 +1,5 @@
/*
* Copyright (c) 2016, 2019, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2016, 2021, 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
@ -154,6 +154,7 @@ public interface ToolProvider {
*
* @throws NullPointerException if {@code name} is {@code null}
*/
@SuppressWarnings("removal")
static Optional<ToolProvider> findFirst(String name) {
Objects.requireNonNull(name);
ClassLoader systemClassLoader = ClassLoader.getSystemClassLoader();

View file

@ -1,5 +1,5 @@
/*
* Copyright (c) 2012, 2013, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2012, 2021, 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
@ -49,6 +49,7 @@ final class Tripwire {
private static final String TRIPWIRE_PROPERTY = "org.openjdk.java.util.stream.tripwire";
/** Should debugging checks be enabled? */
@SuppressWarnings("removal")
static final boolean ENABLED = AccessController.doPrivileged(
(PrivilegedAction<Boolean>) () -> Boolean.getBoolean(TRIPWIRE_PROPERTY));

View file

@ -1,5 +1,5 @@
/*
* Copyright (c) 1995, 2020, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 1995, 2021, 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
@ -226,6 +226,7 @@ public class ZipFile implements ZipConstants, Closeable {
Integer.toHexString(mode));
}
String name = file.getPath();
@SuppressWarnings("removal")
SecurityManager sm = System.getSecurityManager();
if (sm != null) {
sm.checkRead(name);