mirror of
https://github.com/openjdk/jdk.git
synced 2025-08-26 14:24:46 +02:00
8345286: Remove use of SecurityManager API from misc areas
Reviewed-by: alanb, kevinw, sgehwolf
This commit is contained in:
parent
38927fc590
commit
3d49665b85
22 changed files with 43 additions and 261 deletions
|
@ -283,7 +283,6 @@ public final class FilePermission extends Permission implements Serializable {
|
|||
* @param mask the actions mask to use.
|
||||
*
|
||||
*/
|
||||
@SuppressWarnings("removal")
|
||||
private void init(int mask) {
|
||||
if ((mask & ALL) != mask)
|
||||
throw new IllegalArgumentException("invalid actions mask");
|
||||
|
|
|
@ -549,7 +549,6 @@ public final class String
|
|||
* Important: parameter order of this method is deliberately changed in order to
|
||||
* disambiguate it against other similar methods of this class.
|
||||
*/
|
||||
@SuppressWarnings("removal")
|
||||
private String(Charset charset, byte[] bytes, int offset, int length) {
|
||||
if (length == 0) {
|
||||
this.value = "".value;
|
||||
|
@ -787,7 +786,6 @@ public final class String
|
|||
}
|
||||
}
|
||||
|
||||
@SuppressWarnings("removal")
|
||||
private static String newStringNoRepl1(byte[] src, Charset cs) {
|
||||
int len = src.length;
|
||||
if (len == 0) {
|
||||
|
|
|
@ -1379,7 +1379,6 @@ public final class System {
|
|||
|
||||
|
||||
private static volatile LoggerFinder service;
|
||||
@SuppressWarnings("removal")
|
||||
static LoggerFinder accessProvider() {
|
||||
// We do not need to synchronize: LoggerFinderLoader will
|
||||
// always return the same instance, so if we don't have it,
|
||||
|
@ -1483,7 +1482,6 @@ public final class System {
|
|||
*
|
||||
* @since 9
|
||||
*/
|
||||
@SuppressWarnings("removal")
|
||||
@CallerSensitive
|
||||
public static Logger getLogger(String name, ResourceBundle bundle) {
|
||||
final ResourceBundle rb = Objects.requireNonNull(bundle);
|
||||
|
|
|
@ -578,7 +578,6 @@ abstract class ClassSpecializer<T,K,S extends ClassSpecializer<T,K,S>.SpeciesDat
|
|||
* @param speciesData what species we are generating
|
||||
* @return the generated concrete TopClass class
|
||||
*/
|
||||
@SuppressWarnings("removal")
|
||||
Class<? extends T> generateConcreteSpeciesCode(String className, ClassSpecializer<T,K,S>.SpeciesData speciesData) {
|
||||
byte[] classFile = generateConcreteSpeciesCodeFile(className, speciesData);
|
||||
var lookup = new MethodHandles.Lookup(topClass);
|
||||
|
|
|
@ -103,7 +103,6 @@ final class ProxyGenerator {
|
|||
/**
|
||||
* debugging flag for saving generated class files
|
||||
*/
|
||||
@SuppressWarnings("removal")
|
||||
private static final boolean SAVE_GENERATED_FILES =
|
||||
Boolean.getBoolean("jdk.proxy.ProxyGenerator.saveGeneratedFiles");
|
||||
|
||||
|
|
|
@ -1388,7 +1388,6 @@ public abstract class URLConnection {
|
|||
return UnknownContentHandler.INSTANCE;
|
||||
}
|
||||
|
||||
@SuppressWarnings("removal")
|
||||
private ContentHandler lookupContentHandlerViaProvider(String contentType) {
|
||||
|
||||
ClassLoader cl = ClassLoader.getSystemClassLoader();
|
||||
|
|
|
@ -290,7 +290,6 @@ final class JceSecurity {
|
|||
}
|
||||
}
|
||||
|
||||
// This is called from within an doPrivileged block.
|
||||
private static void setupJurisdictionPolicies() throws Exception {
|
||||
|
||||
// Sanity check the crypto.policy Security property. Single
|
||||
|
|
|
@ -30,8 +30,6 @@ import jdk.internal.util.StaticProperty;
|
|||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.security.AccessController;
|
||||
import java.security.PrivilegedAction;
|
||||
import java.util.ArrayDeque;
|
||||
import java.util.Deque;
|
||||
import java.util.function.BiFunction;
|
||||
|
@ -323,18 +321,13 @@ public final class NativeLibraries {
|
|||
return load(this, name, isBuiltin, throwExceptionIfFail());
|
||||
}
|
||||
|
||||
@SuppressWarnings("removal")
|
||||
private boolean throwExceptionIfFail() {
|
||||
if (loadLibraryOnlyIfPresent) return true;
|
||||
|
||||
// If the file exists but fails to load, UnsatisfiedLinkException thrown by the VM
|
||||
// will include the error message from dlopen to provide diagnostic information
|
||||
return AccessController.doPrivileged(new PrivilegedAction<>() {
|
||||
public Boolean run() {
|
||||
File file = new File(name);
|
||||
return file.exists();
|
||||
}
|
||||
});
|
||||
File file = new File(name);
|
||||
return file.exists();
|
||||
}
|
||||
|
||||
/*
|
||||
|
|
|
@ -342,8 +342,6 @@ public final class LazyLoggers {
|
|||
// no need to lock: it doesn't matter if we call
|
||||
// getLoggerFinder() twice - since LoggerFinder already caches
|
||||
// the result.
|
||||
// This is just an optimization to avoid the cost of calling
|
||||
// doPrivileged every time.
|
||||
prov = LoggerFinder.getLoggerFinder();
|
||||
if (prov instanceof TemporaryLoggerFinder) return prov;
|
||||
provider = prov;
|
||||
|
|
|
@ -28,10 +28,9 @@ package jdk.internal.misc;
|
|||
import java.util.concurrent.atomic.AtomicInteger;
|
||||
|
||||
/**
|
||||
* A thread that has no permissions, is not a member of any user-defined
|
||||
* A thread that is not a member of any user-defined
|
||||
* ThreadGroup and supports the ability to erase ThreadLocals.
|
||||
*/
|
||||
@SuppressWarnings("removal")
|
||||
public final class InnocuousThread extends Thread {
|
||||
private static final jdk.internal.misc.Unsafe UNSAFE;
|
||||
private static final long THREAD_LOCALS;
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright (c) 2002, 2022, Oracle and/or its affiliates. All rights reserved.
|
||||
* Copyright (c) 2002, 2024, 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
|
||||
|
@ -25,8 +25,6 @@
|
|||
package jdk.internal.perf;
|
||||
|
||||
import java.nio.ByteBuffer;
|
||||
import java.security.Permission;
|
||||
import java.security.PrivilegedAction;
|
||||
import java.io.IOException;
|
||||
|
||||
import sun.nio.cs.UTF_8;
|
||||
|
@ -49,7 +47,6 @@ import jdk.internal.ref.CleanerFactory;
|
|||
* @author Brian Doherty
|
||||
* @since 1.4.2
|
||||
* @see #getPerf
|
||||
* @see jdk.internal.perf.Perf.GetPerfAction
|
||||
* @see java.nio.ByteBuffer
|
||||
*/
|
||||
public final class Perf {
|
||||
|
@ -58,46 +55,6 @@ public final class Perf {
|
|||
|
||||
private Perf() { } // prevent instantiation
|
||||
|
||||
/**
|
||||
* The GetPerfAction class is a convenience class for acquiring access
|
||||
* to the singleton Perf instance using the
|
||||
* <code>AccessController.doPrivileged()</code> method.
|
||||
* <p>
|
||||
* An instance of this class can be used as the argument to
|
||||
* <code>AccessController.doPrivileged(PrivilegedAction)</code>.
|
||||
* <p> Here is a suggested idiom for use of this class:
|
||||
*
|
||||
* <blockquote><pre>{@code
|
||||
* class MyTrustedClass {
|
||||
* private static final Perf perf =
|
||||
* AccessController.doPrivileged(new Perf.GetPerfAction<Perf>());
|
||||
* ...
|
||||
* }
|
||||
* }</pre></blockquote>
|
||||
* <p>
|
||||
* In the presence of a security manager, the <code>MyTrustedClass</code>
|
||||
* class in the above example will need to be granted the
|
||||
* <em>"sun.misc.Perf.getPerf"</em> <code>RuntimePermission</code>
|
||||
* permission in order to successfully acquire the singleton Perf instance.
|
||||
* <p>
|
||||
* Please note that the <em>"sun.misc.Perf.getPerf"</em> permission
|
||||
* is not a JDK specified permission.
|
||||
*
|
||||
* @see java.security.AccessController#doPrivileged(PrivilegedAction)
|
||||
* @see java.lang.RuntimePermission
|
||||
*/
|
||||
public static class GetPerfAction implements PrivilegedAction<Perf>
|
||||
{
|
||||
/**
|
||||
* Run the <code>Perf.getPerf()</code> method in a privileged context.
|
||||
*
|
||||
* @see #getPerf
|
||||
*/
|
||||
public Perf run() {
|
||||
return getPerf();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Return a reference to the singleton Perf instance.
|
||||
* <p>
|
||||
|
@ -106,11 +63,6 @@ public final class Perf {
|
|||
* for accessing the instrumentation buffer for this or another local
|
||||
* Java virtual machine.
|
||||
* <p>
|
||||
* If a security manager is installed, its <code>checkPermission</code>
|
||||
* method is called with a <code>RuntimePermission</code> with a target
|
||||
* of <em>"sun.misc.Perf.getPerf"</em>. A security exception will result
|
||||
* if the caller has not been granted this permission.
|
||||
* <p>
|
||||
* Access to the returned <code>Perf</code> object should be protected
|
||||
* by its caller and not passed on to untrusted code. This object can
|
||||
* be used to attach to the instrumentation buffer provided by this Java
|
||||
|
@ -119,26 +71,12 @@ public final class Perf {
|
|||
* information. API's built on top of this interface may want to provide
|
||||
* finer grained access control to the contents of individual
|
||||
* instrumentation objects contained within the buffer.
|
||||
* <p>
|
||||
* Please note that the <em>"sun.misc.Perf.getPerf"</em> permission
|
||||
* is not a JDK specified permission.
|
||||
*
|
||||
* @return A reference to the singleton Perf instance.
|
||||
* @throws SecurityException if a security manager exists and its
|
||||
* <code>checkPermission</code> method doesn't allow access
|
||||
* to the <em>"jdk.internal.perf.Perf.getPerf""</em> target.
|
||||
* @see java.lang.RuntimePermission
|
||||
* @see #attach
|
||||
*/
|
||||
public static Perf getPerf()
|
||||
{
|
||||
@SuppressWarnings("removal")
|
||||
SecurityManager security = System.getSecurityManager();
|
||||
if (security != null) {
|
||||
Permission perm = new RuntimePermission("jdk.internal.perf.Perf.getPerf");
|
||||
security.checkPermission(perm);
|
||||
}
|
||||
|
||||
return instance;
|
||||
}
|
||||
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright (c) 2009, 2021, Oracle and/or its affiliates. All rights reserved.
|
||||
* Copyright (c) 2009, 2024, 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
|
||||
|
@ -28,7 +28,6 @@ package jdk.internal.perf;
|
|||
import java.nio.ByteBuffer;
|
||||
import java.nio.ByteOrder;
|
||||
import java.nio.LongBuffer;
|
||||
import java.security.AccessController;
|
||||
|
||||
/**
|
||||
* Performance counter support for internal JRE classes.
|
||||
|
@ -48,9 +47,7 @@ import java.security.AccessController;
|
|||
*
|
||||
*/
|
||||
public class PerfCounter {
|
||||
@SuppressWarnings("removal")
|
||||
private static final Perf perf =
|
||||
AccessController.doPrivileged(new Perf.GetPerfAction());
|
||||
private static final Perf perf = Perf.getPerf();
|
||||
|
||||
// Must match values defined in hotspot/src/share/vm/runtime/perfdata.hpp
|
||||
private static final int V_Constant = 1;
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright (c) 2003, 2021, Oracle and/or its affiliates. All rights reserved.
|
||||
* Copyright (c) 2003, 2024, 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
|
||||
|
@ -26,8 +26,6 @@
|
|||
package jdk.internal.ref;
|
||||
|
||||
import java.lang.ref.*;
|
||||
import java.security.AccessController;
|
||||
import java.security.PrivilegedAction;
|
||||
|
||||
|
||||
/**
|
||||
|
@ -136,21 +134,17 @@ public class Cleaner
|
|||
/**
|
||||
* Runs this cleaner, if it has not been run before.
|
||||
*/
|
||||
@SuppressWarnings("removal")
|
||||
public void clean() {
|
||||
if (!remove(this))
|
||||
return;
|
||||
try {
|
||||
thunk.run();
|
||||
} catch (final Throwable x) {
|
||||
AccessController.doPrivileged(new PrivilegedAction<>() {
|
||||
public Void run() {
|
||||
if (System.err != null)
|
||||
new Error("Cleaner terminated abnormally", x)
|
||||
.printStackTrace();
|
||||
System.exit(1);
|
||||
return null;
|
||||
}});
|
||||
if (System.err != null) {
|
||||
new Error("Cleaner terminated abnormally", x)
|
||||
.printStackTrace();
|
||||
}
|
||||
System.exit(1);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -41,7 +41,6 @@ import java.lang.reflect.InvocationTargetException;
|
|||
import java.lang.reflect.Method;
|
||||
import java.lang.reflect.Modifier;
|
||||
import java.lang.reflect.Proxy;
|
||||
import java.security.PrivilegedAction;
|
||||
import java.util.Set;
|
||||
|
||||
import jdk.internal.access.JavaLangReflectAccess;
|
||||
|
@ -75,22 +74,6 @@ public class ReflectionFactory {
|
|||
this.langReflectAccess = SharedSecrets.getJavaLangReflectAccess();
|
||||
}
|
||||
|
||||
/**
|
||||
* A convenience class for acquiring the capability to instantiate
|
||||
* reflective objects. Use this instead of a raw call to {@link
|
||||
* #getReflectionFactory} in order to avoid being limited by the
|
||||
* permissions of your callers.
|
||||
*
|
||||
* <p>An instance of this class can be used as the argument of
|
||||
* <code>AccessController.doPrivileged</code>.
|
||||
*/
|
||||
public static final class GetReflectionFactoryAction
|
||||
implements PrivilegedAction<ReflectionFactory> {
|
||||
public ReflectionFactory run() {
|
||||
return getReflectionFactory();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Provides the caller with the capability to instantiate reflective
|
||||
* objects.
|
||||
|
|
|
@ -154,7 +154,6 @@ class KeepAliveStream extends MeteredStream implements Hurryable {
|
|||
}
|
||||
}
|
||||
|
||||
@SuppressWarnings("removal")
|
||||
private static void queueForCleanup(KeepAliveCleanerEntry kace) {
|
||||
queue.lock();
|
||||
try {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue