8344064: Remove doPrivileged calls from print/imageio/media classes in the java.desktop module

Reviewed-by: kizune
This commit is contained in:
Phil Race 2024-11-20 18:45:49 +00:00
parent 27fda0ea1f
commit 22a39dc858
19 changed files with 102 additions and 289 deletions

View File

@ -48,8 +48,6 @@ import java.awt.image.WritableRaster;
import java.io.ByteArrayInputStream; import java.io.ByteArrayInputStream;
import java.io.IOException; import java.io.IOException;
import java.nio.ByteOrder; import java.nio.ByteOrder;
import java.security.AccessController;
import java.security.PrivilegedAction;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Iterator; import java.util.Iterator;
import java.util.List; import java.util.List;
@ -2039,17 +2037,9 @@ public class BMPImageReader extends ImageReader implements BMPConstants {
private static Boolean isLinkedProfileAllowed = null; private static Boolean isLinkedProfileAllowed = null;
@SuppressWarnings("removal")
private static boolean isLinkedProfileAllowed() { private static boolean isLinkedProfileAllowed() {
if (isLinkedProfileAllowed == null) { if (isLinkedProfileAllowed == null) {
PrivilegedAction<Boolean> a = new PrivilegedAction<Boolean>() { isLinkedProfileAllowed = Boolean.getBoolean("sun.imageio.bmp.enableLinkedProfiles");
@Override
public Boolean run() {
return Boolean.
getBoolean("sun.imageio.bmp.enableLinkedProfiles");
}
};
isLinkedProfileAllowed = AccessController.doPrivileged(a);
} }
return isLinkedProfileAllowed; return isLinkedProfileAllowed;
} }

View File

@ -90,16 +90,9 @@ public class JPEGImageReader extends ImageReader {
initStatic(); initStatic();
} }
@SuppressWarnings({"removal", "restricted"}) @SuppressWarnings("restricted")
private static void initStatic() { private static void initStatic() {
java.security.AccessController.doPrivileged( System.loadLibrary("javajpeg");
new java.security.PrivilegedAction<Void>() {
@Override
public Void run() {
System.loadLibrary("javajpeg");
return null;
}
});
initReaderIDs(ImageInputStream.class, initReaderIDs(ImageInputStream.class,
JPEGQTable.class, JPEGQTable.class,
JPEGHuffmanTable.class); JPEGHuffmanTable.class);

View File

@ -175,16 +175,9 @@ public class JPEGImageWriter extends ImageWriter {
initStatic(); initStatic();
} }
@SuppressWarnings({"removal", "restricted"}) @SuppressWarnings("restricted")
private static void initStatic() { private static void initStatic() {
java.security.AccessController.doPrivileged( System.loadLibrary("javajpeg");
new java.security.PrivilegedAction<Void>() {
@Override
public Void run() {
System.loadLibrary("javajpeg");
return null;
}
});
initWriterIDs(JPEGQTable.class, initWriterIDs(JPEGQTable.class,
JPEGHuffmanTable.class); JPEGHuffmanTable.class);
} }

View File

@ -28,8 +28,6 @@ package com.sun.imageio.stream;
import sun.awt.util.ThreadGroupUtils; import sun.awt.util.ThreadGroupUtils;
import java.io.IOException; import java.io.IOException;
import java.security.AccessController;
import java.security.PrivilegedAction;
import java.util.Set; import java.util.Set;
import java.util.WeakHashMap; import java.util.WeakHashMap;
import javax.imageio.stream.ImageInputStream; import javax.imageio.stream.ImageInputStream;
@ -86,21 +84,18 @@ public class StreamCloser {
} }
}; };
AccessController.doPrivileged((PrivilegedAction<Object>) () -> { /* The thread must be a member of a thread group
/* The thread must be a member of a thread group * which will not get GCed before VM exit.
* which will not get GCed before VM exit. * Make its parent the top-level thread group.
* Make its parent the top-level thread group. */
*/ ThreadGroup tg = ThreadGroupUtils.getRootThreadGroup();
ThreadGroup tg = ThreadGroupUtils.getRootThreadGroup(); streamCloser = new Thread(tg, streamCloserRunnable,
streamCloser = new Thread(tg, streamCloserRunnable, "StreamCloser", 0, false);
"StreamCloser", 0, false); /* Set context class loader to null in order to avoid
/* Set context class loader to null in order to avoid * keeping a strong reference to an application classloader.
* keeping a strong reference to an application classloader. */
*/ streamCloser.setContextClassLoader(null);
streamCloser.setContextClassLoader(null); Runtime.getRuntime().addShutdownHook(streamCloser);
Runtime.getRuntime().addShutdownHook(streamCloser);
return null;
});
} }
} }
} }

View File

@ -60,8 +60,6 @@ import java.io.InputStreamReader;
import java.io.Reader; import java.io.Reader;
import java.net.MalformedURLException; import java.net.MalformedURLException;
import java.net.URL; import java.net.URL;
import java.security.AccessController;
import java.security.PrivilegedAction;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.HashMap; import java.util.HashMap;
import java.util.Map; import java.util.Map;
@ -506,21 +504,12 @@ class Metacity implements SynthConstants {
private static class Privileged implements PrivilegedAction<Object> { private static class ThemeGetter {
private static int GET_THEME_DIR = 0; private static int GET_THEME_DIR = 0;
private static int GET_USER_THEME = 1; private static int GET_USER_THEME = 1;
private static int GET_IMAGE = 2; private static int GET_IMAGE = 2;
private int type;
private Object arg;
@SuppressWarnings("removal") public Object getThemeItem(int type, Object arg) {
public Object doPrivileged(int type, Object arg) {
this.type = type;
this.arg = arg;
return AccessController.doPrivileged(this);
}
public Object run() {
if (type == GET_THEME_DIR) { if (type == GET_THEME_DIR) {
String sep = File.separator; String sep = File.separator;
String[] dirs = new String[] { String[] dirs = new String[] {
@ -618,11 +607,11 @@ class Metacity implements SynthConstants {
} }
private static URL getThemeDir(String themeName) { private static URL getThemeDir(String themeName) {
return (URL)new Privileged().doPrivileged(Privileged.GET_THEME_DIR, themeName); return (URL)new ThemeGetter().getThemeItem(ThemeGetter.GET_THEME_DIR, themeName);
} }
private static String getUserTheme() { private static String getUserTheme() {
return (String)new Privileged().doPrivileged(Privileged.GET_USER_THEME, null); return (String)new ThemeGetter().getThemeItem(ThemeGetter.GET_USER_THEME, null);
} }
protected void tileImage(Graphics g, Image image, int x0, int y0, int w, int h, float[] alphas) { protected void tileImage(Graphics g, Image image, int x0, int y0, int w, int h, float[] alphas) {
@ -673,7 +662,7 @@ class Metacity implements SynthConstants {
try { try {
@SuppressWarnings("deprecation") @SuppressWarnings("deprecation")
URL url = new URL(themeDir, key); URL url = new URL(themeDir, key);
image = (Image)new Privileged().doPrivileged(Privileged.GET_IMAGE, url); image = (Image)new ThemeGetter().getThemeItem(ThemeGetter.GET_IMAGE, url);
} catch (MalformedURLException ex) { } catch (MalformedURLException ex) {
//log("Bad image url: "+ themeDir + "/" + key); //log("Bad image url: "+ themeDir + "/" + key);
} }
@ -1587,18 +1576,11 @@ class Metacity implements SynthConstants {
documentBuilder = documentBuilder =
DocumentBuilderFactory.newInstance().newDocumentBuilder(); DocumentBuilderFactory.newInstance().newDocumentBuilder();
} }
@SuppressWarnings("removal") InputStream inputStream = null;
InputStream inputStream = try {
AccessController.doPrivileged(new PrivilegedAction<InputStream>() { inputStream = new BufferedInputStream(xmlFile.openStream());
public InputStream run() { } catch (IOException ex) {
try { }
return new BufferedInputStream(xmlFile.openStream());
} catch (IOException ex) {
return null;
}
}
});
Document doc = null; Document doc = null;
if (inputStream != null) { if (inputStream != null) {
doc = documentBuilder.parse(inputStream); doc = documentBuilder.parse(inputStream);

View File

@ -32,7 +32,6 @@ import java.io.InputStream;
import java.io.InputStreamReader; import java.io.InputStreamReader;
import java.net.URL; import java.net.URL;
import java.net.URLClassLoader; import java.net.URLClassLoader;
import java.security.AccessController;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Objects; import java.util.Objects;
@ -55,10 +54,7 @@ public final class JARSoundbankReader extends SoundbankReader {
* {@code true} if jar sound bank is allowed to be loaded default is * {@code true} if jar sound bank is allowed to be loaded default is
* {@code false}. * {@code false}.
*/ */
@SuppressWarnings("removal") private static final boolean JAR_SOUNDBANK_ENABLED = Boolean.getBoolean("jdk.sound.jarsoundbank");
private static final boolean JAR_SOUNDBANK_ENABLED =
AccessController.doPrivileged(
new GetBooleanAction("jdk.sound.jarsoundbank"));
private static boolean isZIP(URL url) { private static boolean isZIP(URL url) {
boolean ok = false; boolean ok = false;

View File

@ -25,8 +25,6 @@
package com.sun.media.sound; package com.sun.media.sound;
import java.security.AccessController;
import java.security.PrivilegedAction;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Collections; import java.util.Collections;
import java.util.List; import java.util.List;
@ -170,9 +168,7 @@ public final class JDK13Services {
return null; return null;
} }
String name = typeClass.getName(); String name = typeClass.getName();
@SuppressWarnings("removal") String value = System.getProperty(name);
String value = AccessController.doPrivileged(
(PrivilegedAction<String>) () -> System.getProperty(name));
if (value == null) { if (value == null) {
value = getProperties().getProperty(name); value = getProperties().getProperty(name);
} }

View File

@ -29,8 +29,6 @@ import java.io.Reader;
import java.nio.file.Files; import java.nio.file.Files;
import java.nio.file.Path; import java.nio.file.Path;
import java.nio.file.Paths; import java.nio.file.Paths;
import java.security.AccessController;
import java.security.PrivilegedAction;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Iterator; import java.util.Iterator;
import java.util.List; import java.util.List;
@ -41,7 +39,7 @@ import javax.sound.sampled.AudioPermission;
/** Managing security in the Java Sound implementation. /** Managing security in the Java Sound implementation.
* This class contains all code that uses and is used by * This class contains all code that uses and is used by
* SecurityManager.doPrivileged(). * SecurityManager
* *
* @author Matthias Pfisterer * @author Matthias Pfisterer
*/ */
@ -74,24 +72,18 @@ final class JSSecurityManager {
* @param properties the properties bundle to store the values of the * @param properties the properties bundle to store the values of the
* properties file * properties file
*/ */
@SuppressWarnings("removal")
static void loadProperties(final Properties properties) { static void loadProperties(final Properties properties) {
final String customFile = AccessController.doPrivileged( final String customFile = System.getProperty("javax.sound.config.file");
(PrivilegedAction<String>) () -> System.getProperty(
"javax.sound.config.file"));
if (customFile != null) { if (customFile != null) {
if (loadPropertiesImpl(properties, customFile)) { if (loadPropertiesImpl(properties, customFile)) {
return; return;
} }
} }
AccessController.doPrivileged((PrivilegedAction<Void>) () -> { final String home = System.getProperty("java.home");
final String home = System.getProperty("java.home"); if (home == null) {
if (home == null) { throw new Error("Can't find java.home ??");
throw new Error("Can't find java.home ??"); }
} loadPropertiesImpl(properties, home, "conf", "sound.properties");
loadPropertiesImpl(properties, home, "conf", "sound.properties");
return null;
});
} }
private static boolean loadPropertiesImpl(final Properties properties, private static boolean loadPropertiesImpl(final Properties properties,
@ -124,32 +116,11 @@ final class JSSecurityManager {
return thread; return thread;
} }
@SuppressWarnings("removal")
static synchronized <T> List<T> getProviders(final Class<T> providerClass) { static synchronized <T> List<T> getProviders(final Class<T> providerClass) {
List<T> p = new ArrayList<>(7); List<T> p = new ArrayList<>(7);
// ServiceLoader creates "lazy" iterator instance, but it ensures that final Iterator<T> ps = ServiceLoader.load(providerClass).iterator();
// next/hasNext run with permissions that are restricted by whatever
// creates the ServiceLoader instance, so it requires to be called from
// privileged section
final PrivilegedAction<Iterator<T>> psAction =
new PrivilegedAction<Iterator<T>>() {
@Override
public Iterator<T> run() {
return ServiceLoader.load(providerClass).iterator();
}
};
final Iterator<T> ps = AccessController.doPrivileged(psAction);
// the iterator's hasNext() method looks through classpath for while (ps.hasNext()) {
// the provider class names, so it requires read permissions
PrivilegedAction<Boolean> hasNextAction = new PrivilegedAction<Boolean>() {
@Override
public Boolean run() {
return ps.hasNext();
}
};
while (AccessController.doPrivileged(hasNextAction)) {
try { try {
// the iterator's next() method creates instances of the // the iterator's next() method creates instances of the
// providers and it should be called in the current security // providers and it should be called in the current security

View File

@ -25,8 +25,6 @@
package com.sun.media.sound; package com.sun.media.sound;
import java.security.AccessController;
import java.security.PrivilegedAction;
import java.util.StringTokenizer; import java.util.StringTokenizer;
/** /**
@ -74,15 +72,12 @@ final class Platform {
/** /**
* Load the native library or libraries. * Load the native library or libraries.
*/ */
@SuppressWarnings({"removal", "restricted"}) @SuppressWarnings("restricted")
private static void loadLibraries() { private static void loadLibraries() {
// load the native library // load the native library
isNativeLibLoaded = true; isNativeLibLoaded = true;
try { try {
AccessController.doPrivileged((PrivilegedAction<Void>) () -> { System.loadLibrary(libName);
System.loadLibrary(libName);
return null;
});
} catch (Throwable t) { } catch (Throwable t) {
if (Printer.err) Printer.err("Couldn't load library "+libName+": "+t.toString()); if (Printer.err) Printer.err("Couldn't load library "+libName+": "+t.toString());
isNativeLibLoaded = false; isNativeLibLoaded = false;

View File

@ -25,7 +25,6 @@
package com.sun.media.sound; package com.sun.media.sound;
import java.security.AccessController;
import sun.security.action.GetPropertyAction; import sun.security.action.GetPropertyAction;
@ -66,9 +65,7 @@ final class Printer {
* Returns {@code true} if the build of the current jdk is "internal". * Returns {@code true} if the build of the current jdk is "internal".
*/ */
private static boolean isBuildInternal() { private static boolean isBuildInternal() {
@SuppressWarnings("removal") String javaVersion = System.getProperty("java.version");
String javaVersion = AccessController.doPrivileged(
new GetPropertyAction("java.version"));
return javaVersion != null && javaVersion.contains("internal"); return javaVersion != null && javaVersion.contains("internal");
} }

View File

@ -36,8 +36,6 @@ import java.io.IOException;
import java.io.InputStream; import java.io.InputStream;
import java.io.OutputStream; import java.io.OutputStream;
import java.lang.ref.WeakReference; import java.lang.ref.WeakReference;
import java.security.AccessController;
import java.security.PrivilegedAction;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Arrays; import java.util.Arrays;
import java.util.HashMap; import java.util.HashMap;
@ -634,15 +632,19 @@ public final class SoftSynthesizer implements AudioSynthesizer,
} }
} }
static interface RunnableAction<T> {
T run();
}
@Override @Override
public Soundbank getDefaultSoundbank() { public Soundbank getDefaultSoundbank() {
synchronized (SoftSynthesizer.class) { synchronized (SoftSynthesizer.class) {
if (defaultSoundBank != null) if (defaultSoundBank != null)
return defaultSoundBank; return defaultSoundBank;
List<PrivilegedAction<InputStream>> actions = new ArrayList<>(); List<RunnableAction<InputStream>> actions = new ArrayList<>();
actions.add(new PrivilegedAction<InputStream>() { actions.add(new RunnableAction<InputStream>() {
@Override @Override
public InputStream run() { public InputStream run() {
File javahome = new File(System.getProperties() File javahome = new File(System.getProperties()
@ -678,7 +680,7 @@ public final class SoftSynthesizer implements AudioSynthesizer,
} }
}); });
actions.add(new PrivilegedAction<InputStream>() { actions.add(new RunnableAction<InputStream>() {
@Override @Override
public InputStream run() { public InputStream run() {
if (OSInfo.getOSType() == OSInfo.OSType.LINUX) { if (OSInfo.getOSType() == OSInfo.OSType.LINUX) {
@ -712,7 +714,7 @@ public final class SoftSynthesizer implements AudioSynthesizer,
} }
}); });
actions.add(new PrivilegedAction<InputStream>() { actions.add(new RunnableAction<InputStream>() {
@Override @Override
public InputStream run() { public InputStream run() {
if (OSInfo.getOSType() == OSInfo.OSType.WINDOWS) { if (OSInfo.getOSType() == OSInfo.OSType.WINDOWS) {
@ -729,7 +731,7 @@ public final class SoftSynthesizer implements AudioSynthesizer,
} }
}); });
actions.add(new PrivilegedAction<InputStream>() { actions.add(new RunnableAction<InputStream>() {
@Override @Override
public InputStream run() { public InputStream run() {
/* /*
@ -749,10 +751,9 @@ public final class SoftSynthesizer implements AudioSynthesizer,
} }
}); });
for (PrivilegedAction<InputStream> action : actions) { for (RunnableAction<InputStream> action : actions) {
try { try {
@SuppressWarnings("removal") InputStream is = action.run();
InputStream is = AccessController.doPrivileged(action);
if(is == null) continue; if(is == null) continue;
Soundbank sbk; Soundbank sbk;
try (is) { try (is) {
@ -778,9 +779,8 @@ public final class SoftSynthesizer implements AudioSynthesizer,
/* /*
* Save generated soundbank to disk for faster future use. * Save generated soundbank to disk for faster future use.
*/ */
@SuppressWarnings("removal") OutputStream out =
OutputStream out = AccessController ((RunnableAction<OutputStream>) () -> {
.doPrivileged((PrivilegedAction<OutputStream>) () -> {
try { try {
File userhome = new File(System File userhome = new File(System
.getProperty("user.home"), ".gervill"); .getProperty("user.home"), ".gervill");
@ -798,7 +798,7 @@ public final class SoftSynthesizer implements AudioSynthesizer,
} catch (final FileNotFoundException ignored) { } catch (final FileNotFoundException ignored) {
} }
return null; return null;
}); }).run();
if (out != null) { if (out != null) {
try (out) { try (out) {
((SF2Soundbank) defaultSoundBank).save(out); ((SF2Soundbank) defaultSoundBank).save(out);
@ -897,28 +897,24 @@ public final class SoftSynthesizer implements AudioSynthesizer,
return info; return info;
} }
@SuppressWarnings("removal")
private Properties getStoredProperties() { private Properties getStoredProperties() {
return AccessController Properties p = new Properties();
.doPrivileged((PrivilegedAction<Properties>) () -> { String notePath = "/com/sun/media/sound/softsynthesizer";
Properties p = new Properties(); try {
String notePath = "/com/sun/media/sound/softsynthesizer"; Preferences prefroot = Preferences.userRoot();
try { if (prefroot.nodeExists(notePath)) {
Preferences prefroot = Preferences.userRoot(); Preferences prefs = prefroot.node(notePath);
if (prefroot.nodeExists(notePath)) { String[] prefs_keys = prefs.keys();
Preferences prefs = prefroot.node(notePath); for (String prefs_key : prefs_keys) {
String[] prefs_keys = prefs.keys(); String val = prefs.get(prefs_key, null);
for (String prefs_key : prefs_keys) { if (val != null) {
String val = prefs.get(prefs_key, null); p.setProperty(prefs_key, val);
if (val != null) {
p.setProperty(prefs_key, val);
}
}
}
} catch (final BackingStoreException ignored) {
} }
return p; }
}); }
} catch (final BackingStoreException ignored) {
}
return p;
} }
@Override @Override

View File

@ -165,10 +165,8 @@ public final class ImageIO {
* Returns the default temporary (cache) directory as defined by the * Returns the default temporary (cache) directory as defined by the
* java.io.tmpdir system property. * java.io.tmpdir system property.
*/ */
@SuppressWarnings("removal")
private static String getTempDir() { private static String getTempDir() {
GetPropertyAction a = new GetPropertyAction("java.io.tmpdir"); return System.getProperty("java.io.tmpdir");
return AccessController.doPrivileged(a);
} }
/** /**

View File

@ -28,8 +28,6 @@ package javax.imageio.metadata;
import org.w3c.dom.Node; import org.w3c.dom.Node;
import java.lang.reflect.Method; import java.lang.reflect.Method;
import java.security.AccessController;
import java.security.PrivilegedAction;
/** /**
* An abstract class to be extended by objects that represent metadata * An abstract class to be extended by objects that represent metadata
@ -398,12 +396,9 @@ public abstract class IIOMetadata {
throw new IllegalArgumentException("Unsupported format name"); throw new IllegalArgumentException("Unsupported format name");
} }
try { try {
final String className = formatClassName;
// Try to load from the module of the IIOMetadata implementation // Try to load from the module of the IIOMetadata implementation
// for this plugin since the IIOMetadataImpl is part of the plugin // for this plugin since the IIOMetadataImpl is part of the plugin
PrivilegedAction<Class<?>> pa = () -> { return getMetadataFormatClass(className); }; Class<?> cls = getMetadataFormatClass(formatClassName);
@SuppressWarnings("removal")
Class<?> cls = AccessController.doPrivileged(pa);
Method meth = cls.getMethod("getInstance"); Method meth = cls.getMethod("getInstance");
return (IIOMetadataFormat) meth.invoke(null); return (IIOMetadataFormat) meth.invoke(null);
} catch (Exception e) { } catch (Exception e) {

View File

@ -25,8 +25,6 @@
package javax.imageio.spi; package javax.imageio.spi;
import java.security.PrivilegedAction;
import java.security.AccessController;
import java.util.Iterator; import java.util.Iterator;
import com.sun.imageio.spi.FileImageInputStreamSpi; import com.sun.imageio.spi.FileImageInputStreamSpi;
import com.sun.imageio.spi.FileImageOutputStreamSpi; import com.sun.imageio.spi.FileImageOutputStreamSpi;
@ -197,30 +195,14 @@ public final class IIORegistry extends ServiceRegistry {
} }
} }
@SuppressWarnings("removal")
private void registerInstalledProviders() { private void registerInstalledProviders() {
/* Iterator<Class<?>> categories = getCategories();
We need to load installed providers while (categories.hasNext()) {
in the privileged mode in order to @SuppressWarnings("unchecked")
be able read corresponding jar files even if Class<IIOServiceProvider> c = (Class<IIOServiceProvider>)categories.next();
file read capability is restricted (like the for (IIOServiceProvider p : ServiceLoader.loadInstalled(c)) {
applet context case). registerServiceProvider(p);
*/ }
PrivilegedAction<Object> doRegistration = }
new PrivilegedAction<Object>() {
public Object run() {
Iterator<Class<?>> categories = getCategories();
while (categories.hasNext()) {
@SuppressWarnings("unchecked")
Class<IIOServiceProvider> c = (Class<IIOServiceProvider>)categories.next();
for (IIOServiceProvider p : ServiceLoader.loadInstalled(c)) {
registerServiceProvider(p);
}
}
return this;
}
};
AccessController.doPrivileged(doRegistration);
} }
} }

View File

@ -26,8 +26,6 @@
package javax.imageio.spi; package javax.imageio.spi;
import java.lang.reflect.Method; import java.lang.reflect.Method;
import java.security.AccessController;
import java.security.PrivilegedAction;
import javax.imageio.metadata.IIOMetadata; import javax.imageio.metadata.IIOMetadata;
import javax.imageio.metadata.IIOMetadataFormat; import javax.imageio.metadata.IIOMetadataFormat;
import javax.imageio.metadata.IIOMetadataFormatImpl; import javax.imageio.metadata.IIOMetadataFormatImpl;
@ -584,10 +582,7 @@ public abstract class ImageReaderWriterSpi extends IIOServiceProvider {
} }
try { try {
// Try to load from the same location as the module of the SPI // Try to load from the same location as the module of the SPI
final String className = formatClassName; Class<?> cls = getMetadataFormatClass(formatClassName);
PrivilegedAction<Class<?>> pa = () -> { return getMetadataFormatClass(className); };
@SuppressWarnings("removal")
Class<?> cls = AccessController.doPrivileged(pa);
Method meth = cls.getMethod("getInstance"); Method meth = cls.getMethod("getInstance");
return (IIOMetadataFormat) meth.invoke(null); return (IIOMetadataFormat) meth.invoke(null);
} catch (Exception e) { } catch (Exception e) {

View File

@ -25,9 +25,6 @@
package javax.imageio.spi; package javax.imageio.spi;
import java.security.AccessControlContext;
import java.security.AccessController;
import java.security.PrivilegedAction;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.HashMap; import java.util.HashMap;
import java.util.Iterator; import java.util.Iterator;
@ -731,8 +728,6 @@ class SubRegistry {
// No way to express heterogeneous map, we want // No way to express heterogeneous map, we want
// Map<Class<T>, T>, where T is ? // Map<Class<T>, T>, where T is ?
final Map<Class<?>, Object> map = new HashMap<>(); final Map<Class<?>, Object> map = new HashMap<>();
@SuppressWarnings("removal")
final Map<Class<?>, AccessControlContext> accMap = new HashMap<>();
public SubRegistry(ServiceRegistry registry, Class<?> category) { public SubRegistry(ServiceRegistry registry, Class<?> category) {
this.registry = registry; this.registry = registry;
@ -748,7 +743,6 @@ class SubRegistry {
deregisterServiceProvider(oprovider); deregisterServiceProvider(oprovider);
} }
map.put(provider.getClass(), provider); map.put(provider.getClass(), provider);
accMap.put(provider.getClass(), AccessController.getContext());
poset.add(provider); poset.add(provider);
if (provider instanceof RegisterableService) { if (provider instanceof RegisterableService) {
RegisterableService rs = (RegisterableService)provider; RegisterableService rs = (RegisterableService)provider;
@ -773,7 +767,6 @@ class SubRegistry {
if (provider == oprovider) { if (provider == oprovider) {
map.remove(provider.getClass()); map.remove(provider.getClass());
accMap.remove(provider.getClass());
poset.remove(provider); poset.remove(provider);
if (provider instanceof RegisterableService) { if (provider instanceof RegisterableService) {
RegisterableService rs = (RegisterableService)provider; RegisterableService rs = (RegisterableService)provider;
@ -815,26 +808,17 @@ class SubRegistry {
return (T)map.get(providerClass); return (T)map.get(providerClass);
} }
@SuppressWarnings("removal")
public synchronized void clear() { public synchronized void clear() {
Iterator<Object> iter = map.values().iterator(); Iterator<Object> iter = map.values().iterator();
while (iter.hasNext()) { while (iter.hasNext()) {
Object provider = iter.next(); Object provider = iter.next();
iter.remove(); iter.remove();
if (provider instanceof RegisterableService) { if (provider instanceof RegisterableService rs) {
RegisterableService rs = (RegisterableService)provider; rs.onDeregistration(registry, category);
AccessControlContext acc = accMap.get(provider.getClass());
if (acc != null || System.getSecurityManager() == null) {
AccessController.doPrivileged((PrivilegedAction<Void>) () -> {
rs.onDeregistration(registry, category);
return null;
}, acc);
}
} }
} }
poset.clear(); poset.clear();
accMap.clear();
} }
@SuppressWarnings("removal") @SuppressWarnings("removal")

View File

@ -410,10 +410,7 @@ public class DocFlavor implements Serializable, Cloneable {
* @spec https://www.rfc-editor.org/info/rfc2278 * @spec https://www.rfc-editor.org/info/rfc2278
* RFC 2278: IANA Charset Registration Procedures * RFC 2278: IANA Charset Registration Procedures
*/ */
@SuppressWarnings("removal") public static final String hostEncoding = System.getProperty("file.encoding");
public static final String hostEncoding =
java.security.AccessController.doPrivileged(
new sun.security.action.GetPropertyAction("file.encoding"));
/** /**
* MIME type. * MIME type.

View File

@ -335,7 +335,6 @@ public abstract class PrintServiceLookup {
* *
* @return all lookup services for this environment * @return all lookup services for this environment
*/ */
@SuppressWarnings("removal")
private static ArrayList<PrintServiceLookup> getAllLookupServices() { private static ArrayList<PrintServiceLookup> getAllLookupServices() {
synchronized (PrintServiceLookup.class) { synchronized (PrintServiceLookup.class) {
ArrayList<PrintServiceLookup> listOfLookupServices = getListOfLookupServices(); ArrayList<PrintServiceLookup> listOfLookupServices = getListOfLookupServices();
@ -344,32 +343,11 @@ public abstract class PrintServiceLookup {
} else { } else {
listOfLookupServices = initListOfLookupServices(); listOfLookupServices = initListOfLookupServices();
} }
try { Iterator<PrintServiceLookup> iterator = ServiceLoader.load(PrintServiceLookup.class).iterator();
java.security.AccessController.doPrivileged( ArrayList<PrintServiceLookup> los = getListOfLookupServices();
new java.security.PrivilegedExceptionAction<Object>() { while (iterator.hasNext()) {
public Object run() { los.add(iterator.next());
Iterator<PrintServiceLookup> iterator =
ServiceLoader.load(PrintServiceLookup.class).
iterator();
ArrayList<PrintServiceLookup> los = getListOfLookupServices();
while (iterator.hasNext()) {
try {
los.add(iterator.next());
} catch (ServiceConfigurationError err) {
/* In the applet case, we continue */
if (System.getSecurityManager() != null) {
err.printStackTrace();
} else {
throw err;
}
}
}
return null;
}
});
} catch (java.security.PrivilegedActionException e) {
} }
return listOfLookupServices; return listOfLookupServices;
} }
} }

View File

@ -183,43 +183,23 @@ public abstract class StreamPrintServiceFactory {
* *
* @return all factories * @return all factories
*/ */
@SuppressWarnings("removal")
private static ArrayList<StreamPrintServiceFactory> getAllFactories() { private static ArrayList<StreamPrintServiceFactory> getAllFactories() {
synchronized (StreamPrintServiceFactory.class) { synchronized (StreamPrintServiceFactory.class) {
ArrayList<StreamPrintServiceFactory> listOfFactories = getListOfFactories(); ArrayList<StreamPrintServiceFactory> listOfFactories = getListOfFactories();
if (listOfFactories != null) { if (listOfFactories != null) {
return listOfFactories; return listOfFactories;
} else { } else {
listOfFactories = initListOfFactories(); listOfFactories = initListOfFactories();
} }
try { Iterator<StreamPrintServiceFactory> iterator =
java.security.AccessController.doPrivileged( ServiceLoader.load(StreamPrintServiceFactory.class).iterator();
new java.security.PrivilegedExceptionAction<Object>() { ArrayList<StreamPrintServiceFactory> lof = getListOfFactories();
public Object run() { while (iterator.hasNext()) {
Iterator<StreamPrintServiceFactory> iterator = lof.add(iterator.next());
ServiceLoader.load }
(StreamPrintServiceFactory.class).iterator(); return listOfFactories;
ArrayList<StreamPrintServiceFactory> lof = getListOfFactories();
while (iterator.hasNext()) {
try {
lof.add(iterator.next());
} catch (ServiceConfigurationError err) {
/* In the applet case, we continue */
if (System.getSecurityManager() != null) {
err.printStackTrace();
} else {
throw err;
}
}
}
return null;
}
});
} catch (java.security.PrivilegedActionException e) {
}
return listOfFactories;
} }
} }