From 4b1653056d39db2c85989c787364e2646e5ef463 Mon Sep 17 00:00:00 2001 From: Phil Race Date: Fri, 22 Nov 2024 18:00:10 +0000 Subject: [PATCH] 8344795: Remove uses of AccessControlContext in java.desktop module Reviewed-by: azvegint --- .../sun/beans/decoder/DocumentHandler.java | 37 +++++----------- .../share/classes/java/awt/AWTEvent.java | 25 ----------- .../share/classes/java/awt/Component.java | 28 ------------ .../share/classes/java/awt/MenuComponent.java | 24 ----------- .../share/classes/java/awt/TrayIcon.java | 22 ---------- .../classes/javax/swing/TransferHandler.java | 43 ------------------- .../share/classes/javax/swing/UIDefaults.java | 6 --- .../share/classes/sun/awt/AWTAccessor.java | 14 ------ 8 files changed, 11 insertions(+), 188 deletions(-) diff --git a/src/java.desktop/share/classes/com/sun/beans/decoder/DocumentHandler.java b/src/java.desktop/share/classes/com/sun/beans/decoder/DocumentHandler.java index a4b7981d0e6..51f84b7b172 100644 --- a/src/java.desktop/share/classes/com/sun/beans/decoder/DocumentHandler.java +++ b/src/java.desktop/share/classes/com/sun/beans/decoder/DocumentHandler.java @@ -38,9 +38,6 @@ import java.util.ArrayList; import java.util.HashMap; import java.util.List; import java.util.Map; -import java.security.AccessControlContext; -import java.security.AccessController; -import java.security.PrivilegedAction; import javax.xml.parsers.ParserConfigurationException; import javax.xml.parsers.SAXParserFactory; @@ -62,8 +59,6 @@ import jdk.internal.access.SharedSecrets; * @see ElementHandler */ public final class DocumentHandler extends DefaultHandler { - @SuppressWarnings("removal") - private final AccessControlContext acc = AccessController.getContext(); private final Map> handlers = new HashMap<>(); private final Map environment = new HashMap<>(); private final List objects = new ArrayList<>(); @@ -367,30 +362,20 @@ public final class DocumentHandler extends DefaultHandler { * * @param input the input source to parse */ - @SuppressWarnings("removal") public void parse(final InputSource input) { - if ((this.acc == null) && (null != System.getSecurityManager())) { - throw new SecurityException("AccessControlContext is not set"); + try { + SAXParserFactory.newInstance().newSAXParser().parse(input, DocumentHandler.this); } - AccessControlContext stack = AccessController.getContext(); - SharedSecrets.getJavaSecurityAccess().doIntersectionPrivilege(new PrivilegedAction() { - public Void run() { - try { - SAXParserFactory.newInstance().newSAXParser().parse(input, DocumentHandler.this); - } - catch (ParserConfigurationException | IOException exception) { - handleException(exception); - } - catch (SAXException wrapper) { - Exception exception = wrapper.getException(); - if (exception == null) { - exception = wrapper; - } - handleException(exception); - } - return null; + catch (ParserConfigurationException | IOException exception) { + handleException(exception); + } + catch (SAXException wrapper) { + Exception exception = wrapper.getException(); + if (exception == null) { + exception = wrapper; } - }, stack, this.acc); + handleException(exception); + } } /** diff --git a/src/java.desktop/share/classes/java/awt/AWTEvent.java b/src/java.desktop/share/classes/java/awt/AWTEvent.java index 93def2fadc9..fe9d30deaeb 100644 --- a/src/java.desktop/share/classes/java/awt/AWTEvent.java +++ b/src/java.desktop/share/classes/java/awt/AWTEvent.java @@ -39,8 +39,6 @@ import java.awt.event.WindowEvent; import java.awt.peer.ComponentPeer; import java.awt.peer.LightweightPeer; import java.io.Serial; -import java.security.AccessControlContext; -import java.security.AccessController; import java.util.EventObject; import sun.awt.AWTAccessor; @@ -112,24 +110,6 @@ public abstract class AWTEvent extends EventObject { */ protected boolean consumed = false; - /* - * The event's AccessControlContext. - */ - @SuppressWarnings("removal") - private transient volatile AccessControlContext acc = - AccessController.getContext(); - - /* - * Returns the acc this event was constructed with. - */ - @SuppressWarnings("removal") - final AccessControlContext getAccessControlContext() { - if (acc == null) { - throw new SecurityException("AWTEvent is missing AccessControlContext"); - } - return acc; - } - transient boolean focusManagerIsDispatching = false; transient boolean isPosted; @@ -281,11 +261,6 @@ public abstract class AWTEvent extends EventObject { return ev.isSystemGenerated; } - @SuppressWarnings("removal") - public AccessControlContext getAccessControlContext(AWTEvent ev) { - return ev.getAccessControlContext(); - } - public byte[] getBData(AWTEvent ev) { return ev.bdata; } diff --git a/src/java.desktop/share/classes/java/awt/Component.java b/src/java.desktop/share/classes/java/awt/Component.java index 36683ff2813..8bfe16619bb 100644 --- a/src/java.desktop/share/classes/java/awt/Component.java +++ b/src/java.desktop/share/classes/java/awt/Component.java @@ -69,8 +69,6 @@ import java.io.PrintStream; import java.io.PrintWriter; import java.io.Serial; import java.io.Serializable; -import java.security.AccessControlContext; -import java.security.AccessController; import java.util.Collections; import java.util.EventListener; import java.util.HashSet; @@ -501,13 +499,6 @@ public abstract class Component implements ImageObserver, MenuContainer, static final Object LOCK = new AWTTreeLock(); static class AWTTreeLock {} - /* - * The component's AccessControlContext. - */ - @SuppressWarnings("removal") - private transient volatile AccessControlContext acc = - AccessController.getContext(); - /** * Minimum size. * (This field perhaps should have been transient). @@ -706,17 +697,6 @@ public abstract class Component implements ImageObserver, MenuContainer, return objectLock; } - /* - * Returns the acc this component was constructed with. - */ - @SuppressWarnings("removal") - final AccessControlContext getAccessControlContext() { - if (acc == null) { - throw new SecurityException("Component is missing AccessControlContext"); - } - return acc; - } - /** * Whether the component is packed or not; */ @@ -972,11 +952,6 @@ public abstract class Component implements ImageObserver, MenuContainer, comp.processEvent(e); } - @SuppressWarnings("removal") - public AccessControlContext getAccessControlContext(Component comp) { - return comp.getAccessControlContext(); - } - public void revalidateSynchronously(Component comp) { comp.revalidateSynchronously(); } @@ -8967,15 +8942,12 @@ public abstract class Component implements ImageObserver, MenuContainer, * @throws IOException if an I/O error occurs * @see #writeObject(ObjectOutputStream) */ - @SuppressWarnings("removal") @Serial private void readObject(ObjectInputStream s) throws ClassNotFoundException, IOException { objectLock = new Object(); - acc = AccessController.getContext(); - s.defaultReadObject(); appContext = AppContext.getAppContext(); diff --git a/src/java.desktop/share/classes/java/awt/MenuComponent.java b/src/java.desktop/share/classes/java/awt/MenuComponent.java index b2bc22c2e93..12a24e92842 100644 --- a/src/java.desktop/share/classes/java/awt/MenuComponent.java +++ b/src/java.desktop/share/classes/java/awt/MenuComponent.java @@ -30,8 +30,6 @@ import java.awt.peer.MenuComponentPeer; import java.io.IOException; import java.io.ObjectInputStream; import java.io.Serial; -import java.security.AccessControlContext; -import java.security.AccessController; import javax.accessibility.Accessible; import javax.accessibility.AccessibleComponent; @@ -103,25 +101,6 @@ public abstract class MenuComponent implements java.io.Serializable { */ volatile boolean newEventsOnly; - /* - * The menu's AccessControlContext. - */ - @SuppressWarnings("removal") - private transient volatile AccessControlContext acc = - AccessController.getContext(); - - /* - * Returns the acc this menu component was constructed with. - */ - @SuppressWarnings("removal") - final AccessControlContext getAccessControlContext() { - if (acc == null) { - throw new SecurityException( - "MenuComponent is missing AccessControlContext"); - } - return acc; - } - /* * Internal constants for serialization. */ @@ -442,15 +421,12 @@ public abstract class MenuComponent implements java.io.Serializable { * * @see java.awt.GraphicsEnvironment#isHeadless */ - @SuppressWarnings("removal") @Serial private void readObject(ObjectInputStream s) throws ClassNotFoundException, IOException, HeadlessException { GraphicsEnvironment.checkHeadless(); - acc = AccessController.getContext(); - s.defaultReadObject(); appContext = AppContext.getAppContext(); diff --git a/src/java.desktop/share/classes/java/awt/TrayIcon.java b/src/java.desktop/share/classes/java/awt/TrayIcon.java index cabb5dac3cf..3323818eeb1 100644 --- a/src/java.desktop/share/classes/java/awt/TrayIcon.java +++ b/src/java.desktop/share/classes/java/awt/TrayIcon.java @@ -32,8 +32,6 @@ import sun.awt.SunToolkit; import sun.awt.AWTAccessor; import sun.awt.HeadlessToolkit; import java.util.EventObject; -import java.security.AccessControlContext; -import java.security.AccessController; /** * A {@code TrayIcon} object represents a tray icon that can be @@ -102,26 +100,6 @@ public class TrayIcon { transient MouseMotionListener mouseMotionListener; transient ActionListener actionListener; - /* - * The tray icon's AccessControlContext. - * - * Unlike the acc in Component, this field is made final - * because TrayIcon is not serializable. - */ - @SuppressWarnings("removal") - private final AccessControlContext acc = AccessController.getContext(); - - /* - * Returns the acc this tray icon was constructed with. - */ - @SuppressWarnings("removal") - final AccessControlContext getAccessControlContext() { - if (acc == null) { - throw new SecurityException("TrayIcon is missing AccessControlContext"); - } - return acc; - } - static { Toolkit.loadLibraries(); if (!GraphicsEnvironment.isHeadless()) { diff --git a/src/java.desktop/share/classes/javax/swing/TransferHandler.java b/src/java.desktop/share/classes/javax/swing/TransferHandler.java index d12c393d66a..613d9d570b5 100644 --- a/src/java.desktop/share/classes/javax/swing/TransferHandler.java +++ b/src/java.desktop/share/classes/javax/swing/TransferHandler.java @@ -42,16 +42,6 @@ import sun.awt.AppContext; import sun.swing.*; import sun.awt.SunToolkit; -import java.security.AccessController; -import java.security.PrivilegedAction; - -import java.security.AccessControlContext; - -import jdk.internal.access.SharedSecrets; -import jdk.internal.access.JavaSecurityAccess; - -import sun.awt.AWTAccessor; - /** * This class is used to handle the transfer of a Transferable * to and from Swing components. The Transferable is used to @@ -1701,40 +1691,7 @@ public class TransferHandler implements Serializable { && ((JComponent)sender).getTransferHandler() == null); } - private static final JavaSecurityAccess javaSecurityAccess = - SharedSecrets.getJavaSecurityAccess(); - public void actionPerformed(final ActionEvent e) { - final Object src = e.getSource(); - - final PrivilegedAction action = new PrivilegedAction() { - public Void run() { - actionPerformedImpl(e); - return null; - } - }; - - @SuppressWarnings("removal") - final AccessControlContext stack = AccessController.getContext(); - @SuppressWarnings("removal") - final AccessControlContext srcAcc = AWTAccessor.getComponentAccessor().getAccessControlContext((Component)src); - @SuppressWarnings("removal") - final AccessControlContext eventAcc = AWTAccessor.getAWTEventAccessor().getAccessControlContext(e); - - if (srcAcc == null) { - javaSecurityAccess.doIntersectionPrivilege(action, stack, eventAcc); - } else { - javaSecurityAccess.doIntersectionPrivilege( - new PrivilegedAction() { - public Void run() { - javaSecurityAccess.doIntersectionPrivilege(action, eventAcc); - return null; - } - }, stack, srcAcc); - } - } - - private void actionPerformedImpl(ActionEvent e) { Object src = e.getSource(); if (src instanceof JComponent) { JComponent c = (JComponent) src; diff --git a/src/java.desktop/share/classes/javax/swing/UIDefaults.java b/src/java.desktop/share/classes/javax/swing/UIDefaults.java index 62939b90e70..c8d294f4fbf 100644 --- a/src/java.desktop/share/classes/javax/swing/UIDefaults.java +++ b/src/java.desktop/share/classes/javax/swing/UIDefaults.java @@ -49,8 +49,6 @@ import java.awt.Color; import java.awt.Insets; import java.awt.Dimension; import java.beans.PropertyChangeListener; -import java.security.AccessController; -import java.security.AccessControlContext; import sun.reflect.misc.MethodUtil; import sun.reflect.misc.ReflectUtil; @@ -1062,8 +1060,6 @@ public class UIDefaults extends Hashtable * @since 1.3 */ public static class ProxyLazyValue implements LazyValue { - @SuppressWarnings("removal") - private AccessControlContext acc; private String className; private String methodName; private Object[] args; @@ -1117,9 +1113,7 @@ public class UIDefaults extends Hashtable * @param o an array of Objects to be passed as * parameters to the static method in class c */ - @SuppressWarnings("removal") public ProxyLazyValue(String c, String m, Object[] o) { - acc = AccessController.getContext(); className = c; methodName = m; if (o != null) { diff --git a/src/java.desktop/share/classes/sun/awt/AWTAccessor.java b/src/java.desktop/share/classes/sun/awt/AWTAccessor.java index 5a3d2c46773..db107fc309c 100644 --- a/src/java.desktop/share/classes/sun/awt/AWTAccessor.java +++ b/src/java.desktop/share/classes/sun/awt/AWTAccessor.java @@ -44,7 +44,6 @@ import java.awt.peer.ComponentPeer; import java.awt.peer.MenuComponentPeer; import java.lang.invoke.MethodHandles; import java.lang.reflect.InvocationTargetException; -import java.security.AccessControlContext; import java.io.File; import java.util.ResourceBundle; @@ -244,13 +243,6 @@ public final class AWTAccessor { */ void processEvent(Component comp, AWTEvent e); - - /* - * Returns the acc this component was constructed with. - */ - @SuppressWarnings("removal") - AccessControlContext getAccessControlContext(Component comp); - /** * Revalidates the component synchronously. */ @@ -353,12 +345,6 @@ public final class AWTAccessor { */ boolean isSystemGenerated(AWTEvent ev); - /** - * Returns the acc this event was constructed with. - */ - @SuppressWarnings("removal") - AccessControlContext getAccessControlContext(AWTEvent ev); - /** * Returns binary data associated with this event; */