Skip to content

Commit 3326874

Browse files
committed
8344857: Remove calls to SecurityManager and doPrivileged in SocketExceptions and URLJarFile in the sun.net package after JEP 486 integration
Reviewed-by: dfuchs, michaelm
1 parent 48e3b65 commit 3326874

File tree

2 files changed

+26
-50
lines changed

2 files changed

+26
-50
lines changed

src/java.base/share/classes/sun/net/util/SocketExceptions.java

Lines changed: 12 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2018, 2023, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2018, 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
@@ -30,8 +30,6 @@
3030
import java.net.InetSocketAddress;
3131
import java.net.UnixDomainSocketAddress;
3232
import java.net.SocketAddress;
33-
import java.security.AccessController;
34-
import java.security.PrivilegedAction;
3533

3634
import sun.security.util.SecurityProperties;
3735

@@ -83,22 +81,16 @@ private static IOException ofUnixDomain(IOException e, UnixDomainSocketAddress a
8381
// return a new instance of the same type with the given detail
8482
// msg, or if the type doesn't support detail msgs, return given
8583
// instance.
86-
87-
@SuppressWarnings("removal")
88-
private static IOException create(IOException e, String msg) {
89-
return AccessController.doPrivileged(new PrivilegedAction<IOException>() {
90-
public IOException run() {
91-
try {
92-
Class<?> clazz = e.getClass();
93-
Constructor<?> ctor = clazz.getConstructor(String.class);
94-
IOException e1 = (IOException)(ctor.newInstance(msg));
95-
e1.setStackTrace(e.getStackTrace());
96-
return e1;
97-
} catch (Exception e0) {
98-
// Some eg AsynchronousCloseException have no detail msg
99-
return e;
100-
}
101-
}
102-
});
84+
private static IOException create(final IOException e, final String msg) {
85+
try {
86+
Class<?> clazz = e.getClass();
87+
Constructor<?> ctor = clazz.getConstructor(String.class);
88+
IOException e1 = (IOException)(ctor.newInstance(msg));
89+
e1.setStackTrace(e.getStackTrace());
90+
return e1;
91+
} catch (Exception e0) {
92+
// Some eg AsynchronousCloseException have no detail msg
93+
return e;
94+
}
10395
}
10496
}

src/java.base/share/classes/sun/net/www/protocol/jar/URLJarFile.java

Lines changed: 14 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -36,9 +36,6 @@
3636
import java.util.zip.ZipEntry;
3737
import java.security.CodeSigner;
3838
import java.security.cert.Certificate;
39-
import java.security.AccessController;
40-
import java.security.PrivilegedExceptionAction;
41-
import java.security.PrivilegedActionException;
4239
import sun.net.www.ParseUtil;
4340

4441
/* URL jar file is a common JarFile subtype used for JarURLConnection */
@@ -159,39 +156,26 @@ private synchronized boolean isSuperMan() throws IOException {
159156
* Given a URL, retrieves a JAR file, caches it to disk, and creates a
160157
* cached JAR file object.
161158
*/
162-
@SuppressWarnings("removal")
163159
private static JarFile retrieve(final URL url, final URLJarFileCloseController closeController) throws IOException {
164-
JarFile result = null;
165160
Runtime.Version version = "runtime".equals(url.getRef())
166161
? JarFile.runtimeVersion()
167162
: JarFile.baseVersion();
168-
169-
/* get the stream before asserting privileges */
170163
try (final InputStream in = url.openConnection().getInputStream()) {
171-
result = AccessController.doPrivileged(
172-
new PrivilegedExceptionAction<>() {
173-
public JarFile run() throws IOException {
174-
Path tmpFile = Files.createTempFile("jar_cache", null);
175-
try {
176-
Files.copy(in, tmpFile, StandardCopyOption.REPLACE_EXISTING);
177-
JarFile jarFile = new URLJarFile(tmpFile.toFile(), closeController, version);
178-
tmpFile.toFile().deleteOnExit();
179-
return jarFile;
180-
} catch (Throwable thr) {
181-
try {
182-
Files.delete(tmpFile);
183-
} catch (IOException ioe) {
184-
thr.addSuppressed(ioe);
185-
}
186-
throw thr;
187-
}
188-
}
189-
});
190-
} catch (PrivilegedActionException pae) {
191-
throw (IOException) pae.getException();
164+
Path tmpFile = Files.createTempFile("jar_cache", null);
165+
try {
166+
Files.copy(in, tmpFile, StandardCopyOption.REPLACE_EXISTING);
167+
JarFile jarFile = new URLJarFile(tmpFile.toFile(), closeController, version);
168+
tmpFile.toFile().deleteOnExit();
169+
return jarFile;
170+
} catch (Throwable thr) {
171+
try {
172+
Files.delete(tmpFile);
173+
} catch (IOException ioe) {
174+
thr.addSuppressed(ioe);
175+
}
176+
throw thr;
177+
}
192178
}
193-
194-
return result;
195179
}
196180

197181
private class URLJarFileEntry extends JarEntry {

0 commit comments

Comments
 (0)