diff --git a/src/java.base/share/classes/java/util/Arrays.java b/src/java.base/share/classes/java/util/Arrays.java index 589c027b2dc..03fdf7a3c99 100644 --- a/src/java.base/share/classes/java/util/Arrays.java +++ b/src/java.base/share/classes/java/util/Arrays.java @@ -985,11 +985,8 @@ public final class Arrays { * circular dependencies. To be removed in a future release. */ static final class LegacyMergeSort { - @SuppressWarnings("removal") private static final boolean userRequested = - java.security.AccessController.doPrivileged( - new sun.security.action.GetBooleanAction( - "java.util.Arrays.useLegacyMergeSort")).booleanValue(); + Boolean.getBoolean("java.util.Arrays.useLegacyMergeSort"); } /** diff --git a/src/java.base/share/classes/java/util/Calendar.java b/src/java.base/share/classes/java/util/Calendar.java index 7ac98c02297..7cf389df42b 100644 --- a/src/java.base/share/classes/java/util/Calendar.java +++ b/src/java.base/share/classes/java/util/Calendar.java @@ -43,12 +43,6 @@ import java.io.ObjectInputStream; import java.io.ObjectOutputStream; import java.io.OptionalDataException; import java.io.Serializable; -import java.security.AccessControlContext; -import java.security.AccessController; -import java.security.PermissionCollection; -import java.security.PrivilegedActionException; -import java.security.PrivilegedExceptionAction; -import java.security.ProtectionDomain; import java.text.DateFormat; import java.text.DateFormatSymbols; import java.time.Instant; @@ -3564,25 +3558,9 @@ public abstract class Calendar implements Serializable, Cloneable, Comparable() { - @Override - public ZoneInfo run() throws Exception { - return (ZoneInfo) input.readObject(); - } - }, - CalendarAccessControlContext.INSTANCE); - } catch (PrivilegedActionException pae) { - Exception e = pae.getException(); + zi = (ZoneInfo) input.readObject(); + } catch (Exception e) { if (!(e instanceof OptionalDataException)) { if (e instanceof RuntimeException) { throw (RuntimeException) e; diff --git a/src/java.base/share/classes/java/util/Currency.java b/src/java.base/share/classes/java/util/Currency.java index 0bc86f3281e..b639855b3bf 100644 --- a/src/java.base/share/classes/java/util/Currency.java +++ b/src/java.base/share/classes/java/util/Currency.java @@ -32,8 +32,6 @@ import java.io.FileReader; import java.io.InputStream; import java.io.IOException; import java.io.Serializable; -import java.security.AccessController; -import java.security.PrivilegedAction; import java.text.ParseException; import java.text.SimpleDateFormat; import java.util.concurrent.ConcurrentHashMap; @@ -213,63 +211,57 @@ public final class Currency implements Serializable { initStatic(); } - @SuppressWarnings("removal") private static void initStatic() { - AccessController.doPrivileged(new PrivilegedAction<>() { - @Override - public Void run() { - try { - try (InputStream in = getClass().getResourceAsStream("/java/util/currency.data")) { - if (in == null) { - throw new InternalError("Currency data not found"); - } - DataInputStream dis = new DataInputStream(new BufferedInputStream(in)); - if (dis.readInt() != MAGIC_NUMBER) { - throw new InternalError("Currency data is possibly corrupted"); - } - formatVersion = dis.readInt(); - if (formatVersion != VALID_FORMAT_VERSION) { - throw new InternalError("Currency data format is incorrect"); - } - dataVersion = dis.readInt(); - mainTable = readIntArray(dis, A_TO_Z * A_TO_Z); - int scCount = dis.readInt(); - specialCasesList = readSpecialCases(dis, scCount); - int ocCount = dis.readInt(); - otherCurrenciesList = readOtherCurrencies(dis, ocCount); - } - } catch (IOException e) { - throw new InternalError(e); - } - // look for the properties file for overrides - String propsFile = System.getProperty("java.util.currency.data"); - if (propsFile == null) { - propsFile = StaticProperty.javaHome() + File.separator + "lib" + - File.separator + "currency.properties"; + try { + try (InputStream in = Currency.class.getResourceAsStream("/java/util/currency.data")) { + if (in == null) { + throw new InternalError("Currency data not found"); } - try { - File propFile = new File(propsFile); - if (propFile.exists()) { - Properties props = new Properties(); - try (FileReader fr = new FileReader(propFile)) { - props.load(fr); - } - Pattern propertiesPattern = - Pattern.compile("([A-Z]{3})\\s*,\\s*(\\d{3})\\s*,\\s*" + - "(\\d+)\\s*,?\\s*(\\d{4}-\\d{2}-\\d{2}T\\d{2}:" + - "\\d{2}:\\d{2})?"); - List currencyEntries - = getValidCurrencyData(props, propertiesPattern); - currencyEntries.forEach(Currency::replaceCurrencyData); - } - } catch (IOException e) { - CurrencyProperty.info("currency.properties is ignored" - + " because of an IOException", e); + DataInputStream dis = new DataInputStream(new BufferedInputStream(in)); + if (dis.readInt() != MAGIC_NUMBER) { + throw new InternalError("Currency data is possibly corrupted"); } - return null; + formatVersion = dis.readInt(); + if (formatVersion != VALID_FORMAT_VERSION) { + throw new InternalError("Currency data format is incorrect"); + } + dataVersion = dis.readInt(); + mainTable = readIntArray(dis, A_TO_Z * A_TO_Z); + int scCount = dis.readInt(); + specialCasesList = readSpecialCases(dis, scCount); + int ocCount = dis.readInt(); + otherCurrenciesList = readOtherCurrencies(dis, ocCount); } - }); + } catch (IOException e) { + throw new InternalError(e); + } + + // look for the properties file for overrides + String propsFile = System.getProperty("java.util.currency.data"); + if (propsFile == null) { + propsFile = StaticProperty.javaHome() + File.separator + "lib" + + File.separator + "currency.properties"; + } + try { + File propFile = new File(propsFile); + if (propFile.exists()) { + Properties props = new Properties(); + try (FileReader fr = new FileReader(propFile)) { + props.load(fr); + } + Pattern propertiesPattern = + Pattern.compile("([A-Z]{3})\\s*,\\s*(\\d{3})\\s*,\\s*" + + "(\\d+)\\s*,?\\s*(\\d{4}-\\d{2}-\\d{2}T\\d{2}:" + + "\\d{2}:\\d{2})?"); + List currencyEntries + = getValidCurrencyData(props, propertiesPattern); + currencyEntries.forEach(Currency::replaceCurrencyData); + } + } catch (IOException e) { + CurrencyProperty.info("currency.properties is ignored" + + " because of an IOException", e); + } } /** diff --git a/src/java.base/share/classes/java/util/Locale.java b/src/java.base/share/classes/java/util/Locale.java index 600b20de639..c055c160367 100644 --- a/src/java.base/share/classes/java/util/Locale.java +++ b/src/java.base/share/classes/java/util/Locale.java @@ -1216,10 +1216,6 @@ public final class Locale implements Cloneable, Serializable { if (newLocale == null) throw new NullPointerException("Can't set default locale to NULL"); - @SuppressWarnings("removal") - SecurityManager sm = System.getSecurityManager(); - if (sm != null) sm.checkPermission(new PropertyPermission - ("user.language", "write")); switch (category) { case DISPLAY: defaultDisplayLocale = newLocale; diff --git a/src/java.base/share/classes/java/util/Properties.java b/src/java.base/share/classes/java/util/Properties.java index 45ca0363660..015cdbc7107 100644 --- a/src/java.base/share/classes/java/util/Properties.java +++ b/src/java.base/share/classes/java/util/Properties.java @@ -949,9 +949,6 @@ public class Properties extends Hashtable { } private static void writeDateComment(BufferedWriter bw) throws IOException { - // value of java.properties.date system property isn't sensitive - // and so doesn't need any security manager checks to make the value accessible - // to the callers String sysPropVal = StaticProperty.javaPropertiesDate(); if (sysPropVal != null && !sysPropVal.isEmpty()) { writeComments(bw, sysPropVal); diff --git a/src/java.base/share/classes/java/util/PropertyResourceBundle.java b/src/java.base/share/classes/java/util/PropertyResourceBundle.java index 02391fa2de2..aba65cbcd88 100644 --- a/src/java.base/share/classes/java/util/PropertyResourceBundle.java +++ b/src/java.base/share/classes/java/util/PropertyResourceBundle.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 1996, 2023, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 1996, 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 @@ -46,7 +46,6 @@ import java.io.IOException; import java.nio.charset.MalformedInputException; import java.nio.charset.UnmappableCharacterException; import sun.nio.cs.ISO_8859_1; -import sun.security.action.GetPropertyAction; import sun.util.PropertyResourceBundleCharset; import sun.util.ResourceBundleEnumeration; @@ -132,9 +131,9 @@ public class PropertyResourceBundle extends ResourceBundle { // Check whether the strict encoding is specified. // The possible encoding is either "ISO-8859-1" or "UTF-8". - private static final String encoding = GetPropertyAction - .privilegedGetProperty("java.util.PropertyResourceBundle.encoding", "") - .toUpperCase(Locale.ROOT); + private static final String encoding = + System.getProperty("java.util.PropertyResourceBundle.encoding", "") + .toUpperCase(Locale.ROOT); /** * Creates a property resource bundle from an {@link java.io.InputStream diff --git a/src/java.base/share/classes/java/util/ResourceBundle.java b/src/java.base/share/classes/java/util/ResourceBundle.java index 83f58b8506f..989cc09f388 100644 --- a/src/java.base/share/classes/java/util/ResourceBundle.java +++ b/src/java.base/share/classes/java/util/ResourceBundle.java @@ -42,7 +42,6 @@ package java.util; import java.io.IOException; import java.io.InputStream; -import java.io.UncheckedIOException; import java.lang.ref.Reference; import java.lang.ref.ReferenceQueue; import java.lang.ref.SoftReference; @@ -53,10 +52,6 @@ import java.lang.reflect.Modifier; import java.net.JarURLConnection; import java.net.URL; import java.net.URLConnection; -import java.security.AccessController; -import java.security.PrivilegedAction; -import java.security.PrivilegedActionException; -import java.security.PrivilegedExceptionAction; import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.ConcurrentMap; import java.util.jar.JarEntry; @@ -70,12 +65,9 @@ import jdk.internal.access.SharedSecrets; import jdk.internal.reflect.CallerSensitive; import jdk.internal.reflect.Reflection; import jdk.internal.util.ReferencedKeyMap; -import sun.security.action.GetPropertyAction; import sun.util.locale.BaseLocale; import sun.util.resources.Bundles; -import static sun.security.util.SecurityConstants.GET_CLASSLOADER_PERMISSION; - /** * @@ -581,10 +573,8 @@ public abstract class ResourceBundle { return locale; } - @SuppressWarnings("removal") private static ClassLoader getLoader(Module module) { - PrivilegedAction pa = module::getClassLoader; - return AccessController.doPrivileged(pa); + return module.getClassLoader(); } /** @@ -1506,15 +1496,12 @@ public abstract class ResourceBundle { } private static class ResourceBundleControlProviderHolder { - private static final PrivilegedAction> pa = - () -> ServiceLoader.load(ResourceBundleControlProvider.class, - ClassLoader.getSystemClassLoader()).stream() - .map(ServiceLoader.Provider::get) - .toList(); - @SuppressWarnings("removal") private static final List CONTROL_PROVIDERS = - AccessController.doPrivileged(pa); + ServiceLoader.load(ResourceBundleControlProvider.class, + ClassLoader.getSystemClassLoader()).stream() + .map(ServiceLoader.Provider::get) + .toList(); private static Control getControl(String baseName) { return CONTROL_PROVIDERS.isEmpty() ? @@ -1594,13 +1581,6 @@ public abstract class ResourceBundle { Control control) { Objects.requireNonNull(module); Module callerModule = getCallerModule(caller); - if (callerModule != module) { - @SuppressWarnings("removal") - SecurityManager sm = System.getSecurityManager(); - if (sm != null) { - sm.checkPermission(GET_CLASSLOADER_PERMISSION); - } - } return getBundleImpl(callerModule, module, baseName, locale, control); } @@ -1885,7 +1865,6 @@ public abstract class ResourceBundle { * Returns the service type of the given baseName that is visible * to the given class loader */ - @SuppressWarnings("removal") private static Class getResourceBundleProviderType(String baseName, ClassLoader loader) { @@ -1900,27 +1879,20 @@ public abstract class ResourceBundle { // Use the class loader of the getBundle caller so that the caller's // visibility of the provider type is checked. - return AccessController.doPrivileged( - new PrivilegedAction<>() { - @Override - public Class run() { - try { - Class c = Class.forName(providerName, false, loader); - if (ResourceBundleProvider.class.isAssignableFrom(c)) { - @SuppressWarnings("unchecked") - Class s = (Class) c; - return s; - } - } catch (ClassNotFoundException e) {} - return null; - } - }); + try { + Class c = Class.forName(providerName, false, loader); + if (ResourceBundleProvider.class.isAssignableFrom(c)) { + @SuppressWarnings("unchecked") + Class s = (Class) c; + return s; + } + } catch (ClassNotFoundException _) {} + return null; } /** * Loads ResourceBundle from service providers. */ - @SuppressWarnings("removal") private static ResourceBundle loadBundleFromProviders(String baseName, Locale locale, ServiceLoader providers, @@ -1928,34 +1900,28 @@ public abstract class ResourceBundle { { if (providers == null) return null; - return AccessController.doPrivileged( - new PrivilegedAction<>() { - public ResourceBundle run() { - for (Iterator itr = providers.iterator(); itr.hasNext(); ) { - try { - ResourceBundleProvider provider = itr.next(); - if (cacheKey != null && cacheKey.callerHasProvider == null - && cacheKey.getModule() == provider.getClass().getModule()) { - cacheKey.callerHasProvider = Boolean.TRUE; - } - ResourceBundle bundle = provider.getBundle(baseName, locale); - trace("provider %s %s locale: %s bundle: %s%n", provider, baseName, locale, bundle); - if (bundle != null) { - return bundle; - } - } catch (ServiceConfigurationError | SecurityException e) { - if (cacheKey != null) { - cacheKey.setCause(e); - } - } - } - if (cacheKey != null && cacheKey.callerHasProvider == null) { - cacheKey.callerHasProvider = Boolean.FALSE; - } - return null; - } - }); - + for (Iterator itr = providers.iterator(); itr.hasNext(); ) { + try { + ResourceBundleProvider provider = itr.next(); + if (cacheKey != null && cacheKey.callerHasProvider == null + && cacheKey.getModule() == provider.getClass().getModule()) { + cacheKey.callerHasProvider = Boolean.TRUE; + } + ResourceBundle bundle = provider.getBundle(baseName, locale); + trace("provider %s %s locale: %s bundle: %s%n", provider, baseName, locale, bundle); + if (bundle != null) { + return bundle; + } + } catch (ServiceConfigurationError e) { + if (cacheKey != null) { + cacheKey.setCause(e); + } + } + } + if (cacheKey != null && cacheKey.callerHasProvider == null) { + cacheKey.callerHasProvider = Boolean.FALSE; + } + return null; } /* @@ -3153,7 +3119,6 @@ public abstract class ResourceBundle { return bundle; } - @SuppressWarnings("removal") private ResourceBundle newBundle0(String bundleName, String format, ClassLoader loader, boolean reload) throws IllegalAccessException, InstantiationException, IOException { @@ -3177,28 +3142,20 @@ public abstract class ResourceBundle { bundleClass.getName() + " in " + m.toString()); } try { - Constructor ctor = AccessController.doPrivileged( - new PrivilegedExceptionAction<>() { - @Override - public Constructor run() throws NoSuchMethodException { - return bundleClass.getDeclaredConstructor(); - } - }); + Constructor ctor = bundleClass.getDeclaredConstructor(); if (!Modifier.isPublic(ctor.getModifiers())) { throw new IllegalAccessException("no-arg constructor in " + bundleClass.getName() + " is not publicly accessible."); } // java.base may not be able to read the bundleClass's module. - PrivilegedAction pa1 = () -> { ctor.setAccessible(true); return null; }; - AccessController.doPrivileged(pa1); + ctor.setAccessible(true); bundle = ctor.newInstance((Object[]) null); } catch (InvocationTargetException e) { uncheckedThrow(e); - } catch (PrivilegedActionException e) { - assert e.getCause() instanceof NoSuchMethodException; + } catch (NoSuchMethodException e) { throw new InstantiationException("public no-arg constructor " + - "does not exist in " + bundleClass.getName()); + "does not exist in " + bundleClass.getName()); } } else { throw new ClassCastException(c.getName() @@ -3212,27 +3169,16 @@ public abstract class ResourceBundle { return bundle; } - final boolean reloadFlag = reload; - InputStream stream = null; - try { - stream = AccessController.doPrivileged( - new PrivilegedExceptionAction<>() { - public InputStream run() throws IOException { - URL url = loader.getResource(resourceName); - if (url == null) return null; + URL url = loader.getResource(resourceName); + if (url == null) return null; - URLConnection connection = url.openConnection(); - if (reloadFlag) { - // Disable caches to get fresh data for - // reloading. - connection.setUseCaches(false); - } - return connection.getInputStream(); - } - }); - } catch (PrivilegedActionException e) { - throw (IOException) e.getCause(); + URLConnection connection = url.openConnection(); + if (reload) { + // Disable caches to get fresh data for + // reloading. + connection.setUseCaches(false); } + InputStream stream = connection.getInputStream(); if (stream != null) { try { bundle = new PropertyResourceBundle(stream); @@ -3563,7 +3509,6 @@ public abstract class ResourceBundle { /** * Returns a new ResourceBundle instance of the given bundleClass */ - @SuppressWarnings("removal") static ResourceBundle newResourceBundle(Class bundleClass) { try { @SuppressWarnings("unchecked") @@ -3573,8 +3518,7 @@ public abstract class ResourceBundle { return null; } // java.base may not be able to read the bundleClass's module. - PrivilegedAction pa = () -> { ctor.setAccessible(true); return null;}; - AccessController.doPrivileged(pa); + ctor.setAccessible(true); try { return ctor.newInstance((Object[]) null); } catch (InvocationTargetException e) { @@ -3602,9 +3546,7 @@ public abstract class ResourceBundle { { String bundleName = Control.INSTANCE.toBundleName(baseName, locale); try { - PrivilegedAction> pa = () -> Class.forName(module, bundleName); - @SuppressWarnings("removal") - Class c = AccessController.doPrivileged(pa, null, GET_CLASSLOADER_PERMISSION); + Class c = Class.forName(module, bundleName); trace("local in %s %s caller %s: %s%n", module, bundleName, callerModule, c); if (c == null) { @@ -3662,56 +3604,46 @@ public abstract class ResourceBundle { { String bundleName = Control.INSTANCE.toBundleName(baseName, locale); - PrivilegedAction pa = () -> { - try { - String resourceName = Control.INSTANCE - .toResourceName0(bundleName, "properties"); - if (resourceName == null) { - return null; - } - trace("local in %s %s caller %s%n", module, resourceName, callerModule); + String resourceName = Control.INSTANCE + .toResourceName0(bundleName, "properties"); + if (resourceName == null) { + return null; + } + trace("local in %s %s caller %s%n", module, resourceName, callerModule); - // if the package is in the given module but not opened - // locate it from the given module first. - String pn = toPackageName(bundleName); - trace(" %s/%s is accessible to %s : %s%n", - module.getName(), pn, callerModule, - isAccessible(callerModule, module, pn)); - if (isAccessible(callerModule, module, pn)) { - InputStream in = module.getResourceAsStream(resourceName); - if (in != null) { - return in; - } - } - ClassLoader loader = module.getClassLoader(); - trace("loader for %s %s caller %s%n", module, resourceName, callerModule); - - try { - if (loader != null) { - return loader.getResourceAsStream(resourceName); - } else { - URL url = BootLoader.findResource(resourceName); - if (url != null) { - return url.openStream(); - } - } - } catch (Exception e) {} - return null; - - } catch (IOException e) { - throw new UncheckedIOException(e); + // if the package is in the given module but not opened + // locate it from the given module first. + String pn = toPackageName(bundleName); + trace(" %s/%s is accessible to %s : %s%n", + module.getName(), pn, callerModule, + isAccessible(callerModule, module, pn)); + if (isAccessible(callerModule, module, pn)) { + InputStream in = module.getResourceAsStream(resourceName); + if (in != null) { + return new PropertyResourceBundle(in); } - }; + } + ClassLoader loader = module.getClassLoader(); + trace("loader for %s %s caller %s%n", module, resourceName, callerModule); - try (@SuppressWarnings("removal") InputStream stream = AccessController.doPrivileged(pa)) { + try { + InputStream stream = null; + if (loader != null) { + stream = loader.getResourceAsStream(resourceName); + } else { + URL url = BootLoader.findResource(resourceName); + if (url != null) { + stream = url.openStream(); + } + } if (stream != null) { return new PropertyResourceBundle(stream); } else { return null; } - } catch (UncheckedIOException e) { - throw e.getCause(); + } catch (Exception e) { + return null; } } @@ -3722,8 +3654,8 @@ public abstract class ResourceBundle { } - private static final boolean TRACE_ON = Boolean.parseBoolean( - GetPropertyAction.privilegedGetProperty("resource.bundle.debug", "false")); + private static final boolean TRACE_ON = Boolean.getBoolean( + System.getProperty("resource.bundle.debug", "false")); private static void trace(String format, Object... params) { if (TRACE_ON) diff --git a/src/java.base/share/classes/java/util/TimeZone.java b/src/java.base/share/classes/java/util/TimeZone.java index f1a2d92b6ba..f0b122418c9 100644 --- a/src/java.base/share/classes/java/util/TimeZone.java +++ b/src/java.base/share/classes/java/util/TimeZone.java @@ -43,7 +43,6 @@ import java.time.ZoneId; import java.time.ZoneOffset; import jdk.internal.util.StaticProperty; -import sun.security.action.GetPropertyAction; import sun.util.calendar.ZoneInfo; import sun.util.calendar.ZoneInfoFile; import sun.util.locale.provider.TimeZoneNameUtility; @@ -683,7 +682,7 @@ public abstract class TimeZone implements Serializable, Cloneable { private static synchronized TimeZone setDefaultZone() { TimeZone tz; // get the time zone ID from the system properties - Properties props = GetPropertyAction.privilegedGetProperties(); + Properties props = System.getProperties(); String zoneID = props.getProperty("user.timezone"); // if the time zone ID is not set (yet), perform the @@ -729,12 +728,6 @@ public abstract class TimeZone implements Serializable, Cloneable { */ public static void setDefault(TimeZone zone) { - @SuppressWarnings("removal") - SecurityManager sm = System.getSecurityManager(); - if (sm != null) { - sm.checkPermission(new PropertyPermission - ("user.timezone", "write")); - } // by saving a defensive clone and returning a clone in getDefault() too, // the defaultTimeZone instance is isolated from user code which makes it // effectively immutable. This is important to avoid races when the diff --git a/src/java.base/share/classes/java/util/Tripwire.java b/src/java.base/share/classes/java/util/Tripwire.java index c807a419619..ec20b956375 100644 --- a/src/java.base/share/classes/java/util/Tripwire.java +++ b/src/java.base/share/classes/java/util/Tripwire.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2012, 2021, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2012, 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,9 +26,6 @@ package java.util; import sun.util.logging.PlatformLogger; -import java.security.AccessController; -import java.security.PrivilegedAction; - /** * Utility class for detecting inadvertent uses of boxing in * {@code java.util} classes. The detection is turned on or off based on @@ -49,9 +46,7 @@ final class Tripwire { private static final String TRIPWIRE_PROPERTY = "org.openjdk.java.util.stream.tripwire"; /** Should debugging checks be enabled? */ - @SuppressWarnings("removal") - static final boolean ENABLED = AccessController.doPrivileged( - (PrivilegedAction) () -> Boolean.getBoolean(TRIPWIRE_PROPERTY)); + static final boolean ENABLED = Boolean.getBoolean(TRIPWIRE_PROPERTY); private Tripwire() { } diff --git a/src/java.base/share/classes/java/util/spi/AbstractResourceBundleProvider.java b/src/java.base/share/classes/java/util/spi/AbstractResourceBundleProvider.java index 6eb35aed691..8db27ec586d 100644 --- a/src/java.base/share/classes/java/util/spi/AbstractResourceBundleProvider.java +++ b/src/java.base/share/classes/java/util/spi/AbstractResourceBundleProvider.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2015, 2021, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2015, 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,12 +32,9 @@ import sun.util.resources.Bundles; import java.io.IOException; import java.io.InputStream; import java.io.UncheckedIOException; -import java.security.AccessController; -import java.security.PrivilegedAction; import java.util.Locale; import java.util.PropertyResourceBundle; import java.util.ResourceBundle; -import static sun.security.util.SecurityConstants.GET_CLASSLOADER_PERMISSION; /** * {@code AbstractResourceBundleProvider} is an abstract class that provides @@ -78,11 +75,10 @@ import static sun.security.util.SecurityConstants.GET_CLASSLOADER_PERMISSION; * return null; * } * }} - * + *

* Refer to {@link ResourceBundleProvider} for details. * - * @see - * Resource Bundles and Named Modules + * @see ResourceBundle##resource-bundle-modules Resource Bundles and Named Modules * @since 9 */ public abstract class AbstractResourceBundleProvider implements ResourceBundleProvider { @@ -222,11 +218,8 @@ public abstract class AbstractResourceBundleProvider implements ResourceBundlePr * Returns the ResourceBundle of .class format if found in the module * of this provider. */ - private static ResourceBundle loadResourceBundle(Module module, String bundleName) - { - PrivilegedAction> pa = () -> Class.forName(module, bundleName); - @SuppressWarnings("removal") - Class c = AccessController.doPrivileged(pa, null, GET_CLASSLOADER_PERMISSION); + private static ResourceBundle loadResourceBundle(Module module, String bundleName) { + Class c = Class.forName(module, bundleName); if (c != null && ResourceBundle.class.isAssignableFrom(c)) { @SuppressWarnings("unchecked") Class bundleClass = (Class) c; @@ -241,28 +234,17 @@ public abstract class AbstractResourceBundleProvider implements ResourceBundlePr */ private static ResourceBundle loadPropertyResourceBundle(Module module, String bundleName) - throws IOException - { + throws IOException { String resourceName = toResourceName(bundleName, "properties"); if (resourceName == null) { return null; } - PrivilegedAction pa = () -> { - try { - return module.getResourceAsStream(resourceName); - } catch (IOException e) { - throw new UncheckedIOException(e); - } - }; - try (@SuppressWarnings("removal") InputStream stream = AccessController.doPrivileged(pa)) { - if (stream != null) { - return new PropertyResourceBundle(stream); - } else { - return null; - } - } catch (UncheckedIOException e) { - throw e.getCause(); + InputStream stream = module.getResourceAsStream(resourceName); + if (stream != null) { + return new PropertyResourceBundle(stream); + } else { + return null; } } diff --git a/src/java.base/share/classes/java/util/spi/LocaleServiceProvider.java b/src/java.base/share/classes/java/util/spi/LocaleServiceProvider.java index 46712e5c80b..6e130872bd4 100644 --- a/src/java.base/share/classes/java/util/spi/LocaleServiceProvider.java +++ b/src/java.base/share/classes/java/util/spi/LocaleServiceProvider.java @@ -222,22 +222,10 @@ import java.util.Locale; */ public abstract class LocaleServiceProvider { - private static Void checkPermission() { - @SuppressWarnings("removal") - SecurityManager sm = System.getSecurityManager(); - if (sm != null) { - sm.checkPermission(new RuntimePermission("localeServiceProvider")); - } - return null; - } - private LocaleServiceProvider(Void ignore) { } - /** * Initializes a new locale service provider. */ - protected LocaleServiceProvider() { - this(checkPermission()); - } + protected LocaleServiceProvider() {} /** * {@return an array of all locales for which this locale service provider diff --git a/src/java.base/share/classes/java/util/spi/ToolProvider.java b/src/java.base/share/classes/java/util/spi/ToolProvider.java index 1a3a710e0be..20909522859 100644 --- a/src/java.base/share/classes/java/util/spi/ToolProvider.java +++ b/src/java.base/share/classes/java/util/spi/ToolProvider.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2016, 2022, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2016, 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 java.util.spi; import java.io.PrintStream; import java.io.PrintWriter; -import java.security.AccessController; -import java.security.PrivilegedAction; import java.util.Objects; import java.util.Optional; import java.util.ServiceLoader; @@ -178,18 +176,14 @@ public interface ToolProvider { * * @throws NullPointerException if {@code name} is {@code null} */ - @SuppressWarnings("removal") static Optional findFirst(String name) { Objects.requireNonNull(name); ClassLoader systemClassLoader = ClassLoader.getSystemClassLoader(); - return AccessController.doPrivileged( - (PrivilegedAction>) () -> { - ServiceLoader sl = - ServiceLoader.load(ToolProvider.class, systemClassLoader); - return StreamSupport.stream(sl.spliterator(), false) - .filter(p -> p.name().equals(name)) - .findFirst(); - }); + + ServiceLoader sl = + ServiceLoader.load(ToolProvider.class, systemClassLoader); + return StreamSupport.stream(sl.spliterator(), false) + .filter(p -> p.name().equals(name)) + .findFirst(); } } - diff --git a/src/java.base/share/classes/java/util/stream/Tripwire.java b/src/java.base/share/classes/java/util/stream/Tripwire.java index 962c7d3e1b0..6aae5e67e50 100644 --- a/src/java.base/share/classes/java/util/stream/Tripwire.java +++ b/src/java.base/share/classes/java/util/stream/Tripwire.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2012, 2021, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2012, 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 @@ -24,9 +24,6 @@ */ package java.util.stream; -import java.security.AccessController; -import java.security.PrivilegedAction; - import sun.util.logging.PlatformLogger; /** @@ -49,9 +46,7 @@ final class Tripwire { private static final String TRIPWIRE_PROPERTY = "org.openjdk.java.util.stream.tripwire"; /** Should debugging checks be enabled? */ - @SuppressWarnings("removal") - static final boolean ENABLED = AccessController.doPrivileged( - (PrivilegedAction) () -> Boolean.getBoolean(TRIPWIRE_PROPERTY)); + static final boolean ENABLED = Boolean.getBoolean(TRIPWIRE_PROPERTY); private Tripwire() { }