diff --git a/src/java.desktop/share/classes/java/awt/Component.java b/src/java.desktop/share/classes/java/awt/Component.java index ad0b87fd3fc..a1f8461c802 100644 --- a/src/java.desktop/share/classes/java/awt/Component.java +++ b/src/java.desktop/share/classes/java/awt/Component.java @@ -627,14 +627,10 @@ public abstract class Component implements ImageObserver, MenuContainer, initIDs(); } - @SuppressWarnings("removal") - String s = java.security.AccessController.doPrivileged( - new GetPropertyAction("awt.image.incrementaldraw")); + String s = System.getProperty("awt.image.incrementaldraw"); isInc = (s == null || s.equals("true")); - @SuppressWarnings("removal") - String s2 = java.security.AccessController.doPrivileged( - new GetPropertyAction("awt.image.redrawrate")); + String s2 = System.getProperty("awt.image.redrawrate"); incRate = (s2 != null) ? Integer.parseInt(s2) : 100; } @@ -1431,15 +1427,7 @@ public abstract class Component implements ImageObserver, MenuContainer, throw new HeadlessException(); } - @SuppressWarnings("removal") - PointerInfo pi = java.security.AccessController.doPrivileged( - new java.security.PrivilegedAction() { - public PointerInfo run() { - return MouseInfo.getPointerInfo(); - } - } - ); - + PointerInfo pi = MouseInfo.getPointerInfo(); synchronized (getTreeLock()) { Component inTheSameWindow = findUnderMouseInWindow(pi); if (!isSameOrAncestorOf(inTheSameWindow, true)) { @@ -6253,14 +6241,7 @@ public abstract class Component implements ImageObserver, MenuContainer, } // Need to check non-bootstraps. - @SuppressWarnings("removal") - Boolean enabled = java.security.AccessController.doPrivileged( - new java.security.PrivilegedAction() { - public Boolean run() { - return isCoalesceEventsOverriden(clazz); - } - } - ); + Boolean enabled = isCoalesceEventsOverriden(clazz); coalesceMap.put(clazz, enabled); return enabled; } diff --git a/src/java.desktop/share/classes/java/awt/Container.java b/src/java.desktop/share/classes/java/awt/Container.java index c8289aa7fcc..2eb2c923de0 100644 --- a/src/java.desktop/share/classes/java/awt/Container.java +++ b/src/java.desktop/share/classes/java/awt/Container.java @@ -1576,10 +1576,8 @@ public class Container extends Component { } // Don't lazy-read because every app uses invalidate() - @SuppressWarnings("removal") - private static final boolean isJavaAwtSmartInvalidate - = AccessController.doPrivileged( - new GetBooleanAction("java.awt.smartInvalidate")); + private static final boolean isJavaAwtSmartInvalidate = + Boolean.getBoolean("java.awt.smartInvalidate"); /** * Invalidates the parent of the container unless the container @@ -2632,14 +2630,7 @@ public class Container extends Component { if (GraphicsEnvironment.isHeadless()) { throw new HeadlessException(); } - @SuppressWarnings("removal") - PointerInfo pi = java.security.AccessController.doPrivileged( - new java.security.PrivilegedAction() { - public PointerInfo run() { - return MouseInfo.getPointerInfo(); - } - } - ); + PointerInfo pi = MouseInfo.getPointerInfo(); synchronized (getTreeLock()) { Component inTheSameWindow = findUnderMouseInWindow(pi); if (isSameOrAncestorOf(inTheSameWindow, allowChildren)) { @@ -4738,33 +4729,17 @@ class LightweightDispatcher implements java.io.Serializable, AWTEventListener { * from other heavyweight containers will generate enter/exit * events in this container */ - @SuppressWarnings("removal") private void startListeningForOtherDrags() { //System.out.println("Adding AWTEventListener"); - java.security.AccessController.doPrivileged( - new java.security.PrivilegedAction() { - public Object run() { - nativeContainer.getToolkit().addAWTEventListener( - LightweightDispatcher.this, - AWTEvent.MOUSE_EVENT_MASK | - AWTEvent.MOUSE_MOTION_EVENT_MASK); - return null; - } - } - ); + nativeContainer.getToolkit().addAWTEventListener( + LightweightDispatcher.this, + AWTEvent.MOUSE_EVENT_MASK | + AWTEvent.MOUSE_MOTION_EVENT_MASK); } - @SuppressWarnings("removal") private void stopListeningForOtherDrags() { //System.out.println("Removing AWTEventListener"); - java.security.AccessController.doPrivileged( - new java.security.PrivilegedAction() { - public Object run() { - nativeContainer.getToolkit().removeAWTEventListener(LightweightDispatcher.this); - return null; - } - } - ); + nativeContainer.getToolkit().removeAWTEventListener(LightweightDispatcher.this); } /* diff --git a/src/java.desktop/share/classes/java/awt/Cursor.java b/src/java.desktop/share/classes/java/awt/Cursor.java index cfccf06723b..8a595f61285 100644 --- a/src/java.desktop/share/classes/java/awt/Cursor.java +++ b/src/java.desktop/share/classes/java/awt/Cursor.java @@ -29,8 +29,6 @@ import java.beans.ConstructorProperties; import java.io.InputStream; import java.io.Serial; import java.security.AccessController; -import java.security.PrivilegedAction; -import java.security.PrivilegedExceptionAction; import java.util.Hashtable; import java.util.Properties; import java.util.StringTokenizer; @@ -332,11 +330,7 @@ public class Cursor implements java.io.Serializable { } final Toolkit toolkit = Toolkit.getDefaultToolkit(); final String file = RESOURCE_PREFIX + fileName; - @SuppressWarnings("removal") - final InputStream in = AccessController.doPrivileged( - (PrivilegedAction) () -> { - return Cursor.class.getResourceAsStream(file); - }); + final InputStream in = Cursor.class.getResourceAsStream(file); try (in) { Image image = toolkit.createImage(in.readAllBytes()); cursor = toolkit.createCustomCursor(image, hotPoint, localized); @@ -428,7 +422,6 @@ public class Cursor implements java.io.Serializable { /* * load the cursor.properties file */ - @SuppressWarnings("removal") private static void loadSystemCustomCursorProperties() throws AWTException { synchronized (systemCustomCursors) { if (systemCustomCursorProperties != null) { @@ -437,14 +430,8 @@ public class Cursor implements java.io.Serializable { systemCustomCursorProperties = new Properties(); try { - AccessController.doPrivileged( - (PrivilegedExceptionAction) () -> { - try (InputStream is = Cursor.class - .getResourceAsStream(PROPERTIES_FILE)) { - systemCustomCursorProperties.load(is); - } - return null; - }); + InputStream is = Cursor.class.getResourceAsStream(PROPERTIES_FILE); + systemCustomCursorProperties.load(is); } catch (Exception e) { systemCustomCursorProperties = null; throw new AWTException("Exception: " + e.getClass() + " " + diff --git a/src/java.desktop/share/classes/java/awt/DefaultKeyboardFocusManager.java b/src/java.desktop/share/classes/java/awt/DefaultKeyboardFocusManager.java index e416e791e8d..3c57ec3a8d9 100644 --- a/src/java.desktop/share/classes/java/awt/DefaultKeyboardFocusManager.java +++ b/src/java.desktop/share/classes/java/awt/DefaultKeyboardFocusManager.java @@ -32,8 +32,6 @@ import java.awt.peer.ComponentPeer; import java.awt.peer.LightweightPeer; import java.io.Serial; import java.lang.ref.WeakReference; -import java.security.AccessController; -import java.security.PrivilegedAction; import java.util.Iterator; import java.util.LinkedList; import java.util.ListIterator; @@ -86,21 +84,14 @@ public class DefaultKeyboardFocusManager extends KeyboardFocusManager { initStatic(); } - @SuppressWarnings("removal") private static void initStatic() { AWTAccessor.setDefaultKeyboardFocusManagerAccessor( new AWTAccessor.DefaultKeyboardFocusManagerAccessor() { public void consumeNextKeyTyped(DefaultKeyboardFocusManager dkfm, KeyEvent e) { dkfm.consumeNextKeyTyped(e); - } + } }); - AccessController.doPrivileged(new PrivilegedAction() { - public Object run() { - fxAppThreadIsDispatchThread = - "true".equals(System.getProperty("javafx.embed.singleThread")); - return null; - } - }); + fxAppThreadIsDispatchThread = "true".equals(System.getProperty("javafx.embed.singleThread")); } /** diff --git a/src/java.desktop/share/classes/java/awt/Desktop.java b/src/java.desktop/share/classes/java/awt/Desktop.java index 025889755b8..89a78518873 100644 --- a/src/java.desktop/share/classes/java/awt/Desktop.java +++ b/src/java.desktop/share/classes/java/awt/Desktop.java @@ -42,8 +42,6 @@ import java.io.FilePermission; import java.io.IOException; import java.net.URI; import java.net.URISyntaxException; -import java.security.AccessController; -import java.security.PrivilegedAction; import java.util.Objects; import javax.swing.JMenuBar; @@ -936,11 +934,7 @@ public class Desktop { sm.checkDelete(file.getPath()); } checkActionSupport(Action.MOVE_TO_TRASH); - final File finalFile = file; - AccessController.doPrivileged((PrivilegedAction) () -> { - checkFileValidation(finalFile); - return null; - }); + checkFileValidation(file); return peer.moveToTrash(file); } } diff --git a/src/java.desktop/share/classes/java/awt/Dialog.java b/src/java.desktop/share/classes/java/awt/Dialog.java index a0d22fbb327..03449200478 100644 --- a/src/java.desktop/share/classes/java/awt/Dialog.java +++ b/src/java.desktop/share/classes/java/awt/Dialog.java @@ -34,8 +34,6 @@ import java.io.IOException; import java.io.ObjectInputStream; import java.io.Serial; import java.security.AccessControlException; -import java.security.AccessController; -import java.security.PrivilegedAction; import java.util.Iterator; import java.util.concurrent.atomic.AtomicLong; @@ -1052,9 +1050,7 @@ public class Dialog extends Window { modalityPushed(); try { - @SuppressWarnings("removal") - final EventQueue eventQueue = AccessController.doPrivileged( - (PrivilegedAction) Toolkit.getDefaultToolkit()::getSystemEventQueue); + EventQueue eventQueue = Toolkit.getDefaultToolkit().getSystemEventQueue(); secondaryLoop = eventQueue.createSecondaryLoop(() -> true, modalFilter, 0); if (!secondaryLoop.enter()) { secondaryLoop = null; diff --git a/src/java.desktop/share/classes/java/awt/EventQueue.java b/src/java.desktop/share/classes/java/awt/EventQueue.java index 4dce257f727..57a9a6cf567 100644 --- a/src/java.desktop/share/classes/java/awt/EventQueue.java +++ b/src/java.desktop/share/classes/java/awt/EventQueue.java @@ -32,9 +32,6 @@ import java.awt.peer.ComponentPeer; import java.lang.ref.WeakReference; import java.lang.reflect.InvocationTargetException; -import java.security.AccessController; -import java.security.PrivilegedAction; - import java.util.EmptyStackException; import sun.awt.*; @@ -45,11 +42,6 @@ import java.util.concurrent.locks.Condition; import java.util.concurrent.locks.Lock; import java.util.concurrent.atomic.AtomicInteger; -import java.security.AccessControlContext; - -import jdk.internal.access.SharedSecrets; -import jdk.internal.access.JavaSecurityAccess; - /** * {@code EventQueue} is a platform-independent class * that queues events, both from the underlying peer classes @@ -229,13 +221,8 @@ public class EventQueue { }); } - @SuppressWarnings("removal") private static boolean fxAppThreadIsDispatchThread = - AccessController.doPrivileged(new PrivilegedAction() { - public Boolean run() { - return "true".equals(System.getProperty("javafx.embed.singleThread")); - } - }); + "true".equals(System.getProperty("javafx.embed.singleThread")); /** * Initializes a new instance of {@code EventQueue}. @@ -668,9 +655,6 @@ public class EventQueue { return null; } - private static final JavaSecurityAccess javaSecurityAccess = - SharedSecrets.getJavaSecurityAccess(); - /** * Dispatches an event. The manner in which the event is * dispatched depends upon the type of the event and the @@ -711,59 +695,25 @@ public class EventQueue { */ protected void dispatchEvent(final AWTEvent event) { final Object src = event.getSource(); - final PrivilegedAction action = new PrivilegedAction() { - public Void run() { - // In case fwDispatcher is installed and we're already on the - // dispatch thread (e.g. performing DefaultKeyboardFocusManager.sendMessage), - // dispatch the event straight away. - if (fwDispatcher == null || isDispatchThreadImpl()) { - dispatchEventImpl(event, src); - } else { - fwDispatcher.scheduleDispatch(new Runnable() { - @Override - public void run() { - if (dispatchThread.filterAndCheckEvent(event)) { - dispatchEventImpl(event, src); - } - } - }); - } - return null; - } - }; - - @SuppressWarnings("removal") - final AccessControlContext stack = AccessController.getContext(); - @SuppressWarnings("removal") - final AccessControlContext srcAcc = getAccessControlContextFrom(src); - @SuppressWarnings("removal") - final AccessControlContext eventAcc = event.getAccessControlContext(); - if (srcAcc == null) { - javaSecurityAccess.doIntersectionPrivilege(action, stack, eventAcc); + // In case fwDispatcher is installed and we're already on the + // dispatch thread (e.g. performing DefaultKeyboardFocusManager.sendMessage), + // dispatch the event straight away. + if (fwDispatcher == null || isDispatchThreadImpl()) { + dispatchEventImpl(event, src); } else { - javaSecurityAccess.doIntersectionPrivilege( - new PrivilegedAction() { - public Void run() { - javaSecurityAccess.doIntersectionPrivilege(action, eventAcc); - return null; + fwDispatcher.scheduleDispatch(new Runnable() { + @Override + public void run() { + if (dispatchThread.filterAndCheckEvent(event)) { + dispatchEventImpl(event, src); } - }, stack, srcAcc); + } + }); } } - @SuppressWarnings("removal") - private static AccessControlContext getAccessControlContextFrom(Object src) { - return src instanceof Component ? - ((Component)src).getAccessControlContext() : - src instanceof MenuComponent ? - ((MenuComponent)src).getAccessControlContext() : - src instanceof TrayIcon ? - ((TrayIcon)src).getAccessControlContext() : - null; - } - /** - * Called from dispatchEvent() under a correct AccessControlContext + * Called from dispatchEvent() */ private void dispatchEventImpl(final AWTEvent event, final Object src) { event.isPosted = true; @@ -1113,21 +1063,12 @@ public class EventQueue { pushPopLock.lock(); try { if (dispatchThread == null && !threadGroup.isDestroyed() && !appContext.isDisposed()) { - dispatchThread = AccessController.doPrivileged( - new PrivilegedAction() { - public EventDispatchThread run() { - EventDispatchThread t = - new EventDispatchThread(threadGroup, - name, - EventQueue.this); - t.setContextClassLoader(classLoader); - t.setPriority(Thread.NORM_PRIORITY + 1); - t.setDaemon(false); - AWTAutoShutdown.getInstance().notifyThreadBusy(t); - return t; - } - } - ); + EventDispatchThread t = new EventDispatchThread(threadGroup, name, EventQueue.this); + t.setContextClassLoader(classLoader); + t.setPriority(Thread.NORM_PRIORITY + 1); + t.setDaemon(false); + AWTAutoShutdown.getInstance().notifyThreadBusy(t); + dispatchThread = t; dispatchThread.start(); } } finally { diff --git a/src/java.desktop/share/classes/java/awt/Font.java b/src/java.desktop/share/classes/java/awt/Font.java index ff5c29a2758..3df4632f9d3 100644 --- a/src/java.desktop/share/classes/java/awt/Font.java +++ b/src/java.desktop/share/classes/java/awt/Font.java @@ -44,8 +44,6 @@ import java.io.OutputStream; import java.io.Serial; import java.lang.ref.SoftReference; import java.nio.file.Files; -import java.security.AccessController; -import java.security.PrivilegedExceptionAction; import java.text.AttributedCharacterIterator.Attribute; import java.text.CharacterIterator; import java.util.EventListener; @@ -1095,7 +1093,6 @@ public class Font implements java.io.Serializable } } - @SuppressWarnings("removal") private static Font[] createFont0(int fontFormat, InputStream fontStream, boolean allFonts, CreatedFontTracker tracker) @@ -1107,27 +1104,14 @@ public class Font implements java.io.Serializable } boolean copiedFontData = false; try { - final File tFile = AccessController.doPrivileged( - new PrivilegedExceptionAction() { - public File run() throws IOException { - return Files.createTempFile("+~JF", ".tmp").toFile(); - } - } - ); + final File tFile = Files.createTempFile("+~JF", ".tmp").toFile(); if (tracker != null) { tracker.add(tFile); } int totalSize = 0; try { - final OutputStream outStream = - AccessController.doPrivileged( - new PrivilegedExceptionAction() { - public OutputStream run() throws IOException { - return new FileOutputStream(tFile); - } - } - ); + final OutputStream outStream = new FileOutputStream(tFile); if (tracker != null) { tracker.set(tFile, outStream); } @@ -1181,14 +1165,7 @@ public class Font implements java.io.Serializable if (tracker != null) { tracker.subBytes(totalSize); } - AccessController.doPrivileged( - new PrivilegedExceptionAction() { - public Void run() { - tFile.delete(); - return null; - } - } - ); + tFile.delete(); } } } catch (Throwable t) { diff --git a/src/java.desktop/share/classes/java/awt/GraphicsEnvironment.java b/src/java.desktop/share/classes/java/awt/GraphicsEnvironment.java index 2e89aa6f672..4936d5d396d 100644 --- a/src/java.desktop/share/classes/java/awt/GraphicsEnvironment.java +++ b/src/java.desktop/share/classes/java/awt/GraphicsEnvironment.java @@ -26,8 +26,6 @@ package java.awt; import java.awt.image.BufferedImage; -import java.security.AccessController; -import java.security.PrivilegedAction; import java.util.Locale; import sun.awt.PlatformGraphicsInfo; @@ -137,20 +135,16 @@ public abstract class GraphicsEnvironment { * @return the value of the property "java.awt.headless" * @since 1.4 */ - @SuppressWarnings("removal") private static boolean getHeadlessProperty() { if (headless == null) { - AccessController.doPrivileged((PrivilegedAction) () -> { - String nm = System.getProperty("java.awt.headless"); + String nm = System.getProperty("java.awt.headless"); - if (nm == null) { - headless = defaultHeadless = - PlatformGraphicsInfo.getDefaultHeadlessProperty(); - } else { - headless = Boolean.valueOf(nm); - } - return null; - }); + if (nm == null) { + headless = defaultHeadless = + PlatformGraphicsInfo.getDefaultHeadlessProperty(); + } else { + headless = Boolean.valueOf(nm); + } } return headless; } diff --git a/src/java.desktop/share/classes/java/awt/KeyboardFocusManager.java b/src/java.desktop/share/classes/java/awt/KeyboardFocusManager.java index 0ca86f3433b..eb623213a77 100644 --- a/src/java.desktop/share/classes/java/awt/KeyboardFocusManager.java +++ b/src/java.desktop/share/classes/java/awt/KeyboardFocusManager.java @@ -40,9 +40,6 @@ import java.beans.VetoableChangeSupport; import java.lang.ref.WeakReference; -import java.security.AccessController; -import java.security.PrivilegedAction; - import java.util.Collections; import java.util.HashSet; import java.util.Iterator; @@ -601,14 +598,8 @@ public abstract class KeyboardFocusManager peer.clearGlobalFocusOwner(activeWindow); } - @SuppressWarnings("removal") void clearGlobalFocusOwnerPriv() { - AccessController.doPrivileged(new PrivilegedAction() { - public Void run() { - clearGlobalFocusOwner(); - return null; - } - }); + clearGlobalFocusOwner(); } Component getNativeFocusOwner() { @@ -1194,14 +1185,8 @@ public abstract class KeyboardFocusManager newFocusCycleRoot); } - @SuppressWarnings("removal") void setGlobalCurrentFocusCycleRootPriv(final Container newFocusCycleRoot) { - AccessController.doPrivileged(new PrivilegedAction() { - public Void run() { - setGlobalCurrentFocusCycleRoot(newFocusCycleRoot); - return null; - } - }); + setGlobalCurrentFocusCycleRoot(newFocusCycleRoot); } /** diff --git a/src/java.desktop/share/classes/java/awt/SequencedEvent.java b/src/java.desktop/share/classes/java/awt/SequencedEvent.java index 410437a5c9e..a671814a57b 100644 --- a/src/java.desktop/share/classes/java/awt/SequencedEvent.java +++ b/src/java.desktop/share/classes/java/awt/SequencedEvent.java @@ -26,8 +26,6 @@ package java.awt; import java.io.Serial; -import java.security.AccessController; -import java.security.PrivilegedAction; import java.util.LinkedList; import sun.awt.AWTAccessor; @@ -80,13 +78,7 @@ class SequencedEvent extends AWTEvent implements ActiveEvent { return new SequencedEvent(event); } }); - AccessController.doPrivileged(new PrivilegedAction() { - public Object run() { - fxAppThreadIsDispatchThread = - "true".equals(System.getProperty("javafx.embed.singleThread")); - return null; - } - }); + fxAppThreadIsDispatchThread = "true".equals(System.getProperty("javafx.embed.singleThread")); } private static final class SequencedEventsFilter implements EventFilter { diff --git a/src/java.desktop/share/classes/java/awt/SplashScreen.java b/src/java.desktop/share/classes/java/awt/SplashScreen.java index 78ec4ed7aa0..7f522026b8a 100644 --- a/src/java.desktop/share/classes/java/awt/SplashScreen.java +++ b/src/java.desktop/share/classes/java/awt/SplashScreen.java @@ -129,13 +129,7 @@ public final class SplashScreen { } // SplashScreen class is now a singleton if (!wasClosed && theInstance == null) { - java.security.AccessController.doPrivileged( - new java.security.PrivilegedAction() { - public Void run() { - System.loadLibrary("splashscreen"); - return null; - } - }); + System.loadLibrary("splashscreen"); long ptr = _getInstance(); if (ptr != 0 && _isVisible(ptr)) { theInstance = new SplashScreen(ptr); diff --git a/src/java.desktop/share/classes/java/awt/Toolkit.java b/src/java.desktop/share/classes/java/awt/Toolkit.java index 19b0ab9019a..d181fb6f536 100644 --- a/src/java.desktop/share/classes/java/awt/Toolkit.java +++ b/src/java.desktop/share/classes/java/awt/Toolkit.java @@ -56,8 +56,6 @@ import java.beans.PropertyChangeSupport; import java.io.File; import java.io.FileInputStream; import java.net.URL; -import java.security.AccessController; -import java.security.PrivilegedAction; import java.util.ArrayList; import java.util.Arrays; import java.util.EventListener; @@ -396,18 +394,12 @@ public abstract class Toolkit { * properties are set up properly before any classes dependent upon them * are initialized. */ - @SuppressWarnings("removal") private static void initAssistiveTechnologies() { // Get accessibility properties final String sep = File.separator; final Properties properties = new Properties(); - - atNames = java.security.AccessController.doPrivileged( - new java.security.PrivilegedAction() { - public String run() { - // Try loading the per-user accessibility properties file. try { File propsFile = new File( @@ -459,9 +451,7 @@ public abstract class Toolkit { System.setProperty("javax.accessibility.assistive_technologies", classNames); } } - return classNames; - } - }); + atNames = classNames; } /** @@ -512,7 +502,6 @@ public abstract class Toolkit { * {@code null} it is ignored. All other errors are handled via an AWTError * exception. */ - @SuppressWarnings("removal") private static void loadAssistiveTechnologies() { // Load any assistive technologies if (atNames != null && !atNames.isBlank()) { @@ -521,20 +510,17 @@ public abstract class Toolkit { .map(String::trim) .collect(Collectors.toSet()); final Map providers = new HashMap<>(); - AccessController.doPrivileged((PrivilegedAction) () -> { - try { - for (AccessibilityProvider p : ServiceLoader.load(AccessibilityProvider.class, cl)) { - String name = p.getName(); - if (names.contains(name) && !providers.containsKey(name)) { - p.activate(); - providers.put(name, p); - } + try { + for (AccessibilityProvider p : ServiceLoader.load(AccessibilityProvider.class, cl)) { + String name = p.getName(); + if (names.contains(name) && !providers.containsKey(name)) { + p.activate(); + providers.put(name, p); } - } catch (java.util.ServiceConfigurationError | Exception e) { - newAWTError(e, "Could not load or activate service provider"); } - return null; - }); + } catch (java.util.ServiceConfigurationError | Exception e) { + newAWTError(e, "Could not load or activate service provider"); + } names.stream() .filter(n -> !providers.containsKey(n)) .forEach(Toolkit::fallbackToLoadClassForAT); @@ -1302,16 +1288,10 @@ public abstract class Toolkit { * directly. -hung */ private static boolean loaded = false; - @SuppressWarnings({"removal", "restricted"}) + @SuppressWarnings("restricted") static void loadLibraries() { if (!loaded) { - java.security.AccessController.doPrivileged( - new java.security.PrivilegedAction() { - public Void run() { - System.loadLibrary("awt"); - return null; - } - }); + System.loadLibrary("awt"); loaded = true; } } @@ -1320,7 +1300,6 @@ public abstract class Toolkit { initStatic(); } - @SuppressWarnings("removal") private static void initStatic() { AWTAccessor.setToolkitAccessor( new AWTAccessor.ToolkitAccessor() { @@ -1330,17 +1309,11 @@ public abstract class Toolkit { } }); - java.security.AccessController.doPrivileged( - new java.security.PrivilegedAction() { - public Void run() { - try { - resources = ResourceBundle.getBundle("sun.awt.resources.awt"); - } catch (MissingResourceException e) { - // No resource file; defaults will be used. - } - return null; - } - }); + try { + resources = ResourceBundle.getBundle("sun.awt.resources.awt"); + } catch (MissingResourceException e) { + // No resource file; defaults will be used. + } // ensure that the proper libraries are loaded loadLibraries(); diff --git a/src/java.desktop/share/classes/java/awt/WaitDispatchSupport.java b/src/java.desktop/share/classes/java/awt/WaitDispatchSupport.java index d239a600697..2968c9ad3ef 100644 --- a/src/java.desktop/share/classes/java/awt/WaitDispatchSupport.java +++ b/src/java.desktop/share/classes/java/awt/WaitDispatchSupport.java @@ -29,9 +29,6 @@ import java.util.Timer; import java.util.TimerTask; import java.util.concurrent.atomic.AtomicBoolean; -import java.security.PrivilegedAction; -import java.security.AccessController; - import sun.awt.PeerEvent; import sun.util.logging.PlatformLogger; @@ -230,13 +227,7 @@ class WaitDispatchSupport implements SecondaryLoop { // The event will be handled after the new event pump // starts. Thus, the enter() method will not hang. // - // Event pump should be privileged. See 6300270. - AccessController.doPrivileged(new PrivilegedAction() { - public Void run() { - run.run(); - return null; - } - }); + run.run(); } else { if (log.isLoggable(PlatformLogger.Level.FINEST)) { log.finest("On non-dispatch thread: " + currentThread); diff --git a/src/java.desktop/share/classes/java/awt/Window.java b/src/java.desktop/share/classes/java/awt/Window.java index a1e9d48d9d4..1a5395431ab 100644 --- a/src/java.desktop/share/classes/java/awt/Window.java +++ b/src/java.desktop/share/classes/java/awt/Window.java @@ -48,7 +48,6 @@ import java.io.Serial; import java.io.Serializable; import java.lang.ref.WeakReference; import java.lang.reflect.InvocationTargetException; -import java.security.AccessController; import java.util.ArrayList; import java.util.Arrays; import java.util.EventListener; @@ -414,13 +413,9 @@ public class Window extends Container implements Accessible { initIDs(); } - @SuppressWarnings("removal") - String s = java.security.AccessController.doPrivileged( - new GetPropertyAction("java.awt.syncLWRequests")); + String s = System.getProperty("java.awt.syncLWRequests"); systemSyncLWRequests = "true".equals(s); - @SuppressWarnings("removal") - String s2 = java.security.AccessController.doPrivileged( - new GetPropertyAction("java.awt.Window.locationByPlatform")); + String s2 = System.getProperty("java.awt.Window.locationByPlatform"); locationByPlatformProp = "true".equals(s2); } @@ -505,7 +500,6 @@ public class Window extends Container implements Accessible { weakThis = new WeakReference(this); addToWindowList(); - setWarningString(); this.cursor = Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR); this.visible = false; @@ -1376,24 +1370,6 @@ public class Window extends Container implements Accessible { return warningString; } - @SuppressWarnings("removal") - private void setWarningString() { - warningString = null; - SecurityManager sm = System.getSecurityManager(); - if (sm != null) { - try { - sm.checkPermission(AWTPermissions.TOPLEVEL_WINDOW_PERMISSION); - } catch (SecurityException se) { - // make sure the privileged action is only - // for getting the property! We don't want the - // above checkPermission call to always succeed! - warningString = AccessController.doPrivileged( - new GetPropertyAction("awt.appletWarning", - "Java Applet Window")); - } - } - } - /** * Gets the {@code Locale} object that is associated * with this window, if the locale has been set. @@ -2978,7 +2954,6 @@ public class Window extends Container implements Accessible { // user's code. // private void initDeserializedWindow() { - setWarningString(); inputContextLock = new Object(); // Deserialized Windows are not yet visible. diff --git a/src/java.desktop/share/classes/java/awt/color/ICC_Profile.java b/src/java.desktop/share/classes/java/awt/color/ICC_Profile.java index b4e71b3c839..729d8123a24 100644 --- a/src/java.desktop/share/classes/java/awt/color/ICC_Profile.java +++ b/src/java.desktop/share/classes/java/awt/color/ICC_Profile.java @@ -48,8 +48,6 @@ import java.io.ObjectStreamException; import java.io.OutputStream; import java.io.Serial; import java.io.Serializable; -import java.security.AccessController; -import java.security.PrivilegedAction; import java.util.Objects; import java.util.StringTokenizer; @@ -1341,13 +1339,8 @@ public sealed class ICC_Profile implements Serializable * fileName. If there is no built-in profile with such name, then the method * returns {@code null}. */ - @SuppressWarnings("removal") private static InputStream getStandardProfileInputStream(String fileName) { - return AccessController.doPrivileged( - (PrivilegedAction) () -> { - return PCMM.class.getResourceAsStream("profiles/" + fileName); - }, null, new FilePermission("<>", "read"), - new RuntimePermission("accessSystemModules")); + return PCMM.class.getResourceAsStream("profiles/" + fileName); } /** diff --git a/src/java.desktop/share/classes/java/awt/dnd/DragSource.java b/src/java.desktop/share/classes/java/awt/dnd/DragSource.java index 01945662e46..8477bc6376d 100644 --- a/src/java.desktop/share/classes/java/awt/dnd/DragSource.java +++ b/src/java.desktop/share/classes/java/awt/dnd/DragSource.java @@ -40,13 +40,11 @@ import java.io.ObjectInputStream; import java.io.ObjectOutputStream; import java.io.Serial; import java.io.Serializable; -import java.security.AccessController; import java.util.EventListener; import sun.awt.AWTAccessor; import sun.awt.AWTAccessor.DragSourceContextAccessor; import sun.awt.dnd.SunDragSourceContextPeer; -import sun.security.action.GetIntegerAction; /** * The {@code DragSource} is the entity responsible @@ -908,8 +906,7 @@ public class DragSource implements Serializable { */ public static int getDragThreshold() { @SuppressWarnings("removal") - int ts = AccessController.doPrivileged( - new GetIntegerAction("awt.dnd.drag.threshold", 0)).intValue(); + int ts = Integer.getInteger("awt.dnd.drag.threshold", 0); if (ts > 0) { return ts; } else { diff --git a/src/java.desktop/share/classes/java/awt/event/NativeLibLoader.java b/src/java.desktop/share/classes/java/awt/event/NativeLibLoader.java index 27a2c439747..8b0d46d05e0 100644 --- a/src/java.desktop/share/classes/java/awt/event/NativeLibLoader.java +++ b/src/java.desktop/share/classes/java/awt/event/NativeLibLoader.java @@ -52,14 +52,8 @@ class NativeLibLoader { * For now, we know it's done by the implementation, and we assume * that the name of the library is "awt". -br. */ - @SuppressWarnings({"removal", "restricted"}) + @SuppressWarnings("restricted") static void loadLibraries() { - java.security.AccessController.doPrivileged( - new java.security.PrivilegedAction() { - public Void run() { - System.loadLibrary("awt"); - return null; - } - }); + System.loadLibrary("awt"); } } diff --git a/src/java.desktop/share/classes/java/awt/image/BufferedImage.java b/src/java.desktop/share/classes/java/awt/image/BufferedImage.java index cfbebd68710..09c96a6560f 100644 --- a/src/java.desktop/share/classes/java/awt/image/BufferedImage.java +++ b/src/java.desktop/share/classes/java/awt/image/BufferedImage.java @@ -31,8 +31,6 @@ import java.awt.Point; import java.awt.Rectangle; import java.awt.Transparency; import java.awt.color.ColorSpace; -import java.security.AccessController; -import java.security.PrivilegedAction; import java.util.Hashtable; import java.util.Set; import java.util.Vector; @@ -800,26 +798,16 @@ public class BufferedImage extends java.awt.Image } // else if ((raster instanceof ByteComponentRaster) && } - @SuppressWarnings("removal") private static boolean isStandard(ColorModel cm, WritableRaster wr) { final Class cmClass = cm.getClass(); final Class wrClass = wr.getClass(); final Class smClass = wr.getSampleModel().getClass(); - final PrivilegedAction checkClassLoadersAction = - new PrivilegedAction() - { + final ClassLoader std = System.class.getClassLoader(); - @Override - public Boolean run() { - final ClassLoader std = System.class.getClassLoader(); - - return (cmClass.getClassLoader() == std) && - (smClass.getClassLoader() == std) && - (wrClass.getClassLoader() == std); - } - }; - return AccessController.doPrivileged(checkClassLoadersAction); + return (cmClass.getClassLoader() == std) && + (smClass.getClassLoader() == std) && + (wrClass.getClassLoader() == std); } /** diff --git a/src/java.desktop/share/classes/java/awt/image/ColorModel.java b/src/java.desktop/share/classes/java/awt/image/ColorModel.java index a0aa8fddc10..b2d568cb09f 100644 --- a/src/java.desktop/share/classes/java/awt/image/ColorModel.java +++ b/src/java.desktop/share/classes/java/awt/image/ColorModel.java @@ -202,16 +202,10 @@ public abstract class ColorModel implements Transparency{ * that the name of the library is "awt". -br. */ private static boolean loaded = false; - @SuppressWarnings({"removal", "restricted"}) + @SuppressWarnings("restricted") static void loadLibraries() { if (!loaded) { - java.security.AccessController.doPrivileged( - new java.security.PrivilegedAction() { - public Void run() { - System.loadLibrary("awt"); - return null; - } - }); + System.loadLibrary("awt"); loaded = true; } } diff --git a/src/java.desktop/share/classes/java/beans/EventHandler.java b/src/java.desktop/share/classes/java/beans/EventHandler.java index b3c630ae5c9..eb892f34985 100644 --- a/src/java.desktop/share/classes/java/beans/EventHandler.java +++ b/src/java.desktop/share/classes/java/beans/EventHandler.java @@ -28,9 +28,6 @@ import java.lang.reflect.InvocationHandler; import java.lang.reflect.InvocationTargetException; import java.lang.reflect.Proxy; import java.lang.reflect.Method; -import java.security.AccessControlContext; -import java.security.AccessController; -import java.security.PrivilegedAction; import sun.reflect.misc.MethodUtil; import sun.reflect.misc.ReflectUtil; @@ -281,8 +278,6 @@ public class EventHandler implements InvocationHandler { private String action; private final String eventPropertyName; private final String listenerMethodName; - @SuppressWarnings("removal") - private final AccessControlContext acc = AccessController.getContext(); /** * Creates a new {@code EventHandler} object; @@ -421,20 +416,7 @@ public class EventHandler implements InvocationHandler { * * @see EventHandler */ - @SuppressWarnings("removal") public Object invoke(final Object proxy, final Method method, final Object[] arguments) { - AccessControlContext acc = this.acc; - if ((acc == null) && (System.getSecurityManager() != null)) { - throw new SecurityException("AccessControlContext is not set"); - } - return AccessController.doPrivileged(new PrivilegedAction() { - public Object run() { - return invokeInternal(proxy, method, arguments); - } - }, acc); - } - - private Object invokeInternal(Object proxy, Method method, Object[] arguments) { String methodName = method.getName(); if (method.getDeclaringClass() == Object.class) { // Handle the Object public methods. @@ -689,7 +671,7 @@ public class EventHandler implements InvocationHandler { * @see EventHandler * @see Proxy#newProxyInstance */ - @SuppressWarnings("removal") + @SuppressWarnings("unchecked") public static T create(Class listenerInterface, Object target, String action, String eventPropertyName, @@ -705,12 +687,7 @@ public class EventHandler implements InvocationHandler { } final ClassLoader loader = getClassLoader(listenerInterface); final Class[] interfaces = {listenerInterface}; - return AccessController.doPrivileged(new PrivilegedAction() { - @SuppressWarnings("unchecked") - public T run() { - return (T) Proxy.newProxyInstance(loader, interfaces, handler); - } - }); + return (T) Proxy.newProxyInstance(loader, interfaces, handler); } private static ClassLoader getClassLoader(Class type) { diff --git a/src/java.desktop/share/classes/java/beans/MetaData.java b/src/java.desktop/share/classes/java/beans/MetaData.java index e3cf55a85c5..0a12e7dcee8 100644 --- a/src/java.desktop/share/classes/java/beans/MetaData.java +++ b/src/java.desktop/share/classes/java/beans/MetaData.java @@ -41,9 +41,6 @@ import java.lang.reflect.Method; import java.lang.reflect.Modifier; import java.lang.reflect.InvocationTargetException; -import java.security.AccessController; -import java.security.PrivilegedAction; - import java.util.*; import javax.swing.Box; @@ -1319,28 +1316,22 @@ static final class sun_swing_PrintColorUIResource_PersistenceDelegate extends Pe } } - @SuppressWarnings("removal") static Object getPrivateFieldValue(Object instance, String name) { Field field = fields.get(name); if (field == null) { int index = name.lastIndexOf('.'); final String className = name.substring(0, index); final String fieldName = name.substring(1 + index); - field = AccessController.doPrivileged(new PrivilegedAction() { - public Field run() { - try { - Field field = Class.forName(className).getDeclaredField(fieldName); - field.setAccessible(true); - return field; - } - catch (ClassNotFoundException exception) { - throw new IllegalStateException("Could not find class", exception); - } - catch (NoSuchFieldException exception) { - throw new IllegalStateException("Could not find field", exception); - } - } - }); + try { + field = Class.forName(className).getDeclaredField(fieldName); + field.setAccessible(true); + } + catch (ClassNotFoundException exception) { + throw new IllegalStateException("Could not find class", exception); + } + catch (NoSuchFieldException exception) { + throw new IllegalStateException("Could not find field", exception); + } fields.put(name, field); } try { diff --git a/src/java.desktop/share/classes/java/beans/SimpleBeanInfo.java b/src/java.desktop/share/classes/java/beans/SimpleBeanInfo.java index 34ca9d20403..7b6fd131c24 100644 --- a/src/java.desktop/share/classes/java/beans/SimpleBeanInfo.java +++ b/src/java.desktop/share/classes/java/beans/SimpleBeanInfo.java @@ -29,8 +29,6 @@ import java.awt.Image; import java.awt.Toolkit; import java.awt.image.ImageProducer; import java.net.URL; -import java.security.AccessController; -import java.security.PrivilegedAction; /** * This is a support class to make it easier for people to provide @@ -154,10 +152,8 @@ public class SimpleBeanInfo implements BeanInfo { * @return an image object. May be null if the load failed. * @see java.beans.SimpleBeanInfo#loadImage(String) */ - @SuppressWarnings("removal") private Image loadStandardImage(final String resourceName) { - return AccessController.doPrivileged( - (PrivilegedAction) () -> loadImage(resourceName)); + return loadImage(resourceName); } /** diff --git a/src/java.desktop/share/classes/java/beans/Statement.java b/src/java.desktop/share/classes/java/beans/Statement.java index d079a0b24a9..bf1c62be78b 100644 --- a/src/java.desktop/share/classes/java/beans/Statement.java +++ b/src/java.desktop/share/classes/java/beans/Statement.java @@ -29,10 +29,6 @@ import java.lang.reflect.Array; import java.lang.reflect.Constructor; import java.lang.reflect.InvocationTargetException; import java.lang.reflect.Method; -import java.security.AccessControlContext; -import java.security.AccessController; -import java.security.PrivilegedActionException; -import java.security.PrivilegedExceptionAction; import com.sun.beans.finder.ClassFinder; import com.sun.beans.finder.ConstructorFinder; @@ -69,8 +65,6 @@ public class Statement { } }; - @SuppressWarnings("removal") - private final AccessControlContext acc = AccessController.getContext(); private final Object target; private final String methodName; private final Object[] arguments; @@ -174,28 +168,7 @@ public class Statement { invoke(); } - @SuppressWarnings("removal") Object invoke() throws Exception { - AccessControlContext acc = this.acc; - if ((acc == null) && (System.getSecurityManager() != null)) { - throw new SecurityException("AccessControlContext is not set"); - } - try { - return AccessController.doPrivileged( - new PrivilegedExceptionAction() { - public Object run() throws Exception { - return invokeInternal(); - } - }, - acc - ); - } - catch (PrivilegedActionException exception) { - throw exception.getException(); - } - } - - private Object invokeInternal() throws Exception { Object target = getTarget(); String methodName = getMethodName(); diff --git a/src/java.desktop/share/classes/java/beans/XMLDecoder.java b/src/java.desktop/share/classes/java/beans/XMLDecoder.java index 8a7e6b9984a..febba84d2a1 100644 --- a/src/java.desktop/share/classes/java/beans/XMLDecoder.java +++ b/src/java.desktop/share/classes/java/beans/XMLDecoder.java @@ -29,9 +29,6 @@ import com.sun.beans.decoder.DocumentHandler; import java.io.Closeable; import java.io.InputStream; import java.io.IOException; -import java.security.AccessControlContext; -import java.security.AccessController; -import java.security.PrivilegedAction; import org.xml.sax.InputSource; import org.xml.sax.helpers.DefaultHandler; @@ -64,8 +61,6 @@ import org.xml.sax.helpers.DefaultHandler; * @author Philip Milne */ public class XMLDecoder implements AutoCloseable { - @SuppressWarnings("removal") - private final AccessControlContext acc = AccessController.getContext(); private final DocumentHandler handler = new DocumentHandler(); private final InputSource input; private Object owner; @@ -189,21 +184,12 @@ public class XMLDecoder implements AutoCloseable { } } - @SuppressWarnings("removal") private boolean parsingComplete() { if (this.input == null) { return false; } if (this.array == null) { - if ((this.acc == null) && (null != System.getSecurityManager())) { - throw new SecurityException("AccessControlContext is not set"); - } - AccessController.doPrivileged(new PrivilegedAction() { - public Void run() { - XMLDecoder.this.handler.parse(XMLDecoder.this.input); - return null; - } - }, this.acc); + XMLDecoder.this.handler.parse(XMLDecoder.this.input); this.array = this.handler.getObjects(); } return true;