From 22a39dc858a27cecfb0a8a8ef42e2cf5f7444545 Mon Sep 17 00:00:00 2001 From: Phil Race Date: Wed, 20 Nov 2024 18:45:49 +0000 Subject: [PATCH] 8344064: Remove doPrivileged calls from print/imageio/media classes in the java.desktop module Reviewed-by: kizune --- .../imageio/plugins/bmp/BMPImageReader.java | 12 +--- .../imageio/plugins/jpeg/JPEGImageReader.java | 11 +--- .../imageio/plugins/jpeg/JPEGImageWriter.java | 11 +--- .../com/sun/imageio/stream/StreamCloser.java | 29 ++++----- .../com/sun/java/swing/plaf/gtk/Metacity.java | 38 +++-------- .../sun/media/sound/JARSoundbankReader.java | 6 +- .../com/sun/media/sound/JDK13Services.java | 6 +- .../sun/media/sound/JSSecurityManager.java | 47 +++----------- .../classes/com/sun/media/sound/Platform.java | 9 +-- .../classes/com/sun/media/sound/Printer.java | 5 +- .../com/sun/media/sound/SoftSynthesizer.java | 64 +++++++++---------- .../share/classes/javax/imageio/ImageIO.java | 4 +- .../javax/imageio/metadata/IIOMetadata.java | 7 +- .../javax/imageio/spi/IIORegistry.java | 34 +++------- .../imageio/spi/ImageReaderWriterSpi.java | 7 +- .../javax/imageio/spi/ServiceRegistry.java | 20 +----- .../share/classes/javax/print/DocFlavor.java | 5 +- .../javax/print/PrintServiceLookup.java | 30 ++------- .../print/StreamPrintServiceFactory.java | 46 ++++--------- 19 files changed, 102 insertions(+), 289 deletions(-) diff --git a/src/java.desktop/share/classes/com/sun/imageio/plugins/bmp/BMPImageReader.java b/src/java.desktop/share/classes/com/sun/imageio/plugins/bmp/BMPImageReader.java index 9eab27031d4..06af183b37c 100644 --- a/src/java.desktop/share/classes/com/sun/imageio/plugins/bmp/BMPImageReader.java +++ b/src/java.desktop/share/classes/com/sun/imageio/plugins/bmp/BMPImageReader.java @@ -48,8 +48,6 @@ import java.awt.image.WritableRaster; import java.io.ByteArrayInputStream; import java.io.IOException; import java.nio.ByteOrder; -import java.security.AccessController; -import java.security.PrivilegedAction; import java.util.ArrayList; import java.util.Iterator; import java.util.List; @@ -2039,17 +2037,9 @@ public class BMPImageReader extends ImageReader implements BMPConstants { private static Boolean isLinkedProfileAllowed = null; - @SuppressWarnings("removal") private static boolean isLinkedProfileAllowed() { if (isLinkedProfileAllowed == null) { - PrivilegedAction a = new PrivilegedAction() { - @Override - public Boolean run() { - return Boolean. - getBoolean("sun.imageio.bmp.enableLinkedProfiles"); - } - }; - isLinkedProfileAllowed = AccessController.doPrivileged(a); + isLinkedProfileAllowed = Boolean.getBoolean("sun.imageio.bmp.enableLinkedProfiles"); } return isLinkedProfileAllowed; } diff --git a/src/java.desktop/share/classes/com/sun/imageio/plugins/jpeg/JPEGImageReader.java b/src/java.desktop/share/classes/com/sun/imageio/plugins/jpeg/JPEGImageReader.java index c28759058c0..24013fb68ad 100644 --- a/src/java.desktop/share/classes/com/sun/imageio/plugins/jpeg/JPEGImageReader.java +++ b/src/java.desktop/share/classes/com/sun/imageio/plugins/jpeg/JPEGImageReader.java @@ -90,16 +90,9 @@ public class JPEGImageReader extends ImageReader { initStatic(); } - @SuppressWarnings({"removal", "restricted"}) + @SuppressWarnings("restricted") private static void initStatic() { - java.security.AccessController.doPrivileged( - new java.security.PrivilegedAction() { - @Override - public Void run() { - System.loadLibrary("javajpeg"); - return null; - } - }); + System.loadLibrary("javajpeg"); initReaderIDs(ImageInputStream.class, JPEGQTable.class, JPEGHuffmanTable.class); diff --git a/src/java.desktop/share/classes/com/sun/imageio/plugins/jpeg/JPEGImageWriter.java b/src/java.desktop/share/classes/com/sun/imageio/plugins/jpeg/JPEGImageWriter.java index 39189130be3..f263d47f6c9 100644 --- a/src/java.desktop/share/classes/com/sun/imageio/plugins/jpeg/JPEGImageWriter.java +++ b/src/java.desktop/share/classes/com/sun/imageio/plugins/jpeg/JPEGImageWriter.java @@ -175,16 +175,9 @@ public class JPEGImageWriter extends ImageWriter { initStatic(); } - @SuppressWarnings({"removal", "restricted"}) + @SuppressWarnings("restricted") private static void initStatic() { - java.security.AccessController.doPrivileged( - new java.security.PrivilegedAction() { - @Override - public Void run() { - System.loadLibrary("javajpeg"); - return null; - } - }); + System.loadLibrary("javajpeg"); initWriterIDs(JPEGQTable.class, JPEGHuffmanTable.class); } diff --git a/src/java.desktop/share/classes/com/sun/imageio/stream/StreamCloser.java b/src/java.desktop/share/classes/com/sun/imageio/stream/StreamCloser.java index 3dabca71ffb..b40c53ead3d 100644 --- a/src/java.desktop/share/classes/com/sun/imageio/stream/StreamCloser.java +++ b/src/java.desktop/share/classes/com/sun/imageio/stream/StreamCloser.java @@ -28,8 +28,6 @@ package com.sun.imageio.stream; import sun.awt.util.ThreadGroupUtils; import java.io.IOException; -import java.security.AccessController; -import java.security.PrivilegedAction; import java.util.Set; import java.util.WeakHashMap; import javax.imageio.stream.ImageInputStream; @@ -86,21 +84,18 @@ public class StreamCloser { } }; - AccessController.doPrivileged((PrivilegedAction) () -> { - /* The thread must be a member of a thread group - * which will not get GCed before VM exit. - * Make its parent the top-level thread group. - */ - ThreadGroup tg = ThreadGroupUtils.getRootThreadGroup(); - streamCloser = new Thread(tg, streamCloserRunnable, - "StreamCloser", 0, false); - /* Set context class loader to null in order to avoid - * keeping a strong reference to an application classloader. - */ - streamCloser.setContextClassLoader(null); - Runtime.getRuntime().addShutdownHook(streamCloser); - return null; - }); + /* The thread must be a member of a thread group + * which will not get GCed before VM exit. + * Make its parent the top-level thread group. + */ + ThreadGroup tg = ThreadGroupUtils.getRootThreadGroup(); + streamCloser = new Thread(tg, streamCloserRunnable, + "StreamCloser", 0, false); + /* Set context class loader to null in order to avoid + * keeping a strong reference to an application classloader. + */ + streamCloser.setContextClassLoader(null); + Runtime.getRuntime().addShutdownHook(streamCloser); } } } diff --git a/src/java.desktop/share/classes/com/sun/java/swing/plaf/gtk/Metacity.java b/src/java.desktop/share/classes/com/sun/java/swing/plaf/gtk/Metacity.java index 295e474579b..629b107f163 100644 --- a/src/java.desktop/share/classes/com/sun/java/swing/plaf/gtk/Metacity.java +++ b/src/java.desktop/share/classes/com/sun/java/swing/plaf/gtk/Metacity.java @@ -60,8 +60,6 @@ import java.io.InputStreamReader; import java.io.Reader; import java.net.MalformedURLException; import java.net.URL; -import java.security.AccessController; -import java.security.PrivilegedAction; import java.util.ArrayList; import java.util.HashMap; import java.util.Map; @@ -506,21 +504,12 @@ class Metacity implements SynthConstants { - private static class Privileged implements PrivilegedAction { + private static class ThemeGetter { private static int GET_THEME_DIR = 0; private static int GET_USER_THEME = 1; private static int GET_IMAGE = 2; - private int type; - private Object arg; - @SuppressWarnings("removal") - public Object doPrivileged(int type, Object arg) { - this.type = type; - this.arg = arg; - return AccessController.doPrivileged(this); - } - - public Object run() { + public Object getThemeItem(int type, Object arg) { if (type == GET_THEME_DIR) { String sep = File.separator; String[] dirs = new String[] { @@ -618,11 +607,11 @@ class Metacity implements SynthConstants { } 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() { - 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) { @@ -673,7 +662,7 @@ class Metacity implements SynthConstants { try { @SuppressWarnings("deprecation") 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) { //log("Bad image url: "+ themeDir + "/" + key); } @@ -1587,18 +1576,11 @@ class Metacity implements SynthConstants { documentBuilder = DocumentBuilderFactory.newInstance().newDocumentBuilder(); } - @SuppressWarnings("removal") - InputStream inputStream = - AccessController.doPrivileged(new PrivilegedAction() { - public InputStream run() { - try { - return new BufferedInputStream(xmlFile.openStream()); - } catch (IOException ex) { - return null; - } - } - }); - + InputStream inputStream = null; + try { + inputStream = new BufferedInputStream(xmlFile.openStream()); + } catch (IOException ex) { + } Document doc = null; if (inputStream != null) { doc = documentBuilder.parse(inputStream); diff --git a/src/java.desktop/share/classes/com/sun/media/sound/JARSoundbankReader.java b/src/java.desktop/share/classes/com/sun/media/sound/JARSoundbankReader.java index 6447e654f60..4ff72c7040a 100644 --- a/src/java.desktop/share/classes/com/sun/media/sound/JARSoundbankReader.java +++ b/src/java.desktop/share/classes/com/sun/media/sound/JARSoundbankReader.java @@ -32,7 +32,6 @@ import java.io.InputStream; import java.io.InputStreamReader; import java.net.URL; import java.net.URLClassLoader; -import java.security.AccessController; import java.util.ArrayList; 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 false}. */ - @SuppressWarnings("removal") - private static final boolean JAR_SOUNDBANK_ENABLED = - AccessController.doPrivileged( - new GetBooleanAction("jdk.sound.jarsoundbank")); + private static final boolean JAR_SOUNDBANK_ENABLED = Boolean.getBoolean("jdk.sound.jarsoundbank"); private static boolean isZIP(URL url) { boolean ok = false; diff --git a/src/java.desktop/share/classes/com/sun/media/sound/JDK13Services.java b/src/java.desktop/share/classes/com/sun/media/sound/JDK13Services.java index 0d8f34ca225..4ed79db13b5 100644 --- a/src/java.desktop/share/classes/com/sun/media/sound/JDK13Services.java +++ b/src/java.desktop/share/classes/com/sun/media/sound/JDK13Services.java @@ -25,8 +25,6 @@ package com.sun.media.sound; -import java.security.AccessController; -import java.security.PrivilegedAction; import java.util.ArrayList; import java.util.Collections; import java.util.List; @@ -170,9 +168,7 @@ public final class JDK13Services { return null; } String name = typeClass.getName(); - @SuppressWarnings("removal") - String value = AccessController.doPrivileged( - (PrivilegedAction) () -> System.getProperty(name)); + String value = System.getProperty(name); if (value == null) { value = getProperties().getProperty(name); } diff --git a/src/java.desktop/share/classes/com/sun/media/sound/JSSecurityManager.java b/src/java.desktop/share/classes/com/sun/media/sound/JSSecurityManager.java index 51482b24aea..e9b99ac1a10 100644 --- a/src/java.desktop/share/classes/com/sun/media/sound/JSSecurityManager.java +++ b/src/java.desktop/share/classes/com/sun/media/sound/JSSecurityManager.java @@ -29,8 +29,6 @@ import java.io.Reader; import java.nio.file.Files; import java.nio.file.Path; import java.nio.file.Paths; -import java.security.AccessController; -import java.security.PrivilegedAction; import java.util.ArrayList; import java.util.Iterator; import java.util.List; @@ -41,7 +39,7 @@ import javax.sound.sampled.AudioPermission; /** Managing security in the Java Sound implementation. * This class contains all code that uses and is used by - * SecurityManager.doPrivileged(). + * SecurityManager * * @author Matthias Pfisterer */ @@ -74,24 +72,18 @@ final class JSSecurityManager { * @param properties the properties bundle to store the values of the * properties file */ - @SuppressWarnings("removal") static void loadProperties(final Properties properties) { - final String customFile = AccessController.doPrivileged( - (PrivilegedAction) () -> System.getProperty( - "javax.sound.config.file")); + final String customFile = System.getProperty("javax.sound.config.file"); if (customFile != null) { if (loadPropertiesImpl(properties, customFile)) { return; } } - AccessController.doPrivileged((PrivilegedAction) () -> { - final String home = System.getProperty("java.home"); - if (home == null) { - throw new Error("Can't find java.home ??"); - } - loadPropertiesImpl(properties, home, "conf", "sound.properties"); - return null; - }); + final String home = System.getProperty("java.home"); + if (home == null) { + throw new Error("Can't find java.home ??"); + } + loadPropertiesImpl(properties, home, "conf", "sound.properties"); } private static boolean loadPropertiesImpl(final Properties properties, @@ -124,32 +116,11 @@ final class JSSecurityManager { return thread; } - @SuppressWarnings("removal") static synchronized List getProviders(final Class providerClass) { List p = new ArrayList<>(7); - // ServiceLoader creates "lazy" iterator instance, but it ensures that - // 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> psAction = - new PrivilegedAction>() { - @Override - public Iterator run() { - return ServiceLoader.load(providerClass).iterator(); - } - }; - final Iterator ps = AccessController.doPrivileged(psAction); + final Iterator ps = ServiceLoader.load(providerClass).iterator(); - // the iterator's hasNext() method looks through classpath for - // the provider class names, so it requires read permissions - PrivilegedAction hasNextAction = new PrivilegedAction() { - @Override - public Boolean run() { - return ps.hasNext(); - } - }; - - while (AccessController.doPrivileged(hasNextAction)) { + while (ps.hasNext()) { try { // the iterator's next() method creates instances of the // providers and it should be called in the current security diff --git a/src/java.desktop/share/classes/com/sun/media/sound/Platform.java b/src/java.desktop/share/classes/com/sun/media/sound/Platform.java index 727718c6ca9..ded8a6496f5 100644 --- a/src/java.desktop/share/classes/com/sun/media/sound/Platform.java +++ b/src/java.desktop/share/classes/com/sun/media/sound/Platform.java @@ -25,8 +25,6 @@ package com.sun.media.sound; -import java.security.AccessController; -import java.security.PrivilegedAction; import java.util.StringTokenizer; /** @@ -74,15 +72,12 @@ final class Platform { /** * Load the native library or libraries. */ - @SuppressWarnings({"removal", "restricted"}) + @SuppressWarnings("restricted") private static void loadLibraries() { // load the native library isNativeLibLoaded = true; try { - AccessController.doPrivileged((PrivilegedAction) () -> { - System.loadLibrary(libName); - return null; - }); + System.loadLibrary(libName); } catch (Throwable t) { if (Printer.err) Printer.err("Couldn't load library "+libName+": "+t.toString()); isNativeLibLoaded = false; diff --git a/src/java.desktop/share/classes/com/sun/media/sound/Printer.java b/src/java.desktop/share/classes/com/sun/media/sound/Printer.java index c67ca92f574..40e179b1bd8 100644 --- a/src/java.desktop/share/classes/com/sun/media/sound/Printer.java +++ b/src/java.desktop/share/classes/com/sun/media/sound/Printer.java @@ -25,7 +25,6 @@ package com.sun.media.sound; -import java.security.AccessController; import sun.security.action.GetPropertyAction; @@ -66,9 +65,7 @@ final class Printer { * Returns {@code true} if the build of the current jdk is "internal". */ private static boolean isBuildInternal() { - @SuppressWarnings("removal") - String javaVersion = AccessController.doPrivileged( - new GetPropertyAction("java.version")); + String javaVersion = System.getProperty("java.version"); return javaVersion != null && javaVersion.contains("internal"); } diff --git a/src/java.desktop/share/classes/com/sun/media/sound/SoftSynthesizer.java b/src/java.desktop/share/classes/com/sun/media/sound/SoftSynthesizer.java index e951a6a6578..4c33416e470 100644 --- a/src/java.desktop/share/classes/com/sun/media/sound/SoftSynthesizer.java +++ b/src/java.desktop/share/classes/com/sun/media/sound/SoftSynthesizer.java @@ -36,8 +36,6 @@ import java.io.IOException; import java.io.InputStream; import java.io.OutputStream; import java.lang.ref.WeakReference; -import java.security.AccessController; -import java.security.PrivilegedAction; import java.util.ArrayList; import java.util.Arrays; import java.util.HashMap; @@ -634,15 +632,19 @@ public final class SoftSynthesizer implements AudioSynthesizer, } } + static interface RunnableAction { + T run(); + } + @Override public Soundbank getDefaultSoundbank() { synchronized (SoftSynthesizer.class) { if (defaultSoundBank != null) return defaultSoundBank; - List> actions = new ArrayList<>(); + List> actions = new ArrayList<>(); - actions.add(new PrivilegedAction() { + actions.add(new RunnableAction() { @Override public InputStream run() { File javahome = new File(System.getProperties() @@ -678,7 +680,7 @@ public final class SoftSynthesizer implements AudioSynthesizer, } }); - actions.add(new PrivilegedAction() { + actions.add(new RunnableAction() { @Override public InputStream run() { if (OSInfo.getOSType() == OSInfo.OSType.LINUX) { @@ -712,7 +714,7 @@ public final class SoftSynthesizer implements AudioSynthesizer, } }); - actions.add(new PrivilegedAction() { + actions.add(new RunnableAction() { @Override public InputStream run() { if (OSInfo.getOSType() == OSInfo.OSType.WINDOWS) { @@ -729,7 +731,7 @@ public final class SoftSynthesizer implements AudioSynthesizer, } }); - actions.add(new PrivilegedAction() { + actions.add(new RunnableAction() { @Override public InputStream run() { /* @@ -749,10 +751,9 @@ public final class SoftSynthesizer implements AudioSynthesizer, } }); - for (PrivilegedAction action : actions) { + for (RunnableAction action : actions) { try { - @SuppressWarnings("removal") - InputStream is = AccessController.doPrivileged(action); + InputStream is = action.run(); if(is == null) continue; Soundbank sbk; try (is) { @@ -778,9 +779,8 @@ public final class SoftSynthesizer implements AudioSynthesizer, /* * Save generated soundbank to disk for faster future use. */ - @SuppressWarnings("removal") - OutputStream out = AccessController - .doPrivileged((PrivilegedAction) () -> { + OutputStream out = + ((RunnableAction) () -> { try { File userhome = new File(System .getProperty("user.home"), ".gervill"); @@ -798,7 +798,7 @@ public final class SoftSynthesizer implements AudioSynthesizer, } catch (final FileNotFoundException ignored) { } return null; - }); + }).run(); if (out != null) { try (out) { ((SF2Soundbank) defaultSoundBank).save(out); @@ -897,28 +897,24 @@ public final class SoftSynthesizer implements AudioSynthesizer, return info; } - @SuppressWarnings("removal") private Properties getStoredProperties() { - return AccessController - .doPrivileged((PrivilegedAction) () -> { - Properties p = new Properties(); - String notePath = "/com/sun/media/sound/softsynthesizer"; - try { - Preferences prefroot = Preferences.userRoot(); - if (prefroot.nodeExists(notePath)) { - Preferences prefs = prefroot.node(notePath); - String[] prefs_keys = prefs.keys(); - for (String prefs_key : prefs_keys) { - String val = prefs.get(prefs_key, null); - if (val != null) { - p.setProperty(prefs_key, val); - } - } - } - } catch (final BackingStoreException ignored) { + Properties p = new Properties(); + String notePath = "/com/sun/media/sound/softsynthesizer"; + try { + Preferences prefroot = Preferences.userRoot(); + if (prefroot.nodeExists(notePath)) { + Preferences prefs = prefroot.node(notePath); + String[] prefs_keys = prefs.keys(); + for (String prefs_key : prefs_keys) { + String val = prefs.get(prefs_key, null); + if (val != null) { + p.setProperty(prefs_key, val); } - return p; - }); + } + } + } catch (final BackingStoreException ignored) { + } + return p; } @Override diff --git a/src/java.desktop/share/classes/javax/imageio/ImageIO.java b/src/java.desktop/share/classes/javax/imageio/ImageIO.java index b11641c82ca..316a74a22ea 100644 --- a/src/java.desktop/share/classes/javax/imageio/ImageIO.java +++ b/src/java.desktop/share/classes/javax/imageio/ImageIO.java @@ -165,10 +165,8 @@ public final class ImageIO { * Returns the default temporary (cache) directory as defined by the * java.io.tmpdir system property. */ - @SuppressWarnings("removal") private static String getTempDir() { - GetPropertyAction a = new GetPropertyAction("java.io.tmpdir"); - return AccessController.doPrivileged(a); + return System.getProperty("java.io.tmpdir"); } /** diff --git a/src/java.desktop/share/classes/javax/imageio/metadata/IIOMetadata.java b/src/java.desktop/share/classes/javax/imageio/metadata/IIOMetadata.java index 3954f886f47..b94d6a85a02 100644 --- a/src/java.desktop/share/classes/javax/imageio/metadata/IIOMetadata.java +++ b/src/java.desktop/share/classes/javax/imageio/metadata/IIOMetadata.java @@ -28,8 +28,6 @@ package javax.imageio.metadata; import org.w3c.dom.Node; import java.lang.reflect.Method; -import java.security.AccessController; -import java.security.PrivilegedAction; /** * 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"); } try { - final String className = formatClassName; // Try to load from the module of the IIOMetadata implementation // for this plugin since the IIOMetadataImpl is part of the plugin - PrivilegedAction> pa = () -> { return getMetadataFormatClass(className); }; - @SuppressWarnings("removal") - Class cls = AccessController.doPrivileged(pa); + Class cls = getMetadataFormatClass(formatClassName); Method meth = cls.getMethod("getInstance"); return (IIOMetadataFormat) meth.invoke(null); } catch (Exception e) { diff --git a/src/java.desktop/share/classes/javax/imageio/spi/IIORegistry.java b/src/java.desktop/share/classes/javax/imageio/spi/IIORegistry.java index b80e6370293..1ea7146ae4a 100644 --- a/src/java.desktop/share/classes/javax/imageio/spi/IIORegistry.java +++ b/src/java.desktop/share/classes/javax/imageio/spi/IIORegistry.java @@ -25,8 +25,6 @@ package javax.imageio.spi; -import java.security.PrivilegedAction; -import java.security.AccessController; import java.util.Iterator; import com.sun.imageio.spi.FileImageInputStreamSpi; import com.sun.imageio.spi.FileImageOutputStreamSpi; @@ -197,30 +195,14 @@ public final class IIORegistry extends ServiceRegistry { } } - @SuppressWarnings("removal") private void registerInstalledProviders() { - /* - We need to load installed providers - in the privileged mode in order to - be able read corresponding jar files even if - file read capability is restricted (like the - applet context case). - */ - PrivilegedAction doRegistration = - new PrivilegedAction() { - public Object run() { - Iterator> categories = getCategories(); - while (categories.hasNext()) { - @SuppressWarnings("unchecked") - Class c = (Class)categories.next(); - for (IIOServiceProvider p : ServiceLoader.loadInstalled(c)) { - registerServiceProvider(p); - } - } - return this; - } - }; - - AccessController.doPrivileged(doRegistration); + Iterator> categories = getCategories(); + while (categories.hasNext()) { + @SuppressWarnings("unchecked") + Class c = (Class)categories.next(); + for (IIOServiceProvider p : ServiceLoader.loadInstalled(c)) { + registerServiceProvider(p); + } + } } } diff --git a/src/java.desktop/share/classes/javax/imageio/spi/ImageReaderWriterSpi.java b/src/java.desktop/share/classes/javax/imageio/spi/ImageReaderWriterSpi.java index 7abefdd9431..f74415a8a38 100644 --- a/src/java.desktop/share/classes/javax/imageio/spi/ImageReaderWriterSpi.java +++ b/src/java.desktop/share/classes/javax/imageio/spi/ImageReaderWriterSpi.java @@ -26,8 +26,6 @@ package javax.imageio.spi; import java.lang.reflect.Method; -import java.security.AccessController; -import java.security.PrivilegedAction; import javax.imageio.metadata.IIOMetadata; import javax.imageio.metadata.IIOMetadataFormat; import javax.imageio.metadata.IIOMetadataFormatImpl; @@ -584,10 +582,7 @@ public abstract class ImageReaderWriterSpi extends IIOServiceProvider { } try { // Try to load from the same location as the module of the SPI - final String className = formatClassName; - PrivilegedAction> pa = () -> { return getMetadataFormatClass(className); }; - @SuppressWarnings("removal") - Class cls = AccessController.doPrivileged(pa); + Class cls = getMetadataFormatClass(formatClassName); Method meth = cls.getMethod("getInstance"); return (IIOMetadataFormat) meth.invoke(null); } catch (Exception e) { diff --git a/src/java.desktop/share/classes/javax/imageio/spi/ServiceRegistry.java b/src/java.desktop/share/classes/javax/imageio/spi/ServiceRegistry.java index 3e0bc06b361..0ba532b0b83 100644 --- a/src/java.desktop/share/classes/javax/imageio/spi/ServiceRegistry.java +++ b/src/java.desktop/share/classes/javax/imageio/spi/ServiceRegistry.java @@ -25,9 +25,6 @@ package javax.imageio.spi; -import java.security.AccessControlContext; -import java.security.AccessController; -import java.security.PrivilegedAction; import java.util.ArrayList; import java.util.HashMap; import java.util.Iterator; @@ -731,8 +728,6 @@ class SubRegistry { // No way to express heterogeneous map, we want // Map, T>, where T is ? final Map, Object> map = new HashMap<>(); - @SuppressWarnings("removal") - final Map, AccessControlContext> accMap = new HashMap<>(); public SubRegistry(ServiceRegistry registry, Class category) { this.registry = registry; @@ -748,7 +743,6 @@ class SubRegistry { deregisterServiceProvider(oprovider); } map.put(provider.getClass(), provider); - accMap.put(provider.getClass(), AccessController.getContext()); poset.add(provider); if (provider instanceof RegisterableService) { RegisterableService rs = (RegisterableService)provider; @@ -773,7 +767,6 @@ class SubRegistry { if (provider == oprovider) { map.remove(provider.getClass()); - accMap.remove(provider.getClass()); poset.remove(provider); if (provider instanceof RegisterableService) { RegisterableService rs = (RegisterableService)provider; @@ -815,26 +808,17 @@ class SubRegistry { return (T)map.get(providerClass); } - @SuppressWarnings("removal") public synchronized void clear() { Iterator iter = map.values().iterator(); while (iter.hasNext()) { Object provider = iter.next(); iter.remove(); - if (provider instanceof RegisterableService) { - RegisterableService rs = (RegisterableService)provider; - AccessControlContext acc = accMap.get(provider.getClass()); - if (acc != null || System.getSecurityManager() == null) { - AccessController.doPrivileged((PrivilegedAction) () -> { - rs.onDeregistration(registry, category); - return null; - }, acc); - } + if (provider instanceof RegisterableService rs) { + rs.onDeregistration(registry, category); } } poset.clear(); - accMap.clear(); } @SuppressWarnings("removal") diff --git a/src/java.desktop/share/classes/javax/print/DocFlavor.java b/src/java.desktop/share/classes/javax/print/DocFlavor.java index 448cc78d9e1..9db970cc779 100644 --- a/src/java.desktop/share/classes/javax/print/DocFlavor.java +++ b/src/java.desktop/share/classes/javax/print/DocFlavor.java @@ -410,10 +410,7 @@ public class DocFlavor implements Serializable, Cloneable { * @spec https://www.rfc-editor.org/info/rfc2278 * RFC 2278: IANA Charset Registration Procedures */ - @SuppressWarnings("removal") - public static final String hostEncoding = - java.security.AccessController.doPrivileged( - new sun.security.action.GetPropertyAction("file.encoding")); + public static final String hostEncoding = System.getProperty("file.encoding"); /** * MIME type. diff --git a/src/java.desktop/share/classes/javax/print/PrintServiceLookup.java b/src/java.desktop/share/classes/javax/print/PrintServiceLookup.java index 2931a1cbae0..29c7b420f7c 100644 --- a/src/java.desktop/share/classes/javax/print/PrintServiceLookup.java +++ b/src/java.desktop/share/classes/javax/print/PrintServiceLookup.java @@ -335,7 +335,6 @@ public abstract class PrintServiceLookup { * * @return all lookup services for this environment */ - @SuppressWarnings("removal") private static ArrayList getAllLookupServices() { synchronized (PrintServiceLookup.class) { ArrayList listOfLookupServices = getListOfLookupServices(); @@ -344,32 +343,11 @@ public abstract class PrintServiceLookup { } else { listOfLookupServices = initListOfLookupServices(); } - try { - java.security.AccessController.doPrivileged( - new java.security.PrivilegedExceptionAction() { - public Object run() { - Iterator iterator = - ServiceLoader.load(PrintServiceLookup.class). - iterator(); - ArrayList 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) { + Iterator iterator = ServiceLoader.load(PrintServiceLookup.class).iterator(); + ArrayList los = getListOfLookupServices(); + while (iterator.hasNext()) { + los.add(iterator.next()); } - return listOfLookupServices; } } diff --git a/src/java.desktop/share/classes/javax/print/StreamPrintServiceFactory.java b/src/java.desktop/share/classes/javax/print/StreamPrintServiceFactory.java index 29033cb7147..5247d4ef861 100644 --- a/src/java.desktop/share/classes/javax/print/StreamPrintServiceFactory.java +++ b/src/java.desktop/share/classes/javax/print/StreamPrintServiceFactory.java @@ -183,43 +183,23 @@ public abstract class StreamPrintServiceFactory { * * @return all factories */ - @SuppressWarnings("removal") private static ArrayList getAllFactories() { synchronized (StreamPrintServiceFactory.class) { - ArrayList listOfFactories = getListOfFactories(); - if (listOfFactories != null) { - return listOfFactories; - } else { - listOfFactories = initListOfFactories(); - } + ArrayList listOfFactories = getListOfFactories(); + if (listOfFactories != null) { + return listOfFactories; + } else { + listOfFactories = initListOfFactories(); + } - try { - java.security.AccessController.doPrivileged( - new java.security.PrivilegedExceptionAction() { - public Object run() { - Iterator iterator = - ServiceLoader.load - (StreamPrintServiceFactory.class).iterator(); - ArrayList 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; + Iterator iterator = + ServiceLoader.load(StreamPrintServiceFactory.class).iterator(); + ArrayList lof = getListOfFactories(); + while (iterator.hasNext()) { + lof.add(iterator.next()); + } + return listOfFactories; } }