Skip to content

Commit 922b12f

Browse files
author
Brian Burkhalter
committed
8344078: Remove security manager dependency in java.nio
Reviewed-by: alanb, rriggs
1 parent 2649406 commit 922b12f

File tree

67 files changed

+285
-1480
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

67 files changed

+285
-1480
lines changed

src/java.base/aix/classes/sun/nio/ch/DefaultSelectorProvider.java

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2015, 2021, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2015, 2024, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* This code is free software; you can redistribute it and/or modify it
@@ -25,20 +25,12 @@
2525

2626
package sun.nio.ch;
2727

28-
import java.security.AccessController;
29-
import java.security.PrivilegedAction;
30-
3128
/**
3229
* Creates this platform's default SelectorProvider
3330
*/
3431

35-
@SuppressWarnings("removal")
3632
public class DefaultSelectorProvider {
37-
private static final SelectorProviderImpl INSTANCE;
38-
static {
39-
PrivilegedAction<SelectorProviderImpl> pa = PollSelectorProvider::new;
40-
INSTANCE = AccessController.doPrivileged(pa);
41-
}
33+
private static final SelectorProviderImpl INSTANCE = new PollSelectorProvider();
4234

4335
/**
4436
* Prevent instantiation.
@@ -51,4 +43,4 @@ private DefaultSelectorProvider() { }
5143
public static SelectorProviderImpl get() {
5244
return INSTANCE;
5345
}
54-
}
46+
}

src/java.base/linux/classes/sun/nio/ch/DefaultSelectorProvider.java

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2015, 2021, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2015, 2024, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* This code is free software; you can redistribute it and/or modify it
@@ -25,20 +25,12 @@
2525

2626
package sun.nio.ch;
2727

28-
import java.security.AccessController;
29-
import java.security.PrivilegedAction;
30-
3128
/**
3229
* Creates this platform's default SelectorProvider
3330
*/
3431

35-
@SuppressWarnings("removal")
3632
public class DefaultSelectorProvider {
37-
private static final SelectorProviderImpl INSTANCE;
38-
static {
39-
PrivilegedAction<SelectorProviderImpl> pa = EPollSelectorProvider::new;
40-
INSTANCE = AccessController.doPrivileged(pa);
41-
}
33+
private static final SelectorProviderImpl INSTANCE = new EPollSelectorProvider();
4234

4335
/**
4436
* Prevent instantiation.

src/java.base/linux/classes/sun/nio/fs/LinuxDosFileAttributeView.java

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2008, 2022, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2008, 2024, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* This code is free software; you can redistribute it and/or modify it
@@ -115,8 +115,6 @@ public Map<String,Object> readAttributes(String[] attributes)
115115

116116
@Override
117117
public DosFileAttributes readAttributes() throws IOException {
118-
file.checkRead();
119-
120118
int fd = -1;
121119
try {
122120
fd = file.openForAttributeAccess(followLinks);
@@ -249,8 +247,6 @@ private int getDosAttribute(int fd) throws UnixException {
249247
* Updates the value of the user.DOSATTRIB extended attribute
250248
*/
251249
private void updateDosAttribute(int flag, boolean enable) throws IOException {
252-
file.checkWrite();
253-
254250
int fd = -1;
255251
try {
256252
fd = file.openForAttributeAccess(followLinks);

src/java.base/macosx/classes/sun/nio/ch/DefaultSelectorProvider.java

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -25,20 +25,12 @@
2525

2626
package sun.nio.ch;
2727

28-
import java.security.AccessController;
29-
import java.security.PrivilegedAction;
30-
3128
/**
3229
* Creates this platform's default SelectorProvider
3330
*/
3431

35-
@SuppressWarnings("removal")
3632
public class DefaultSelectorProvider {
37-
private static final SelectorProviderImpl INSTANCE;
38-
static {
39-
PrivilegedAction<SelectorProviderImpl> pa = KQueueSelectorProvider::new;
40-
INSTANCE = AccessController.doPrivileged(pa);
41-
}
33+
private static final SelectorProviderImpl INSTANCE = new KQueueSelectorProvider();
4234

4335
/**
4436
* Prevent instantiation.

src/java.base/macosx/classes/sun/nio/fs/BsdFileAttributeViews.java

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -50,9 +50,6 @@ private static void setTimes(UnixPath path, FileTime lastModifiedTime,
5050
return;
5151
}
5252

53-
// permission check
54-
path.checkWrite();
55-
5653
// use a file descriptor if possible to avoid a race due to accessing
5754
// a path more than once as the file at that path could change.
5855
// if path is a symlink, then the open should fail with ELOOP and

src/java.base/macosx/classes/sun/nio/fs/BsdFileSystem.java

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2008, 2022, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2008, 2024, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* This code is free software; you can redistribute it and/or modify it
@@ -28,13 +28,11 @@
2828
import java.io.IOException;
2929
import java.nio.file.FileStore;
3030
import java.nio.file.WatchService;
31-
import java.security.AccessController;
3231
import java.util.ArrayList;
3332
import java.util.Collections;
3433
import java.util.HashSet;
3534
import java.util.Set;
3635
import sun.nio.ch.IOStatus;
37-
import sun.security.action.GetPropertyAction;
3836

3937
import static sun.nio.fs.UnixConstants.*;
4038
import static sun.nio.fs.UnixNativeDispatcher.chown;

src/java.base/share/classes/java/nio/channels/spi/AsynchronousChannelProvider.java

Lines changed: 10 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,6 @@
3131
import java.util.ServiceLoader;
3232
import java.util.ServiceConfigurationError;
3333
import java.util.concurrent.*;
34-
import java.security.AccessController;
35-
import java.security.PrivilegedAction;
3634

3735
/**
3836
* Service-provider class for asynchronous channels.
@@ -62,20 +60,15 @@ protected AsynchronousChannelProvider() {
6260
private static class ProviderHolder {
6361
static final AsynchronousChannelProvider provider = load();
6462

65-
@SuppressWarnings("removal")
6663
private static AsynchronousChannelProvider load() {
67-
return AccessController
68-
.doPrivileged(new PrivilegedAction<>() {
69-
public AsynchronousChannelProvider run() {
70-
AsynchronousChannelProvider p;
71-
p = loadProviderFromProperty();
72-
if (p != null)
73-
return p;
74-
p = loadProviderAsService();
75-
if (p != null)
76-
return p;
77-
return sun.nio.ch.DefaultAsynchronousChannelProvider.create();
78-
}});
64+
AsynchronousChannelProvider p;
65+
p = loadProviderFromProperty();
66+
if (p != null)
67+
return p;
68+
p = loadProviderAsService();
69+
if (p != null)
70+
return p;
71+
return sun.nio.ch.DefaultAsynchronousChannelProvider.create();
7972
}
8073

8174
private static AsynchronousChannelProvider loadProviderFromProperty() {
@@ -87,7 +80,7 @@ private static AsynchronousChannelProvider loadProviderFromProperty() {
8780
Object tmp = Class.forName(cn, true,
8881
ClassLoader.getSystemClassLoader()).newInstance();
8982
return (AsynchronousChannelProvider)tmp;
90-
} catch (ClassNotFoundException | SecurityException |
83+
} catch (ClassNotFoundException |
9184
InstantiationException | IllegalAccessException x) {
9285
throw new ServiceConfigurationError(null, x);
9386
}
@@ -98,17 +91,7 @@ private static AsynchronousChannelProvider loadProviderAsService() {
9891
ServiceLoader.load(AsynchronousChannelProvider.class,
9992
ClassLoader.getSystemClassLoader());
10093
Iterator<AsynchronousChannelProvider> i = sl.iterator();
101-
for (;;) {
102-
try {
103-
return (i.hasNext()) ? i.next() : null;
104-
} catch (ServiceConfigurationError sce) {
105-
if (sce.getCause() instanceof SecurityException) {
106-
// Ignore the security exception, try the next provider
107-
continue;
108-
}
109-
throw sce;
110-
}
111-
}
94+
return sl.findFirst().orElse(null);
11295
}
11396
}
11497

src/java.base/share/classes/java/nio/channels/spi/SelectorProvider.java

Lines changed: 8 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,6 @@
3333
import java.nio.channels.Pipe;
3434
import java.nio.channels.ServerSocketChannel;
3535
import java.nio.channels.SocketChannel;
36-
import java.security.AccessController;
37-
import java.security.PrivilegedAction;
3836
import java.util.Iterator;
3937
import java.util.Objects;
4038
import java.util.ServiceLoader;
@@ -81,17 +79,13 @@ protected SelectorProvider() {
8179
private static class Holder {
8280
static final SelectorProvider INSTANCE = provider();
8381

84-
@SuppressWarnings("removal")
8582
static SelectorProvider provider() {
86-
PrivilegedAction<SelectorProvider> pa = () -> {
87-
SelectorProvider sp;
88-
if ((sp = loadProviderFromProperty()) != null)
89-
return sp;
90-
if ((sp = loadProviderAsService()) != null)
91-
return sp;
92-
return sun.nio.ch.DefaultSelectorProvider.get();
93-
};
94-
return AccessController.doPrivileged(pa);
83+
SelectorProvider sp;
84+
if ((sp = loadProviderFromProperty()) != null)
85+
return sp;
86+
if ((sp = loadProviderAsService()) != null)
87+
return sp;
88+
return sun.nio.ch.DefaultSelectorProvider.get();
9589
}
9690

9791
private static SelectorProvider loadProviderFromProperty() {
@@ -105,8 +99,7 @@ private static SelectorProvider loadProviderFromProperty() {
10599
NoSuchMethodException |
106100
IllegalAccessException |
107101
InvocationTargetException |
108-
InstantiationException |
109-
SecurityException x) {
102+
InstantiationException x) {
110103
throw new ServiceConfigurationError(null, x);
111104
}
112105
}
@@ -116,17 +109,7 @@ private static SelectorProvider loadProviderAsService() {
116109
ServiceLoader.load(SelectorProvider.class,
117110
ClassLoader.getSystemClassLoader());
118111
Iterator<SelectorProvider> i = sl.iterator();
119-
for (;;) {
120-
try {
121-
return i.hasNext() ? i.next() : null;
122-
} catch (ServiceConfigurationError sce) {
123-
if (sce.getCause() instanceof SecurityException) {
124-
// Ignore the security exception, try the next provider
125-
continue;
126-
}
127-
throw sce;
128-
}
129-
}
112+
return sl.findFirst().orElse(null);
130113
}
131114
}
132115

0 commit comments

Comments
 (0)