mirror of
https://github.com/openjdk/jdk.git
synced 2025-08-27 14:54:52 +02:00
8344078: Remove security manager dependency in java.nio
Reviewed-by: alanb, rriggs
This commit is contained in:
parent
2649406323
commit
922b12f30c
67 changed files with 285 additions and 1480 deletions
|
@ -31,8 +31,6 @@ import java.util.Iterator;
|
|||
import java.util.ServiceLoader;
|
||||
import java.util.ServiceConfigurationError;
|
||||
import java.util.concurrent.*;
|
||||
import java.security.AccessController;
|
||||
import java.security.PrivilegedAction;
|
||||
|
||||
/**
|
||||
* Service-provider class for asynchronous channels.
|
||||
|
@ -62,20 +60,15 @@ public abstract class AsynchronousChannelProvider {
|
|||
private static class ProviderHolder {
|
||||
static final AsynchronousChannelProvider provider = load();
|
||||
|
||||
@SuppressWarnings("removal")
|
||||
private static AsynchronousChannelProvider load() {
|
||||
return AccessController
|
||||
.doPrivileged(new PrivilegedAction<>() {
|
||||
public AsynchronousChannelProvider run() {
|
||||
AsynchronousChannelProvider p;
|
||||
p = loadProviderFromProperty();
|
||||
if (p != null)
|
||||
return p;
|
||||
p = loadProviderAsService();
|
||||
if (p != null)
|
||||
return p;
|
||||
return sun.nio.ch.DefaultAsynchronousChannelProvider.create();
|
||||
}});
|
||||
AsynchronousChannelProvider p;
|
||||
p = loadProviderFromProperty();
|
||||
if (p != null)
|
||||
return p;
|
||||
p = loadProviderAsService();
|
||||
if (p != null)
|
||||
return p;
|
||||
return sun.nio.ch.DefaultAsynchronousChannelProvider.create();
|
||||
}
|
||||
|
||||
private static AsynchronousChannelProvider loadProviderFromProperty() {
|
||||
|
@ -87,7 +80,7 @@ public abstract class AsynchronousChannelProvider {
|
|||
Object tmp = Class.forName(cn, true,
|
||||
ClassLoader.getSystemClassLoader()).newInstance();
|
||||
return (AsynchronousChannelProvider)tmp;
|
||||
} catch (ClassNotFoundException | SecurityException |
|
||||
} catch (ClassNotFoundException |
|
||||
InstantiationException | IllegalAccessException x) {
|
||||
throw new ServiceConfigurationError(null, x);
|
||||
}
|
||||
|
@ -98,17 +91,7 @@ public abstract class AsynchronousChannelProvider {
|
|||
ServiceLoader.load(AsynchronousChannelProvider.class,
|
||||
ClassLoader.getSystemClassLoader());
|
||||
Iterator<AsynchronousChannelProvider> i = sl.iterator();
|
||||
for (;;) {
|
||||
try {
|
||||
return (i.hasNext()) ? i.next() : null;
|
||||
} catch (ServiceConfigurationError sce) {
|
||||
if (sce.getCause() instanceof SecurityException) {
|
||||
// Ignore the security exception, try the next provider
|
||||
continue;
|
||||
}
|
||||
throw sce;
|
||||
}
|
||||
}
|
||||
return sl.findFirst().orElse(null);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -33,8 +33,6 @@ import java.nio.channels.DatagramChannel;
|
|||
import java.nio.channels.Pipe;
|
||||
import java.nio.channels.ServerSocketChannel;
|
||||
import java.nio.channels.SocketChannel;
|
||||
import java.security.AccessController;
|
||||
import java.security.PrivilegedAction;
|
||||
import java.util.Iterator;
|
||||
import java.util.Objects;
|
||||
import java.util.ServiceLoader;
|
||||
|
@ -81,17 +79,13 @@ public abstract class SelectorProvider {
|
|||
private static class Holder {
|
||||
static final SelectorProvider INSTANCE = provider();
|
||||
|
||||
@SuppressWarnings("removal")
|
||||
static SelectorProvider provider() {
|
||||
PrivilegedAction<SelectorProvider> pa = () -> {
|
||||
SelectorProvider sp;
|
||||
if ((sp = loadProviderFromProperty()) != null)
|
||||
return sp;
|
||||
if ((sp = loadProviderAsService()) != null)
|
||||
return sp;
|
||||
return sun.nio.ch.DefaultSelectorProvider.get();
|
||||
};
|
||||
return AccessController.doPrivileged(pa);
|
||||
SelectorProvider sp;
|
||||
if ((sp = loadProviderFromProperty()) != null)
|
||||
return sp;
|
||||
if ((sp = loadProviderAsService()) != null)
|
||||
return sp;
|
||||
return sun.nio.ch.DefaultSelectorProvider.get();
|
||||
}
|
||||
|
||||
private static SelectorProvider loadProviderFromProperty() {
|
||||
|
@ -105,8 +99,7 @@ public abstract class SelectorProvider {
|
|||
NoSuchMethodException |
|
||||
IllegalAccessException |
|
||||
InvocationTargetException |
|
||||
InstantiationException |
|
||||
SecurityException x) {
|
||||
InstantiationException x) {
|
||||
throw new ServiceConfigurationError(null, x);
|
||||
}
|
||||
}
|
||||
|
@ -116,17 +109,7 @@ public abstract class SelectorProvider {
|
|||
ServiceLoader.load(SelectorProvider.class,
|
||||
ClassLoader.getSystemClassLoader());
|
||||
Iterator<SelectorProvider> i = sl.iterator();
|
||||
for (;;) {
|
||||
try {
|
||||
return i.hasNext() ? i.next() : null;
|
||||
} catch (ServiceConfigurationError sce) {
|
||||
if (sce.getCause() instanceof SecurityException) {
|
||||
// Ignore the security exception, try the next provider
|
||||
continue;
|
||||
}
|
||||
throw sce;
|
||||
}
|
||||
}
|
||||
return sl.findFirst().orElse(null);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -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
|
||||
|
@ -34,15 +34,12 @@ import sun.nio.cs.ThreadLocalCoders;
|
|||
import java.nio.ByteBuffer;
|
||||
import java.nio.CharBuffer;
|
||||
import java.nio.charset.spi.CharsetProvider;
|
||||
import java.security.AccessController;
|
||||
import java.security.PrivilegedAction;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
import java.util.Iterator;
|
||||
import java.util.Locale;
|
||||
import java.util.Map;
|
||||
import java.util.NoSuchElementException;
|
||||
import java.util.ServiceConfigurationError;
|
||||
import java.util.ServiceLoader;
|
||||
import java.util.Set;
|
||||
import java.util.SortedMap;
|
||||
|
@ -346,9 +343,7 @@ public abstract class Charset
|
|||
cache1 = new Object[] { charsetName, cs };
|
||||
}
|
||||
|
||||
// Creates an iterator that walks over the available providers, ignoring
|
||||
// those whose lookup or instantiation causes a security exception to be
|
||||
// thrown. Should be invoked with full privileges.
|
||||
// Creates an iterator that walks over the available providers
|
||||
//
|
||||
private static Iterator<CharsetProvider> providers() {
|
||||
return new Iterator<>() {
|
||||
|
@ -360,17 +355,9 @@ public abstract class Charset
|
|||
|
||||
private boolean getNext() {
|
||||
while (next == null) {
|
||||
try {
|
||||
if (!i.hasNext())
|
||||
return false;
|
||||
next = i.next();
|
||||
} catch (ServiceConfigurationError sce) {
|
||||
if (sce.getCause() instanceof SecurityException) {
|
||||
// Ignore security exceptions
|
||||
continue;
|
||||
}
|
||||
throw sce;
|
||||
}
|
||||
if (!i.hasNext())
|
||||
return false;
|
||||
next = i.next();
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
@ -406,7 +393,6 @@ public abstract class Charset
|
|||
ThreadTrackHolder.TRACKER.end(key);
|
||||
}
|
||||
|
||||
@SuppressWarnings("removal")
|
||||
private static Charset lookupViaProviders(final String charsetName) {
|
||||
|
||||
// The runtime startup sequence looks up standard charsets as a
|
||||
|
@ -426,20 +412,13 @@ public abstract class Charset
|
|||
return null;
|
||||
}
|
||||
try {
|
||||
return AccessController.doPrivileged(
|
||||
new PrivilegedAction<>() {
|
||||
public Charset run() {
|
||||
for (Iterator<CharsetProvider> i = providers();
|
||||
i.hasNext();) {
|
||||
CharsetProvider cp = i.next();
|
||||
Charset cs = cp.charsetForName(charsetName);
|
||||
if (cs != null)
|
||||
return cs;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
});
|
||||
|
||||
for (Iterator<CharsetProvider> i = providers(); i.hasNext();) {
|
||||
CharsetProvider cp = i.next();
|
||||
Charset cs = cp.charsetForName(charsetName);
|
||||
if (cs != null)
|
||||
return cs;
|
||||
}
|
||||
return null;
|
||||
} finally {
|
||||
endLookup(key);
|
||||
}
|
||||
|
@ -449,22 +428,18 @@ public abstract class Charset
|
|||
private static class ExtendedProviderHolder {
|
||||
static final CharsetProvider[] extendedProviders = extendedProviders();
|
||||
// returns ExtendedProvider, if installed
|
||||
@SuppressWarnings("removal")
|
||||
private static CharsetProvider[] extendedProviders() {
|
||||
return AccessController.doPrivileged(new PrivilegedAction<>() {
|
||||
public CharsetProvider[] run() {
|
||||
CharsetProvider[] cps = new CharsetProvider[1];
|
||||
int n = 0;
|
||||
ServiceLoader<CharsetProvider> sl =
|
||||
ServiceLoader.loadInstalled(CharsetProvider.class);
|
||||
for (CharsetProvider cp : sl) {
|
||||
if (n + 1 > cps.length) {
|
||||
cps = Arrays.copyOf(cps, cps.length << 1);
|
||||
}
|
||||
cps[n++] = cp;
|
||||
}
|
||||
return n == cps.length ? cps : Arrays.copyOf(cps, n);
|
||||
}});
|
||||
CharsetProvider[] cps = new CharsetProvider[1];
|
||||
int n = 0;
|
||||
ServiceLoader<CharsetProvider> sl =
|
||||
ServiceLoader.loadInstalled(CharsetProvider.class);
|
||||
for (CharsetProvider cp : sl) {
|
||||
if (n + 1 > cps.length) {
|
||||
cps = Arrays.copyOf(cps, cps.length << 1);
|
||||
}
|
||||
cps[n++] = cp;
|
||||
}
|
||||
return n == cps.length ? cps : Arrays.copyOf(cps, n);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -628,26 +603,20 @@ public abstract class Charset
|
|||
* @return An immutable, case-insensitive map from canonical charset names
|
||||
* to charset objects
|
||||
*/
|
||||
@SuppressWarnings("removal")
|
||||
public static SortedMap<String,Charset> availableCharsets() {
|
||||
return AccessController.doPrivileged(
|
||||
new PrivilegedAction<>() {
|
||||
public SortedMap<String,Charset> run() {
|
||||
TreeMap<String,Charset> m =
|
||||
new TreeMap<>(
|
||||
String.CASE_INSENSITIVE_ORDER);
|
||||
put(standardProvider.charsets(), m);
|
||||
CharsetProvider[] ecps = ExtendedProviderHolder.extendedProviders;
|
||||
for (CharsetProvider ecp :ecps) {
|
||||
put(ecp.charsets(), m);
|
||||
}
|
||||
for (Iterator<CharsetProvider> i = providers(); i.hasNext();) {
|
||||
CharsetProvider cp = i.next();
|
||||
put(cp.charsets(), m);
|
||||
}
|
||||
return Collections.unmodifiableSortedMap(m);
|
||||
}
|
||||
});
|
||||
TreeMap<String,Charset> m =
|
||||
new TreeMap<>(
|
||||
String.CASE_INSENSITIVE_ORDER);
|
||||
put(standardProvider.charsets(), m);
|
||||
CharsetProvider[] ecps = ExtendedProviderHolder.extendedProviders;
|
||||
for (CharsetProvider ecp :ecps) {
|
||||
put(ecp.charsets(), m);
|
||||
}
|
||||
for (Iterator<CharsetProvider> i = providers(); i.hasNext();) {
|
||||
CharsetProvider cp = i.next();
|
||||
put(cp.charsets(), m);
|
||||
}
|
||||
return Collections.unmodifiableSortedMap(m);
|
||||
}
|
||||
|
||||
private @Stable static Charset defaultCharset;
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright (c) 2011, 2023, Oracle and/or its affiliates. All rights reserved.
|
||||
* Copyright (c) 2011, 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
|
||||
|
@ -116,13 +116,9 @@ class CopyMoveHelper {
|
|||
// attributes of source file
|
||||
BasicFileAttributes sourceAttrs = null;
|
||||
if (sourcePosixView != null) {
|
||||
try {
|
||||
sourceAttrs = Files.readAttributes(source,
|
||||
PosixFileAttributes.class,
|
||||
linkOptions);
|
||||
} catch (SecurityException ignored) {
|
||||
// okay to continue if RuntimePermission("accessUserInformation") not granted
|
||||
}
|
||||
sourceAttrs = Files.readAttributes(source,
|
||||
PosixFileAttributes.class,
|
||||
linkOptions);
|
||||
}
|
||||
if (sourceAttrs == null)
|
||||
sourceAttrs = Files.readAttributes(source,
|
||||
|
@ -173,11 +169,7 @@ class CopyMoveHelper {
|
|||
|
||||
if (sourceAttrs instanceof PosixFileAttributes sourcePosixAttrs &&
|
||||
targetView instanceof PosixFileAttributeView targetPosixView) {
|
||||
try {
|
||||
targetPosixView.setPermissions(sourcePosixAttrs.permissions());
|
||||
} catch (SecurityException ignored) {
|
||||
// okay to continue if RuntimePermission("accessUserInformation") not granted
|
||||
}
|
||||
targetPosixView.setPermissions(sourcePosixAttrs.permissions());
|
||||
}
|
||||
} catch (Throwable x) {
|
||||
// rollback
|
||||
|
|
|
@ -25,12 +25,10 @@
|
|||
|
||||
package java.nio.file;
|
||||
|
||||
import java.nio.file.spi.FileSystemProvider;
|
||||
import java.net.URI;
|
||||
import java.io.IOException;
|
||||
import java.security.AccessController;
|
||||
import java.security.PrivilegedAction;
|
||||
import java.lang.reflect.Constructor;
|
||||
import java.net.URI;
|
||||
import java.nio.file.spi.FileSystemProvider;
|
||||
import java.util.Collections;
|
||||
import java.util.Map;
|
||||
import java.util.ServiceConfigurationError;
|
||||
|
@ -96,13 +94,7 @@ public final class FileSystems {
|
|||
// returns default file system
|
||||
private static FileSystem defaultFileSystem() {
|
||||
// load default provider
|
||||
@SuppressWarnings("removal")
|
||||
FileSystemProvider provider = AccessController
|
||||
.doPrivileged(new PrivilegedAction<>() {
|
||||
public FileSystemProvider run() {
|
||||
return getDefaultProvider();
|
||||
}
|
||||
});
|
||||
FileSystemProvider provider = getDefaultProvider();
|
||||
|
||||
// return file system
|
||||
return provider.getFileSystem(URI.create("file:///"));
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright (c) 2013, 2023, Oracle and/or its affiliates. All rights reserved.
|
||||
* Copyright (c) 2014, 2023, 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
|
||||
|
@ -58,8 +58,6 @@ class FileTreeIterator implements Iterator<Event>, Closeable {
|
|||
* if {@code maxDepth} is negative
|
||||
* @throws IOException
|
||||
* if an I/O errors occurs opening the starting file
|
||||
* @throws SecurityException
|
||||
* if the security manager denies access to the starting file
|
||||
* @throws NullPointerException
|
||||
* if {@code start} or {@code options} is {@code null} or
|
||||
* the options array contains a {@code null} element
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright (c) 2007, 2023, Oracle and/or its affiliates. All rights reserved.
|
||||
* Copyright (c) 2007, 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
|
||||
|
@ -198,16 +198,12 @@ class FileTreeWalker implements Closeable {
|
|||
* the walk is following sym links is not. The {@code canUseCached}
|
||||
* argument determines whether this method can use cached attributes.
|
||||
*/
|
||||
@SuppressWarnings("removal")
|
||||
private BasicFileAttributes getAttributes(Path file, boolean canUseCached)
|
||||
throws IOException
|
||||
{
|
||||
// if attributes are cached then use them if possible
|
||||
if (canUseCached &&
|
||||
(file instanceof BasicFileAttributesHolder) &&
|
||||
(System.getSecurityManager() == null))
|
||||
{
|
||||
BasicFileAttributes cached = ((BasicFileAttributesHolder)file).get();
|
||||
if (canUseCached && (file instanceof BasicFileAttributesHolder bfah)) {
|
||||
BasicFileAttributes cached = bfah.get();
|
||||
if (cached != null && (!followLinks || !cached.isSymbolicLink())) {
|
||||
return cached;
|
||||
}
|
||||
|
@ -250,7 +246,7 @@ class FileTreeWalker implements Closeable {
|
|||
// cycle detected
|
||||
return true;
|
||||
}
|
||||
} catch (IOException | SecurityException x) {
|
||||
} catch (IOException e) {
|
||||
// ignore
|
||||
}
|
||||
}
|
||||
|
@ -262,25 +258,16 @@ class FileTreeWalker implements Closeable {
|
|||
* Visits the given file, returning the {@code Event} corresponding to that
|
||||
* visit.
|
||||
*
|
||||
* The {@code ignoreSecurityException} parameter determines whether
|
||||
* any SecurityException should be ignored or not. If a SecurityException
|
||||
* is thrown, and is ignored, then this method returns {@code null} to
|
||||
* mean that there is no event corresponding to a visit to the file.
|
||||
*
|
||||
* The {@code canUseCached} parameter determines whether cached attributes
|
||||
* for the file can be used or not.
|
||||
*/
|
||||
private Event visit(Path entry, boolean ignoreSecurityException, boolean canUseCached) {
|
||||
private Event visit(Path entry, boolean canUseCached) {
|
||||
// need the file attributes
|
||||
BasicFileAttributes attrs;
|
||||
try {
|
||||
attrs = getAttributes(entry, canUseCached);
|
||||
} catch (IOException ioe) {
|
||||
return new Event(EventType.ENTRY, entry, ioe);
|
||||
} catch (SecurityException se) {
|
||||
if (ignoreSecurityException)
|
||||
return null;
|
||||
throw se;
|
||||
}
|
||||
|
||||
// at maximum depth or file is not a directory
|
||||
|
@ -301,10 +288,6 @@ class FileTreeWalker implements Closeable {
|
|||
stream = Files.newDirectoryStream(entry);
|
||||
} catch (IOException ioe) {
|
||||
return new Event(EventType.ENTRY, entry, ioe);
|
||||
} catch (SecurityException se) {
|
||||
if (ignoreSecurityException)
|
||||
return null;
|
||||
throw se;
|
||||
}
|
||||
|
||||
// push a directory node to the stack and return an event
|
||||
|
@ -321,7 +304,6 @@ class FileTreeWalker implements Closeable {
|
|||
throw new IllegalStateException("Closed");
|
||||
|
||||
Event ev = visit(file,
|
||||
false, // ignoreSecurityException
|
||||
false); // canUseCached
|
||||
assert ev != null;
|
||||
return ev;
|
||||
|
@ -372,7 +354,6 @@ class FileTreeWalker implements Closeable {
|
|||
|
||||
// visit the entry
|
||||
ev = visit(entry,
|
||||
true, // ignoreSecurityException
|
||||
true); // canUseCached
|
||||
|
||||
} while (ev == null);
|
||||
|
|
|
@ -58,8 +58,6 @@ import java.nio.file.attribute.PosixFilePermission;
|
|||
import java.nio.file.attribute.UserPrincipal;
|
||||
import java.nio.file.spi.FileSystemProvider;
|
||||
import java.nio.file.spi.FileTypeDetector;
|
||||
import java.security.AccessController;
|
||||
import java.security.PrivilegedAction;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
|
@ -696,14 +694,8 @@ public final class Files {
|
|||
} catch (IOException x) {
|
||||
// parent may not exist or other reason
|
||||
}
|
||||
SecurityException se = null;
|
||||
Path absDir = dir;
|
||||
try {
|
||||
absDir = dir.toAbsolutePath();
|
||||
} catch (SecurityException x) {
|
||||
// don't have permission to get absolute path
|
||||
se = x;
|
||||
}
|
||||
Path absDir = dir.toAbsolutePath();
|
||||
|
||||
// find a descendant that exists
|
||||
Path parent = absDir.getParent();
|
||||
while (parent != null) {
|
||||
|
@ -717,12 +709,8 @@ public final class Files {
|
|||
}
|
||||
if (parent == null) {
|
||||
// unable to find existing parent
|
||||
if (se == null) {
|
||||
throw new FileSystemException(absDir.toString(), null,
|
||||
"Unable to determine if root directory exists");
|
||||
} else {
|
||||
throw se;
|
||||
}
|
||||
throw new FileSystemException(absDir.toString(), null,
|
||||
"Unable to determine if root directory exists");
|
||||
}
|
||||
|
||||
// create directories
|
||||
|
@ -1525,29 +1513,19 @@ public final class Files {
|
|||
loadInstalledDetectors();
|
||||
|
||||
// creates the default file type detector
|
||||
@SuppressWarnings("removal")
|
||||
private static FileTypeDetector createDefaultFileTypeDetector() {
|
||||
return AccessController
|
||||
.doPrivileged(new PrivilegedAction<>() {
|
||||
@Override public FileTypeDetector run() {
|
||||
return sun.nio.fs.DefaultFileTypeDetector.create();
|
||||
}});
|
||||
return sun.nio.fs.DefaultFileTypeDetector.create();
|
||||
}
|
||||
|
||||
// loads all installed file type detectors
|
||||
@SuppressWarnings("removal")
|
||||
private static List<FileTypeDetector> loadInstalledDetectors() {
|
||||
return AccessController
|
||||
.doPrivileged(new PrivilegedAction<>() {
|
||||
@Override public List<FileTypeDetector> run() {
|
||||
List<FileTypeDetector> list = new ArrayList<>();
|
||||
ServiceLoader<FileTypeDetector> loader = ServiceLoader
|
||||
.load(FileTypeDetector.class, ClassLoader.getSystemClassLoader());
|
||||
for (FileTypeDetector detector: loader) {
|
||||
list.add(detector);
|
||||
}
|
||||
return list;
|
||||
}});
|
||||
List<FileTypeDetector> list = new ArrayList<>();
|
||||
ServiceLoader<FileTypeDetector> loader = ServiceLoader
|
||||
.load(FileTypeDetector.class, ClassLoader.getSystemClassLoader());
|
||||
for (FileTypeDetector detector: loader) {
|
||||
list.add(detector);
|
||||
}
|
||||
return list;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -2863,26 +2841,16 @@ public final class Files {
|
|||
}
|
||||
|
||||
// attempt to delete an existing file
|
||||
SecurityException se = null;
|
||||
if (replaceExisting) {
|
||||
try {
|
||||
deleteIfExists(target);
|
||||
} catch (SecurityException x) {
|
||||
se = x;
|
||||
}
|
||||
deleteIfExists(target);
|
||||
}
|
||||
|
||||
// attempt to create target file. If it fails with
|
||||
// FileAlreadyExistsException then it may be because the security
|
||||
// manager prevented us from deleting the file, in which case we just
|
||||
// throw the SecurityException.
|
||||
// attempt to create target file.
|
||||
OutputStream ostream;
|
||||
try {
|
||||
ostream = newOutputStream(target, StandardOpenOption.CREATE_NEW,
|
||||
StandardOpenOption.WRITE);
|
||||
} catch (FileAlreadyExistsException x) {
|
||||
if (se != null)
|
||||
throw se;
|
||||
// someone else won the race and created the file
|
||||
throw x;
|
||||
}
|
||||
|
|
|
@ -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
|
||||
|
@ -117,16 +117,12 @@ class TempFileHelper {
|
|||
}
|
||||
|
||||
// loop generating random names until file or directory can be created
|
||||
@SuppressWarnings("removal")
|
||||
SecurityManager sm = System.getSecurityManager();
|
||||
for (;;) {
|
||||
Path f;
|
||||
try {
|
||||
f = generatePath(prefix, suffix, dir);
|
||||
} catch (InvalidPathException e) {
|
||||
// don't reveal temporary directory location
|
||||
if (sm != null)
|
||||
throw new IllegalArgumentException("Invalid prefix or suffix");
|
||||
throw e;
|
||||
}
|
||||
try {
|
||||
|
@ -135,11 +131,6 @@ class TempFileHelper {
|
|||
} else {
|
||||
return Files.createFile(f, attrs);
|
||||
}
|
||||
} catch (SecurityException e) {
|
||||
// don't reveal temporary directory location
|
||||
if (dir == tmpdir && sm != null)
|
||||
throw new SecurityException("Unable to create temporary file or directory");
|
||||
throw e;
|
||||
} catch (FileAlreadyExistsException e) {
|
||||
// ignore
|
||||
}
|
||||
|
|
|
@ -45,7 +45,6 @@ import java.nio.file.FileSystemNotFoundException;
|
|||
import java.nio.file.FileSystems;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.LinkOption;
|
||||
import java.nio.file.LinkPermission;
|
||||
import java.nio.file.NoSuchFileException;
|
||||
import java.nio.file.NotDirectoryException;
|
||||
import java.nio.file.NotLinkException;
|
||||
|
@ -68,8 +67,6 @@ import java.util.ServiceConfigurationError;
|
|||
import java.util.ServiceLoader;
|
||||
import java.util.Set;
|
||||
import java.util.concurrent.ExecutorService;
|
||||
import java.security.AccessController;
|
||||
import java.security.PrivilegedAction;
|
||||
|
||||
import sun.nio.ch.FileChannelImpl;
|
||||
|
||||
|
@ -185,13 +182,7 @@ public abstract class FileSystemProvider {
|
|||
}
|
||||
loadingProviders = true;
|
||||
|
||||
@SuppressWarnings("removal")
|
||||
List<FileSystemProvider> list = AccessController
|
||||
.doPrivileged(new PrivilegedAction<>() {
|
||||
@Override
|
||||
public List<FileSystemProvider> run() {
|
||||
return loadInstalledProviders();
|
||||
}});
|
||||
List<FileSystemProvider> list = loadInstalledProviders();
|
||||
|
||||
// insert the default provider at the start of the list
|
||||
list.add(0, defaultProvider);
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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(']');
|
||||
|
|
|
@ -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=");
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -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 {
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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();
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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")
|
||||
|
|
|
@ -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();
|
||||
|
|
|
@ -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,
|
||||
|
|
|
@ -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 {
|
||||
|
|
|
@ -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();
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -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";
|
||||
|
|
|
@ -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();
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue