8344078: Remove security manager dependency in java.nio

Reviewed-by: alanb, rriggs
This commit is contained in:
Brian Burkhalter 2024-11-18 19:17:14 +00:00
parent 2649406323
commit 922b12f30c
67 changed files with 285 additions and 1480 deletions

View file

@ -34,10 +34,6 @@ import java.util.Queue;
import java.util.concurrent.*;
import java.util.concurrent.atomic.AtomicInteger;
import java.util.concurrent.atomic.AtomicBoolean;
import java.security.PrivilegedAction;
import java.security.AccessController;
import java.security.AccessControlContext;
import sun.security.action.GetIntegerAction;
/**
* Base implementation of AsynchronousChannelGroup
@ -48,9 +44,8 @@ abstract class AsynchronousChannelGroupImpl
{
// number of internal threads handling I/O events when using an unbounded
// thread pool. Internal threads do not dispatch to completion handlers.
@SuppressWarnings("removal")
private static final int internalThreadCount = AccessController.doPrivileged(
new GetIntegerAction("sun.nio.ch.internalThreadPoolSize", 1));
private static final int internalThreadCount =
Integer.getInteger("sun.nio.ch.internalThreadPoolSize", 1);
// associated thread pool
private final ThreadPool pool;
@ -115,17 +110,10 @@ abstract class AsynchronousChannelGroupImpl
};
}
@SuppressWarnings("removal")
private void startInternalThread(final Runnable task) {
AccessController.doPrivileged(new PrivilegedAction<>() {
@Override
public Void run() {
// internal threads should not be visible to application so
// cannot use user-supplied thread factory
ThreadPool.defaultThreadFactory().newThread(task).start();
return null;
}
});
// internal threads should not be visible to application so
// cannot use user-supplied thread factory
ThreadPool.defaultThreadFactory().newThread(task).start();
}
protected final void startThreads(Runnable task) {
@ -247,18 +235,9 @@ abstract class AsynchronousChannelGroupImpl
*/
abstract void shutdownHandlerTasks();
@SuppressWarnings("removal")
private void shutdownExecutors() {
AccessController.doPrivileged(
new PrivilegedAction<>() {
public Void run() {
pool.executor().shutdown();
timeoutExecutor.shutdown();
return null;
}
},
null,
new RuntimePermission("modifyThread"));
pool.executor().shutdown();
timeoutExecutor.shutdown();
}
@Override
@ -320,28 +299,6 @@ abstract class AsynchronousChannelGroupImpl
*/
@Override
public final void execute(Runnable task) {
@SuppressWarnings("removal")
SecurityManager sm = System.getSecurityManager();
if (sm != null) {
// when a security manager is installed then the user's task
// must be run with the current calling context
@SuppressWarnings("removal")
final AccessControlContext acc = AccessController.getContext();
final Runnable delegate = task;
task = new Runnable() {
@SuppressWarnings("removal")
@Override
public void run() {
AccessController.doPrivileged(new PrivilegedAction<>() {
@Override
public Void run() {
delegate.run();
return null;
}
}, acc);
}
};
}
executeOnPooledThread(task);
}
}

View file

@ -1,5 +1,5 @@
/*
* Copyright (c) 2008, 2023, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2008, 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
@ -150,10 +150,6 @@ abstract class AsynchronousServerSocketChannelImpl
{
InetSocketAddress isa = (local == null) ? new InetSocketAddress(0) :
Net.checkAddress(local);
@SuppressWarnings("removal")
SecurityManager sm = System.getSecurityManager();
if (sm != null)
sm.checkListen(isa.getPort());
try {
begin();
@ -175,7 +171,7 @@ abstract class AsynchronousServerSocketChannelImpl
public final SocketAddress getLocalAddress() throws IOException {
if (!isOpen())
throw new ClosedChannelException();
return Net.getRevealedLocalAddress(localAddress);
return localAddress;
}
@Override
@ -257,7 +253,7 @@ abstract class AsynchronousServerSocketChannelImpl
if (localAddress == null) {
sb.append("unbound");
} else {
sb.append(Net.getRevealedLocalAddressAsString(localAddress));
sb.append(localAddress.toString());
}
}
sb.append(']');

View file

@ -1,5 +1,5 @@
/*
* Copyright (c) 2008, 2021, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2008, 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
@ -428,11 +428,6 @@ abstract class AsynchronousSocketChannelImpl
throw new AlreadyBoundException();
InetSocketAddress isa = (local == null) ?
new InetSocketAddress(0) : Net.checkAddress(local);
@SuppressWarnings("removal")
SecurityManager sm = System.getSecurityManager();
if (sm != null) {
sm.checkListen(isa.getPort());
}
NetHooks.beforeTcpBind(fd, isa.getAddress(), isa.getPort());
Net.bind(fd, isa.getAddress(), isa.getPort());
localAddress = Net.localAddress(fd);
@ -447,7 +442,7 @@ abstract class AsynchronousSocketChannelImpl
public final SocketAddress getLocalAddress() throws IOException {
if (!isOpen())
throw new ClosedChannelException();
return Net.getRevealedLocalAddress(localAddress);
return localAddress;
}
@Override
@ -591,8 +586,7 @@ abstract class AsynchronousSocketChannelImpl
}
if (localAddress != null) {
sb.append(" local=");
sb.append(
Net.getRevealedLocalAddressAsString(localAddress));
sb.append(localAddress.toString());
}
if (remoteAddress != null) {
sb.append(" remote=");

View file

@ -1,5 +1,5 @@
/*
* Copyright (c) 2008, 2010, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2008, 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
@ -49,8 +49,8 @@ final class CompletedFuture<V> implements Future<V> {
}
static <V> CompletedFuture<V> withFailure(Throwable exc) {
// exception must be IOException or SecurityException
if (!(exc instanceof IOException) && !(exc instanceof SecurityException))
// exception must be IOException
if (!(exc instanceof IOException))
exc = new IOException(exc);
return new CompletedFuture<V>(null, exc);
}

View file

@ -1,5 +1,5 @@
/*
* Copyright (c) 2008, 2023, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2008, 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
@ -27,8 +27,6 @@ package sun.nio.ch;
import java.nio.channels.*;
import java.util.concurrent.*;
import java.security.AccessController;
import sun.security.action.GetIntegerAction;
import jdk.internal.misc.InnocuousThread;
/**
@ -41,9 +39,8 @@ class Invoker {
// maximum number of completion handlers that may be invoked on the current
// thread before it re-directs invocations to the thread pool. This helps
// avoid stack overflow and lessens the risk of starvation.
@SuppressWarnings("removal")
private static final int maxHandlerInvokeCount = AccessController.doPrivileged(
new GetIntegerAction("sun.nio.ch.maxCompletionHandlersOnStack", 16));
private static final int maxHandlerInvokeCount =
Integer.getInteger("sun.nio.ch.maxCompletionHandlersOnStack", 16);
// Per-thread object with reference to channel group and a counter for
// the number of completion handlers invoked. This should be reset to 0
@ -115,7 +112,6 @@ class Invoker {
* Invoke handler without checking the thread identity or number of handlers
* on the thread stack.
*/
@SuppressWarnings("removal")
static <V,A> void invokeUnchecked(CompletionHandler<V,? super A> handler,
A attachment,
V value,
@ -129,18 +125,6 @@ class Invoker {
// clear interrupt
Thread.interrupted();
// clear thread locals when in default thread pool
if (System.getSecurityManager() != null) {
Thread me = Thread.currentThread();
if (me instanceof InnocuousThread) {
GroupAndInvokeCount thisGroupAndInvokeCount = myGroupAndInvokeCount.get();
((InnocuousThread)me).eraseThreadLocals();
if (thisGroupAndInvokeCount != null) {
myGroupAndInvokeCount.set(thisGroupAndInvokeCount);
}
}
}
}
/**

View file

@ -1,5 +1,5 @@
/*
* Copyright (c) 2000, 2023, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2000, 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
@ -45,14 +45,11 @@ import java.nio.channels.NotYetBoundException;
import java.nio.channels.NotYetConnectedException;
import java.nio.channels.UnresolvedAddressException;
import java.nio.channels.UnsupportedAddressTypeException;
import java.security.AccessController;
import java.security.PrivilegedAction;
import java.util.Enumeration;
import java.util.Objects;
import sun.net.ext.ExtendedSocketOptions;
import sun.net.util.IPAddressUtil;
import sun.security.action.GetPropertyAction;
public class Net {
private Net() { }
@ -215,34 +212,6 @@ public class Net {
translateException(x, false);
}
/**
* Returns the local address after performing a SecurityManager#checkConnect.
*/
static InetSocketAddress getRevealedLocalAddress(SocketAddress sa) {
InetSocketAddress isa = (InetSocketAddress) sa;
@SuppressWarnings("removal")
SecurityManager sm = System.getSecurityManager();
if (isa != null && sm != null) {
try {
sm.checkConnect(isa.getAddress().getHostAddress(), -1);
} catch (SecurityException e) {
// Return loopback address only if security check fails
isa = getLoopbackAddress(isa.getPort());
}
}
return isa;
}
@SuppressWarnings("removal")
static String getRevealedLocalAddressAsString(SocketAddress sa) {
InetSocketAddress isa = (InetSocketAddress) sa;
if (System.getSecurityManager() == null) {
return isa.toString();
} else {
return getLoopbackAddress(isa.getPort()).toString();
}
}
private static InetSocketAddress getLoopbackAddress(int port) {
return new InetSocketAddress(InetAddress.getLoopbackAddress(), port);
}
@ -302,20 +271,15 @@ public class Net {
* Returns any IPv4 address of the given network interface, or
* null if the interface does not have any IPv4 addresses.
*/
@SuppressWarnings("removal")
static Inet4Address anyInet4Address(final NetworkInterface interf) {
return AccessController.doPrivileged(new PrivilegedAction<Inet4Address>() {
public Inet4Address run() {
Enumeration<InetAddress> addrs = interf.getInetAddresses();
while (addrs.hasMoreElements()) {
InetAddress addr = addrs.nextElement();
if (addr instanceof Inet4Address inet4Address) {
return inet4Address;
}
}
return null;
Enumeration<InetAddress> addrs = interf.getInetAddresses();
while (addrs.hasMoreElements()) {
InetAddress addr = addrs.nextElement();
if (addr instanceof Inet4Address inet4Address) {
return inet4Address;
}
});
}
return null;
}
/**
@ -500,8 +464,7 @@ public class Net {
}
private static boolean isFastTcpLoopbackRequested() {
String loopbackProp = GetPropertyAction
.privilegedGetProperty("jdk.net.useFastTcpLoopback", "false");
String loopbackProp = System.getProperty("jdk.net.useFastTcpLoopback", "false");
return loopbackProp.isEmpty() || Boolean.parseBoolean(loopbackProp);
}
@ -827,8 +790,7 @@ public class Net {
static {
int availLevel = isExclusiveBindAvailable();
if (availLevel >= 0) {
String exclBindProp = GetPropertyAction
.privilegedGetProperty("sun.net.useExclusiveBind");
String exclBindProp = System.getProperty("sun.net.useExclusiveBind");
if (exclBindProp != null) {
EXCLUSIVE_BIND = exclBindProp.isEmpty() || Boolean.parseBoolean(exclBindProp);
} else {

View file

@ -145,7 +145,7 @@ final class PendingFuture<V,A> implements Future<V> {
* Sets the result, or a no-op if the result or exception is already set.
*/
void setFailure(Throwable x) {
if (!(x instanceof IOException) && !(x instanceof SecurityException))
if (!(x instanceof IOException))
x = new IOException(x);
synchronized (this) {
if (haveResult)

View file

@ -1,5 +1,5 @@
/*
* Copyright (c) 2000, 2021, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2000, 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
@ -27,8 +27,6 @@ package sun.nio.ch;
import java.io.*;
import java.lang.reflect.*;
import java.security.AccessController;
import java.security.PrivilegedAction;
class Reflect { // package-private
@ -43,22 +41,13 @@ class Reflect { // package-private
}
}
@SuppressWarnings("removal")
private static void setAccessible(final AccessibleObject ao) {
AccessController.doPrivileged(new PrivilegedAction<Void>() {
public Void run() {
ao.setAccessible(true);
return null;
}});
}
static Constructor<?> lookupConstructor(String className,
Class<?>[] paramTypes)
{
try {
Class<?> cl = Class.forName(className);
Constructor<?> c = cl.getDeclaredConstructor(paramTypes);
setAccessible(c);
c.setAccessible(true);
return c;
} catch (ClassNotFoundException | NoSuchMethodException x) {
throw new ReflectionError(x);
@ -82,7 +71,7 @@ class Reflect { // package-private
try {
Class<?> cl = Class.forName(className);
Method m = cl.getDeclaredMethod(methodName, paramTypes);
setAccessible(m);
m.setAccessible(true);
return m;
} catch (ClassNotFoundException | NoSuchMethodException x) {
throw new ReflectionError(x);
@ -115,7 +104,7 @@ class Reflect { // package-private
try {
Class<?> cl = Class.forName(className);
Field f = cl.getDeclaredField(fieldName);
setAccessible(f);
f.setAccessible(true);
return f;
} catch (ClassNotFoundException | NoSuchFieldException x) {
throw new ReflectionError(x);

View file

@ -1,5 +1,5 @@
/*
* Copyright (c) 2000, 2021, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2000, 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
@ -37,9 +37,6 @@ import java.net.StandardSocketOptions;
import java.nio.channels.IllegalBlockingModeException;
import java.nio.channels.ServerSocketChannel;
import java.nio.channels.SocketChannel;
import java.security.AccessController;
import java.security.PrivilegedActionException;
import java.security.PrivilegedExceptionAction;
import java.util.Set;
import static java.util.concurrent.TimeUnit.MILLISECONDS;
@ -61,14 +58,8 @@ class ServerSocketAdaptor // package-private
// Timeout "option" value for accepts
private volatile int timeout;
@SuppressWarnings("removal")
static ServerSocket create(ServerSocketChannelImpl ssc) {
PrivilegedExceptionAction<ServerSocket> pa = () -> new ServerSocketAdaptor(ssc);
try {
return AccessController.doPrivileged(pa);
} catch (PrivilegedActionException pae) {
throw new InternalError("Should not reach here", pae);
}
return new ServerSocketAdaptor(ssc);
}
private ServerSocketAdaptor(ServerSocketChannelImpl ssc) {
@ -98,7 +89,7 @@ class ServerSocketAdaptor // package-private
if (local == null) {
return null;
} else {
return Net.getRevealedLocalAddress(local).getAddress();
return ((InetSocketAddress)local).getAddress();
}
}

View file

@ -202,11 +202,7 @@ class ServerSocketChannelImpl
public SocketAddress getLocalAddress() throws IOException {
synchronized (stateLock) {
ensureOpen();
if (isUnixSocket()) {
return UnixDomainSockets.getRevealedLocalAddress(localAddress);
} else {
return Net.getRevealedLocalAddress(localAddress);
}
return localAddress;
}
}
@ -305,7 +301,6 @@ class ServerSocketChannelImpl
}
private SocketAddress unixBind(SocketAddress local, int backlog) throws IOException {
UnixDomainSockets.checkPermission();
if (local == null) {
// Attempt up to 10 times to find an unused name in temp directory.
// If local address supplied then bind called only once
@ -336,10 +331,6 @@ class ServerSocketChannelImpl
} else {
isa = Net.checkAddress(local, family);
}
@SuppressWarnings("removal")
SecurityManager sm = System.getSecurityManager();
if (sm != null)
sm.checkListen(isa.getPort());
NetHooks.beforeTcpBind(fd, isa.getAddress(), isa.getPort());
Net.bind(family, fd, isa.getAddress(), isa.getPort());
Net.listen(fd, backlog < 1 ? 50 : backlog);
@ -423,7 +414,6 @@ class ServerSocketChannelImpl
throws IOException
{
if (isUnixSocket()) {
UnixDomainSockets.checkPermission();
String[] pa = new String[1];
int n = UnixDomainSockets.accept(fd, newfd, pa);
if (n > 0)
@ -495,16 +485,6 @@ class ServerSocketChannelImpl
try {
// newly accepted socket is initially in blocking mode
IOUtil.configureBlocking(newfd, true);
// check permitted to accept connections from the remote address
if (isNetSocket()) {
@SuppressWarnings("removal")
SecurityManager sm = System.getSecurityManager();
if (sm != null) {
InetSocketAddress isa = (InetSocketAddress) sa;
sm.checkAccept(isa.getAddress().getHostAddress(), isa.getPort());
}
}
return new SocketChannelImpl(provider(), family, newfd, sa);
} catch (Exception e) {
nd.close(newfd);
@ -749,9 +729,7 @@ class ServerSocketChannelImpl
if (addr == null) {
sb.append("unbound");
} else if (isUnixSocket()) {
sb.append(UnixDomainSockets.getRevealedLocalAddressAsString(addr));
} else {
sb.append(Net.getRevealedLocalAddressAsString(addr));
sb.append(addr);
}
}
}

View file

@ -30,8 +30,6 @@ import jdk.internal.event.FileForceEvent;
import java.nio.channels.*;
import java.util.concurrent.*;
import java.nio.ByteBuffer;
import java.security.AccessController;
import java.security.PrivilegedAction;
import java.io.FileDescriptor;
import java.io.IOException;

View file

@ -1,5 +1,5 @@
/*
* Copyright (c) 2000, 2022, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2000, 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
@ -36,9 +36,6 @@ import java.net.SocketException;
import java.net.SocketOption;
import java.net.StandardSocketOptions;
import java.nio.channels.SocketChannel;
import java.security.AccessController;
import java.security.PrivilegedActionException;
import java.security.PrivilegedExceptionAction;
import java.util.Set;
import static java.util.concurrent.TimeUnit.MILLISECONDS;
@ -63,16 +60,10 @@ class SocketAdaptor
this.sc = sc;
}
@SuppressWarnings("removal")
static Socket create(SocketChannelImpl sc) {
try {
if (System.getSecurityManager() == null) {
return new SocketAdaptor(sc);
} else {
PrivilegedExceptionAction<Socket> pa = () -> new SocketAdaptor(sc);
return AccessController.doPrivileged(pa);
}
} catch (SocketException | PrivilegedActionException e) {
return new SocketAdaptor(sc);
} catch (SocketException e) {
throw new InternalError(e);
}
}
@ -132,7 +123,7 @@ class SocketAdaptor
if (sc.isOpen()) {
InetSocketAddress local = localAddress();
if (local != null) {
return Net.getRevealedLocalAddress(local).getAddress();
return local.getAddress();
}
}
return new InetSocketAddress(0).getAddress();
@ -165,7 +156,7 @@ class SocketAdaptor
@Override
public SocketAddress getLocalSocketAddress() {
return Net.getRevealedLocalAddress(sc.localAddress());
return sc.localAddress();
}
@Override

View file

@ -243,11 +243,7 @@ class SocketChannelImpl
public SocketAddress getLocalAddress() throws IOException {
synchronized (stateLock) {
ensureOpen();
if (isUnixSocket()) {
return UnixDomainSockets.getRevealedLocalAddress(localAddress);
} else {
return Net.getRevealedLocalAddress(localAddress);
}
return localAddress;
}
}
@ -811,7 +807,6 @@ class SocketChannelImpl
}
private SocketAddress unixBind(SocketAddress local) throws IOException {
UnixDomainSockets.checkPermission();
if (local == null) {
return UnixDomainSockets.unnamed();
} else {
@ -833,11 +828,6 @@ class SocketChannelImpl
} else {
isa = Net.checkAddress(local, family);
}
@SuppressWarnings("removal")
SecurityManager sm = System.getSecurityManager();
if (sm != null) {
sm.checkListen(isa.getPort());
}
NetHooks.beforeTcpBind(fd, isa.getAddress(), isa.getPort());
Net.bind(family, fd, isa.getAddress(), isa.getPort());
return Net.localAddress(fd);
@ -923,15 +913,9 @@ class SocketChannelImpl
*/
private SocketAddress checkRemote(SocketAddress sa) {
if (isUnixSocket()) {
UnixDomainSockets.checkPermission();
return UnixDomainSockets.checkAddress(sa);
} else {
InetSocketAddress isa = Net.checkAddress(sa, family);
@SuppressWarnings("removal")
SecurityManager sm = System.getSecurityManager();
if (sm != null) {
sm.checkConnect(isa.getAddress().getHostAddress(), isa.getPort());
}
InetAddress address = isa.getAddress();
if (address.isAnyLocalAddress()) {
int port = isa.getPort();
@ -1617,15 +1601,11 @@ class SocketChannelImpl
SocketAddress addr = localAddress();
if (addr != null) {
sb.append(" local=");
if (isUnixSocket()) {
sb.append(UnixDomainSockets.getRevealedLocalAddressAsString(addr));
} else {
sb.append(Net.getRevealedLocalAddressAsString(addr));
}
sb.append(addr);
}
if (remoteAddress() != null) {
sb.append(" remote=");
sb.append(remoteAddress().toString());
sb.append(remoteAddress());
}
}
}

View file

@ -26,10 +26,6 @@
package sun.nio.ch;
import java.util.concurrent.*;
import java.security.AccessController;
import java.security.PrivilegedAction;
import sun.security.action.GetPropertyAction;
import sun.security.action.GetIntegerAction;
import jdk.internal.misc.InnocuousThread;
/**
@ -72,24 +68,12 @@ public class ThreadPool {
return poolSize;
}
@SuppressWarnings("removal")
static ThreadFactory defaultThreadFactory() {
if (System.getSecurityManager() == null) {
return (Runnable r) -> {
Thread t = new Thread(r);
t.setDaemon(true);
return t;
};
} else {
return (Runnable r) -> {
PrivilegedAction<Thread> action = () -> {
Thread t = InnocuousThread.newThread(r);
t.setDaemon(true);
return t;
};
return AccessController.doPrivileged(action);
};
}
return (Runnable r) -> {
Thread t = new Thread(r);
t.setDaemon(true);
return t;
};
}
private static class DefaultThreadPoolHolder {
@ -148,9 +132,7 @@ public class ThreadPool {
}
private static int getDefaultThreadPoolInitialSize() {
@SuppressWarnings("removal")
String propValue = AccessController.doPrivileged(new
GetPropertyAction(DEFAULT_THREAD_POOL_INITIAL_SIZE));
String propValue = System.getProperty(DEFAULT_THREAD_POOL_INITIAL_SIZE);
if (propValue != null) {
try {
return Integer.parseInt(propValue);
@ -163,9 +145,7 @@ public class ThreadPool {
}
private static ThreadFactory getDefaultThreadPoolThreadFactory() {
@SuppressWarnings("removal")
String propValue = AccessController.doPrivileged(new
GetPropertyAction(DEFAULT_THREAD_POOL_THREAD_FACTORY));
String propValue = System.getProperty(DEFAULT_THREAD_POOL_THREAD_FACTORY);
if (propValue != null) {
try {
@SuppressWarnings("deprecation")

View file

@ -1,5 +1,5 @@
/*
* Copyright (c) 2020, 2021, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2020, 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
@ -59,25 +59,6 @@ class UnixDomainSockets {
return supported;
}
static void checkPermission() {
@SuppressWarnings("removal")
SecurityManager sm = System.getSecurityManager();
if (sm != null)
sm.checkPermission(accessUnixDomainSocket);
}
static UnixDomainSocketAddress getRevealedLocalAddress(SocketAddress sa) {
UnixDomainSocketAddress addr = (UnixDomainSocketAddress) sa;
try {
checkPermission();
// Security check passed
} catch (SecurityException e) {
// Return unnamed address only if security check fails
addr = unnamed();
}
return addr;
}
static UnixDomainSocketAddress localAddress(FileDescriptor fd) throws IOException {
String path = new String(localAddress0(fd), UnixDomainSocketsUtil.getCharset());
return UnixDomainSocketAddress.of(path);
@ -85,11 +66,6 @@ class UnixDomainSockets {
private static native byte[] localAddress0(FileDescriptor fd) throws IOException;
@SuppressWarnings("removal")
static String getRevealedLocalAddressAsString(SocketAddress sa) {
return (System.getSecurityManager() != null) ? sa.toString() : "";
}
static UnixDomainSocketAddress checkAddress(SocketAddress sa) {
if (sa == null)
throw new NullPointerException();

View file

@ -1,5 +1,5 @@
/*
* Copyright (c) 2000, 2022, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2000, 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
@ -32,15 +32,12 @@ import java.lang.reflect.Constructor;
import java.lang.reflect.InvocationTargetException;
import java.nio.ByteBuffer;
import java.nio.MappedByteBuffer;
import java.security.AccessController;
import java.security.PrivilegedAction;
import java.util.Collection;
import java.util.Iterator;
import java.util.Set;
import jdk.internal.misc.TerminatingThreadLocal;
import jdk.internal.misc.Unsafe;
import sun.security.action.GetPropertyAction;
public class Util {
@ -75,7 +72,7 @@ public class Util {
* for potential future-proofing.
*/
private static long getMaxCachedBufferSize() {
String s = GetPropertyAction.privilegedGetProperty("jdk.nio.maxCachedBufferSize");
String s = System.getProperty("jdk.nio.maxCachedBufferSize");
if (s != null) {
try {
long m = Long.parseLong(s);
@ -406,28 +403,23 @@ public class Util {
private static volatile Constructor<?> directByteBufferConstructor;
@SuppressWarnings("removal")
private static void initDBBConstructor() {
AccessController.doPrivileged(new PrivilegedAction<Void>() {
public Void run() {
try {
Class<?> cl = Class.forName("java.nio.DirectByteBuffer");
Constructor<?> ctor = cl.getDeclaredConstructor(
new Class<?>[] { int.class,
long.class,
FileDescriptor.class,
Runnable.class,
boolean.class, MemorySegment.class});
ctor.setAccessible(true);
directByteBufferConstructor = ctor;
} catch (ClassNotFoundException |
NoSuchMethodException |
IllegalArgumentException |
ClassCastException x) {
throw new InternalError(x);
}
return null;
}});
try {
Class<?> cl = Class.forName("java.nio.DirectByteBuffer");
Constructor<?> ctor = cl.getDeclaredConstructor(
new Class<?>[] { int.class,
long.class,
FileDescriptor.class,
Runnable.class,
boolean.class, MemorySegment.class });
ctor.setAccessible(true);
directByteBufferConstructor = ctor;
} catch (ClassNotFoundException |
NoSuchMethodException |
IllegalArgumentException |
ClassCastException x) {
throw new InternalError(x);
}
}
static MappedByteBuffer newMappedByteBuffer(int size, long addr,
@ -455,28 +447,23 @@ public class Util {
private static volatile Constructor<?> directByteBufferRConstructor;
@SuppressWarnings("removal")
private static void initDBBRConstructor() {
AccessController.doPrivileged(new PrivilegedAction<Void>() {
public Void run() {
try {
Class<?> cl = Class.forName("java.nio.DirectByteBufferR");
Constructor<?> ctor = cl.getDeclaredConstructor(
new Class<?>[] { int.class,
long.class,
FileDescriptor.class,
Runnable.class,
boolean.class, MemorySegment.class });
ctor.setAccessible(true);
directByteBufferRConstructor = ctor;
} catch (ClassNotFoundException |
NoSuchMethodException |
IllegalArgumentException |
ClassCastException x) {
throw new InternalError(x);
}
return null;
}});
try {
Class<?> cl = Class.forName("java.nio.DirectByteBufferR");
Constructor<?> ctor = cl.getDeclaredConstructor(
new Class<?>[] { int.class,
long.class,
FileDescriptor.class,
Runnable.class,
boolean.class, MemorySegment.class });
ctor.setAccessible(true);
directByteBufferRConstructor = ctor;
} catch (ClassNotFoundException |
NoSuchMethodException |
IllegalArgumentException |
ClassCastException x) {
throw new InternalError(x);
}
}
static MappedByteBuffer newMappedByteBufferR(int size, long addr,

View file

@ -1,5 +1,5 @@
/*
* Copyright (c) 2008, 2023, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2008, 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 sun.nio.cs;
import java.io.InputStream;
import java.io.IOException;
import java.util.*;
import java.security.*;
public class CharsetMapping {
public static final char UNMAPPABLE_DECODING = '\uFFFD';
@ -129,13 +128,8 @@ public class CharsetMapping {
}
// init the CharsetMapping object from the .dat binary file
@SuppressWarnings("removal")
public static CharsetMapping get(final InputStream is) {
return AccessController.doPrivileged(new PrivilegedAction<>() {
public CharsetMapping run() {
return new CharsetMapping().load(is);
}
});
return new CharsetMapping().load(is);
}
public static class Entry {

View file

@ -1,5 +1,5 @@
/*
* Copyright (c) 2008, 2021, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2008, 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 sun.nio.fs;
import java.nio.file.*;
import java.security.AccessController;
import java.security.PrivilegedAction;
import java.io.IOException;
import java.util.*;
@ -54,22 +52,14 @@ abstract class AbstractPoller implements Runnable {
/**
* Starts the poller thread
*/
@SuppressWarnings("removal")
public void start() {
final Runnable thisRunnable = this;
AccessController.doPrivileged(new PrivilegedAction<>() {
@Override
public Object run() {
Thread thr = new Thread(null,
thisRunnable,
"FileSystemWatchService",
0,
false);
thr.setDaemon(true);
thr.start();
return null;
}
});
Thread thr = new Thread(null,
this,
"FileSystemWatchService",
0,
false);
thr.setDaemon(true);
thr.start();
}
/**

View file

@ -1,5 +1,5 @@
/*
* Copyright (c) 2008, 2021, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2008, 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,9 +25,9 @@
package sun.nio.fs;
import java.io.IOException;
import java.nio.ByteBuffer;
import java.nio.file.attribute.UserDefinedFileAttributeView;
import java.io.IOException;
import java.util.*;
/**
@ -39,22 +39,6 @@ abstract class AbstractUserDefinedFileAttributeView
{
protected AbstractUserDefinedFileAttributeView() { }
protected void checkAccess(String file,
boolean checkRead,
boolean checkWrite)
{
assert checkRead || checkWrite;
@SuppressWarnings("removal")
SecurityManager sm = System.getSecurityManager();
if (sm != null) {
if (checkRead)
sm.checkRead(file);
if (checkWrite)
sm.checkWrite(file);
sm.checkPermission(new RuntimePermission("accessUserDefinedAttributes"));
}
}
@Override
public final String name() {
return "user";

View file

@ -1,5 +1,5 @@
/*
* Copyright (c) 2008, 2023, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2008, 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
@ -36,10 +36,6 @@ import java.nio.file.WatchEvent;
import java.nio.file.WatchKey;
import java.nio.file.attribute.BasicFileAttributes;
import java.nio.file.attribute.FileTime;
import java.security.AccessController;
import java.security.PrivilegedAction;
import java.security.PrivilegedExceptionAction;
import java.security.PrivilegedActionException;
import java.io.IOException;
import java.util.HashMap;
import java.util.HashSet;
@ -86,7 +82,6 @@ class PollingWatchService
/**
* Register the given file with this watch service
*/
@SuppressWarnings("removal")
@Override
WatchKey register(final Path path,
WatchEvent.Kind<?>[] events,
@ -133,30 +128,9 @@ class PollingWatchService
if (!isOpen())
throw new ClosedWatchServiceException();
// registration is done in privileged block as it requires the
// attributes of the entries in the directory.
try {
return AccessController.doPrivileged(
new PrivilegedExceptionAction<PollingWatchKey>() {
@Override
public PollingWatchKey run() throws IOException {
return doPrivilegedRegister(path, eventSet);
}
});
} catch (PrivilegedActionException pae) {
Throwable cause = pae.getCause();
if (cause instanceof IOException ioe)
throw ioe;
throw new AssertionError(pae);
}
}
// registers directory returning a new key if not already registered or
// existing key if already registered
// registers directory returning a new key if not already registered or
// existing key if already registered
private PollingWatchKey doPrivilegedRegister(Path path,
Set<? extends WatchEvent.Kind<?>> events)
throws IOException
{
// check file is a directory and get its file key if possible
BasicFileAttributes attrs = Files.readAttributes(path, BasicFileAttributes.class);
if (!attrs.isDirectory()) {
@ -183,13 +157,12 @@ class PollingWatchService
watchKey.disable();
}
}
watchKey.enable(events);
watchKey.enable(eventSet);
return watchKey;
}
}
@SuppressWarnings("removal")
@Override
void implClose() throws IOException {
synchronized (map) {
@ -200,13 +173,7 @@ class PollingWatchService
}
map.clear();
}
AccessController.doPrivileged(new PrivilegedAction<Void>() {
@Override
public Void run() {
scheduledExecutor.shutdown();
return null;
}
});
scheduledExecutor.shutdown();
}
/**