From 395e404666e51f76270de4de1899aa681ba889c9 Mon Sep 17 00:00:00 2001 From: Abhishek Kumar Date: Thu, 21 Nov 2024 17:39:44 +0000 Subject: [PATCH] 8344066: Remove SecurityManager uses from the jdk.accessibility module Reviewed-by: prr --- .../accessibility/util/AWTEventMonitor.java | 37 -------- .../accessibility/util/EventQueueMonitor.java | 24 ++--- .../accessibility/util/SwingEventMonitor.java | 89 ------------------- .../accessibility/internal/AccessBridge.java | 29 +----- 4 files changed, 11 insertions(+), 168 deletions(-) diff --git a/src/jdk.accessibility/share/classes/com/sun/java/accessibility/util/AWTEventMonitor.java b/src/jdk.accessibility/share/classes/com/sun/java/accessibility/util/AWTEventMonitor.java index b1b93d795e4..0ba0c5123f2 100644 --- a/src/jdk.accessibility/share/classes/com/sun/java/accessibility/util/AWTEventMonitor.java +++ b/src/jdk.accessibility/share/classes/com/sun/java/accessibility/util/AWTEventMonitor.java @@ -29,7 +29,6 @@ import java.awt.*; import java.awt.event.*; import javax.swing.*; import javax.swing.event.*; -import sun.awt.AWTPermissions; /** *

The {@code AWTEventMonitor} implements a suite of listeners that are @@ -85,17 +84,6 @@ public class AWTEventMonitor { return componentWithFocus; } - /* - * Check permissions - */ - private static void checkInstallPermission() { - @SuppressWarnings("removal") - SecurityManager security = System.getSecurityManager(); - if (security != null) { - security.checkPermission(AWTPermissions.ALL_AWT_EVENTS_PERMISSION); - } - } - /** * Adds the specified listener to receive all {@link EventID#COMPONENT COMPONENT} * events on each component instance in the Java Virtual Machine as they occur. @@ -108,7 +96,6 @@ public class AWTEventMonitor { */ public static void addComponentListener(ComponentListener l) { if (componentListener == null) { - checkInstallPermission(); awtListener.installListeners(EventID.COMPONENT); } componentListener = AWTEventMulticaster.add(componentListener, l); @@ -190,7 +177,6 @@ public class AWTEventMonitor { */ public static void addKeyListener(KeyListener l) { if (keyListener == null) { - checkInstallPermission(); awtListener.installListeners(EventID.KEY); } keyListener = AWTEventMulticaster.add(keyListener, l); @@ -222,7 +208,6 @@ public class AWTEventMonitor { */ public static void addMouseListener(MouseListener l) { if (mouseListener == null) { - checkInstallPermission(); awtListener.installListeners(EventID.MOUSE); } mouseListener = AWTEventMulticaster.add(mouseListener, l); @@ -254,7 +239,6 @@ public class AWTEventMonitor { */ public static void addMouseMotionListener(MouseMotionListener l) { if (mouseMotionListener == null) { - checkInstallPermission(); awtListener.installListeners(EventID.MOTION); } mouseMotionListener = AWTEventMulticaster.add(mouseMotionListener, l); @@ -286,7 +270,6 @@ public class AWTEventMonitor { */ public static void addWindowListener(WindowListener l) { if (windowListener == null) { - checkInstallPermission(); awtListener.installListeners(EventID.WINDOW); } windowListener = AWTEventMulticaster.add(windowListener, l); @@ -318,7 +301,6 @@ public class AWTEventMonitor { */ public static void addActionListener(ActionListener l) { if (actionListener == null) { - checkInstallPermission(); awtListener.installListeners(EventID.ACTION); } actionListener = AWTEventMulticaster.add(actionListener, l); @@ -351,7 +333,6 @@ public class AWTEventMonitor { */ public static void addAdjustmentListener(AdjustmentListener l) { if (adjustmentListener == null) { - checkInstallPermission(); awtListener.installListeners(EventID.ADJUSTMENT); } adjustmentListener = AWTEventMulticaster.add(adjustmentListener, l); @@ -383,7 +364,6 @@ public class AWTEventMonitor { */ public static void addItemListener(ItemListener l) { if (itemListener == null) { - checkInstallPermission(); awtListener.installListeners(EventID.ITEM); } itemListener = AWTEventMulticaster.add(itemListener, l); @@ -415,7 +395,6 @@ public class AWTEventMonitor { */ public static void addTextListener(TextListener l) { if (textListener == null) { - checkInstallPermission(); awtListener.installListeners(EventID.TEXT); } textListener = AWTEventMulticaster.add(textListener, l); @@ -668,8 +647,6 @@ public class AWTEventMonitor { } } catch (NoSuchMethodException e) { // System.out.println("Exception: " + e.toString()); - } catch (SecurityException e) { - System.out.println("Exception: " + e.toString()); } break; @@ -714,8 +691,6 @@ public class AWTEventMonitor { } } catch (NoSuchMethodException e) { // System.out.println("Exception: " + e.toString()); - } catch (SecurityException e) { - System.out.println("Exception: " + e.toString()); } // [PK] CheckboxMenuItem isn't a component but it does // implement Interface ItemSelectable!! @@ -755,8 +730,6 @@ public class AWTEventMonitor { } } catch (NoSuchMethodException e) { // System.out.println("Exception: " + e.toString()); - } catch (SecurityException e) { - System.out.println("Exception: " + e.toString()); } break; @@ -776,8 +749,6 @@ public class AWTEventMonitor { } } catch (NoSuchMethodException e) { // System.out.println("Exception: " + e.toString()); - } catch (SecurityException e) { - System.out.println("Exception: " + e.toString()); } break; @@ -881,8 +852,6 @@ public class AWTEventMonitor { } } catch (NoSuchMethodException e) { // System.out.println("Exception: " + e.toString()); - } catch (SecurityException e) { - System.out.println("Exception: " + e.toString()); } break; @@ -921,8 +890,6 @@ public class AWTEventMonitor { } } catch (NoSuchMethodException e) { // System.out.println("Exception: " + e.toString()); - } catch (SecurityException e) { - System.out.println("Exception: " + e.toString()); } // [PK] CheckboxMenuItem isn't a component but it does // implement Interface ItemSelectable!! @@ -955,8 +922,6 @@ public class AWTEventMonitor { } } catch (NoSuchMethodException e) { // System.out.println("Exception: " + e.toString()); - } catch (SecurityException e) { - System.out.println("Exception: " + e.toString()); } break; @@ -973,8 +938,6 @@ public class AWTEventMonitor { } } catch (NoSuchMethodException e) { // System.out.println("Exception: " + e.toString()); - } catch (SecurityException e) { - System.out.println("Exception: " + e.toString()); } break; diff --git a/src/jdk.accessibility/share/classes/com/sun/java/accessibility/util/EventQueueMonitor.java b/src/jdk.accessibility/share/classes/com/sun/java/accessibility/util/EventQueueMonitor.java index cb630223c49..9ef9482e3ec 100644 --- a/src/jdk.accessibility/share/classes/com/sun/java/accessibility/util/EventQueueMonitor.java +++ b/src/jdk.accessibility/share/classes/com/sun/java/accessibility/util/EventQueueMonitor.java @@ -29,8 +29,6 @@ import java.util.*; import java.awt.*; import java.awt.event.*; import javax.accessibility.*; -import java.security.AccessController; -import java.security.PrivilegedAction; /** * The {@code EventQueueMonitor} class provides key core functionality for Assistive @@ -142,24 +140,16 @@ public class EventQueueMonitor /** * Tell the {@code EventQueueMonitor} to start listening for events. */ - @SuppressWarnings("removal") public static void maybeInitialize() { if (cedt == null) { - java.security.AccessController.doPrivileged( - new java.security.PrivilegedAction() { - public Void run() { - try { - long eventMask = AWTEvent.WINDOW_EVENT_MASK | - AWTEvent.FOCUS_EVENT_MASK | - AWTEvent.MOUSE_MOTION_EVENT_MASK; + try { + long eventMask = AWTEvent.WINDOW_EVENT_MASK | + AWTEvent.FOCUS_EVENT_MASK | + AWTEvent.MOUSE_MOTION_EVENT_MASK; - Toolkit.getDefaultToolkit().addAWTEventListener(new EventQueueMonitor(), eventMask); - } catch (Exception e) { - } - return null; - } - } - ); + Toolkit.getDefaultToolkit().addAWTEventListener(new EventQueueMonitor(), eventMask); + } catch (Exception e) { + } } } diff --git a/src/jdk.accessibility/share/classes/com/sun/java/accessibility/util/SwingEventMonitor.java b/src/jdk.accessibility/share/classes/com/sun/java/accessibility/util/SwingEventMonitor.java index df14d2c0da6..f6f3bb686b1 100644 --- a/src/jdk.accessibility/share/classes/com/sun/java/accessibility/util/SwingEventMonitor.java +++ b/src/jdk.accessibility/share/classes/com/sun/java/accessibility/util/SwingEventMonitor.java @@ -976,8 +976,6 @@ public class SwingEventMonitor extends AWTEventMonitor { } } catch (NoSuchMethodException e) { // System.out.println("Exception: " + e.toString()); - } catch (SecurityException e) { - System.out.println("Exception: " + e.toString()); } break; @@ -1001,8 +999,6 @@ public class SwingEventMonitor extends AWTEventMonitor { } } catch (NoSuchMethodException e) { // System.out.println("Exception: " + e.toString()); - } catch (SecurityException e) { - System.out.println("Exception: " + e.toString()); } // Look for components which support CellEditor listeners @@ -1023,8 +1019,6 @@ public class SwingEventMonitor extends AWTEventMonitor { } } catch (NoSuchMethodException e) { // System.out.println("Exception: " + e.toString()); - } catch (SecurityException e) { - System.out.println("Exception: " + e.toString()); } break; @@ -1050,8 +1044,6 @@ public class SwingEventMonitor extends AWTEventMonitor { } } catch (NoSuchMethodException e) { // System.out.println("Exception: " + e.toString()); - } catch (SecurityException e) { - System.out.println("Exception: " + e.toString()); } // Look for components which support the getModel method @@ -1078,10 +1070,7 @@ public class SwingEventMonitor extends AWTEventMonitor { } } catch (NoSuchMethodException e) { // System.out.println("Exception: " + e.toString()); - } catch (SecurityException e) { - System.out.println("Exception: " + e.toString()); } - break; case EventID.COLUMNMODEL: @@ -1101,8 +1090,6 @@ public class SwingEventMonitor extends AWTEventMonitor { } } catch (NoSuchMethodException e) { // System.out.println("Exception: " + e.toString()); - } catch (SecurityException e) { - System.out.println("Exception: " + e.toString()); } break; @@ -1126,8 +1113,6 @@ public class SwingEventMonitor extends AWTEventMonitor { } } catch (NoSuchMethodException e) { // System.out.println("Exception: " + e.toString()); - } catch (SecurityException e) { - System.out.println("Exception: " + e.toString()); } // Look for components which support Document listeners @@ -1148,8 +1133,6 @@ public class SwingEventMonitor extends AWTEventMonitor { } } catch (NoSuchMethodException e) { // System.out.println("Exception: " + e.toString()); - } catch (SecurityException e) { - System.out.println("Exception: " + e.toString()); } // Add the monitor as a PropertyChangeListener for document // change events from text components. @@ -1174,8 +1157,6 @@ public class SwingEventMonitor extends AWTEventMonitor { } } catch (NoSuchMethodException e) { // System.out.println("Exception: " + e.toString()); - } catch (SecurityException e) { - System.out.println("Exception: " + e.toString()); } } break; @@ -1210,8 +1191,6 @@ public class SwingEventMonitor extends AWTEventMonitor { } } catch (NoSuchMethodException e) { // System.out.println("Exception: " + e.toString()); - } catch (SecurityException e) { - System.out.println("Exception: " + e.toString()); } break; @@ -1234,8 +1213,6 @@ public class SwingEventMonitor extends AWTEventMonitor { } } catch (NoSuchMethodException e) { // System.out.println("Exception: " + e.toString()); - } catch (SecurityException e) { - System.out.println("Exception: " + e.toString()); } // Look for selection models which support ListSelectionListeners @@ -1257,8 +1234,6 @@ public class SwingEventMonitor extends AWTEventMonitor { } } catch (NoSuchMethodException e) { // System.out.println("Exception: " + e.toString()); - } catch (SecurityException e) { - System.out.println("Exception: " + e.toString()); } break; @@ -1278,8 +1253,6 @@ public class SwingEventMonitor extends AWTEventMonitor { } } catch (NoSuchMethodException e) { // System.out.println("Exception: " + e.toString()); - } catch (SecurityException e) { - System.out.println("Exception: " + e.toString()); } break; @@ -1302,8 +1275,6 @@ public class SwingEventMonitor extends AWTEventMonitor { } } catch (NoSuchMethodException e) { // System.out.println("Exception: " + e.toString()); - } catch (SecurityException e) { - System.out.println("Exception: " + e.toString()); } // Look for components which support getPopupMenu @@ -1329,8 +1300,6 @@ public class SwingEventMonitor extends AWTEventMonitor { } } catch (NoSuchMethodException e) { // System.out.println("Exception: " + e.toString()); - } catch (SecurityException e) { - System.out.println("Exception: " + e.toString()); } break; @@ -1350,8 +1319,6 @@ public class SwingEventMonitor extends AWTEventMonitor { } } catch (NoSuchMethodException e) { // System.out.println("Exception: " + e.toString()); - } catch (SecurityException e) { - System.out.println("Exception: " + e.toString()); } break; @@ -1371,8 +1338,6 @@ public class SwingEventMonitor extends AWTEventMonitor { } } catch (NoSuchMethodException e) { // System.out.println("Exception: " + e.toString()); - } catch (SecurityException e) { - System.out.println("Exception: " + e.toString()); } break; @@ -1396,8 +1361,6 @@ public class SwingEventMonitor extends AWTEventMonitor { } } catch (NoSuchMethodException e) { // System.out.println("Exception: " + e.toString()); - } catch (SecurityException e) { - System.out.println("Exception: " + e.toString()); } // Look for components which support UndoableEdit listeners @@ -1418,8 +1381,6 @@ public class SwingEventMonitor extends AWTEventMonitor { } } catch (NoSuchMethodException e) { // System.out.println("Exception: " + e.toString()); - } catch (SecurityException e) { - System.out.println("Exception: " + e.toString()); } break; @@ -1442,8 +1403,6 @@ public class SwingEventMonitor extends AWTEventMonitor { } } catch (NoSuchMethodException e) { // System.out.println("Exception: " + e.toString()); - } catch (SecurityException e) { - System.out.println("Exception: " + e.toString()); } break; @@ -1466,8 +1425,6 @@ public class SwingEventMonitor extends AWTEventMonitor { } } catch (NoSuchMethodException e) { // System.out.println("Exception: " + e.toString()); - } catch (SecurityException e) { - System.out.println("Exception: " + e.toString()); } // Look for components which support the getSelectionModel method @@ -1489,8 +1446,6 @@ public class SwingEventMonitor extends AWTEventMonitor { } } catch (NoSuchMethodException e) { // System.out.println("Exception: " + e.toString()); - } catch (SecurityException e) { - System.out.println("Exception: " + e.toString()); } break; @@ -1622,8 +1577,6 @@ public class SwingEventMonitor extends AWTEventMonitor { } } catch (NoSuchMethodException e) { // System.out.println("Exception: " + e.toString()); - } catch (SecurityException e) { - System.out.println("Exception: " + e.toString()); } break; @@ -1646,8 +1599,6 @@ public class SwingEventMonitor extends AWTEventMonitor { } } catch (NoSuchMethodException e) { // System.out.println("Exception: " + e.toString()); - } catch (SecurityException e) { - System.out.println("Exception: " + e.toString()); } // Look for components which support CellEditor listeners @@ -1665,8 +1616,6 @@ public class SwingEventMonitor extends AWTEventMonitor { } } catch (NoSuchMethodException e) { // System.out.println("Exception: " + e.toString()); - } catch (SecurityException e) { - System.out.println("Exception: " + e.toString()); } break; @@ -1689,8 +1638,6 @@ public class SwingEventMonitor extends AWTEventMonitor { } } catch (NoSuchMethodException e) { // System.out.println("Exception: " + e.toString()); - } catch (SecurityException e) { - System.out.println("Exception: " + e.toString()); } // Look for components which support the getModel method @@ -1714,8 +1661,6 @@ public class SwingEventMonitor extends AWTEventMonitor { } } catch (NoSuchMethodException e) { // System.out.println("Exception: " + e.toString()); - } catch (SecurityException e) { - System.out.println("Exception: " + e.toString()); } break; @@ -1735,8 +1680,6 @@ public class SwingEventMonitor extends AWTEventMonitor { } } catch (NoSuchMethodException e) { // System.out.println("Exception: " + e.toString()); - } catch (SecurityException e) { - System.out.println("Exception: " + e.toString()); } break; @@ -1759,8 +1702,6 @@ public class SwingEventMonitor extends AWTEventMonitor { } } catch (NoSuchMethodException e) { // System.out.println("Exception: " + e.toString()); - } catch (SecurityException e) { - System.out.println("Exception: " + e.toString()); } // Look for components which support Document listeners @@ -1778,8 +1719,6 @@ public class SwingEventMonitor extends AWTEventMonitor { } } catch (NoSuchMethodException e) { // System.out.println("Exception: " + e.toString()); - } catch (SecurityException e) { - System.out.println("Exception: " + e.toString()); } break; @@ -1810,8 +1749,6 @@ public class SwingEventMonitor extends AWTEventMonitor { } } catch (NoSuchMethodException e) { // System.out.println("Exception: " + e.toString()); - } catch (SecurityException e) { - System.out.println("Exception: " + e.toString()); } break; @@ -1831,8 +1768,6 @@ public class SwingEventMonitor extends AWTEventMonitor { } } catch (NoSuchMethodException e) { // System.out.println("Exception: " + e.toString()); - } catch (SecurityException e) { - System.out.println("Exception: " + e.toString()); } // Look for selection models which support @@ -1853,8 +1788,6 @@ public class SwingEventMonitor extends AWTEventMonitor { } } catch (NoSuchMethodException e) { // System.out.println("Exception: " + e.toString()); - } catch (SecurityException e) { - System.out.println("Exception: " + e.toString()); } break; @@ -1871,8 +1804,6 @@ public class SwingEventMonitor extends AWTEventMonitor { } } catch (NoSuchMethodException e) { // System.out.println("Exception: " + e.toString()); - } catch (SecurityException e) { - System.out.println("Exception: " + e.toString()); } break; @@ -1892,8 +1823,6 @@ public class SwingEventMonitor extends AWTEventMonitor { } } catch (NoSuchMethodException e) { // System.out.println("Exception: " + e.toString()); - } catch (SecurityException e) { - System.out.println("Exception: " + e.toString()); } // Look for components which support getPopupMenu @@ -1916,8 +1845,6 @@ public class SwingEventMonitor extends AWTEventMonitor { } } catch (NoSuchMethodException e) { // System.out.println("Exception: " + e.toString()); - } catch (SecurityException e) { - System.out.println("Exception: " + e.toString()); } break; @@ -1934,8 +1861,6 @@ public class SwingEventMonitor extends AWTEventMonitor { } } catch (NoSuchMethodException e) { // System.out.println("Exception: " + e.toString()); - } catch (SecurityException e) { - System.out.println("Exception: " + e.toString()); } break; @@ -1952,8 +1877,6 @@ public class SwingEventMonitor extends AWTEventMonitor { } } catch (NoSuchMethodException e) { // System.out.println("Exception: " + e.toString()); - } catch (SecurityException e) { - System.out.println("Exception: " + e.toString()); } break; @@ -1976,8 +1899,6 @@ public class SwingEventMonitor extends AWTEventMonitor { } } catch (NoSuchMethodException e) { // System.out.println("Exception: " + e.toString()); - } catch (SecurityException e) { - System.out.println("Exception: " + e.toString()); } // Look for components which support UndoableEdit listeners @@ -1995,8 +1916,6 @@ public class SwingEventMonitor extends AWTEventMonitor { } } catch (NoSuchMethodException e) { // System.out.println("Exception: " + e.toString()); - } catch (SecurityException e) { - System.out.println("Exception: " + e.toString()); } break; @@ -2013,8 +1932,6 @@ public class SwingEventMonitor extends AWTEventMonitor { } } catch (NoSuchMethodException e) { // System.out.println("Exception: " + e.toString()); - } catch (SecurityException e) { - System.out.println("Exception: " + e.toString()); } break; @@ -2034,8 +1951,6 @@ public class SwingEventMonitor extends AWTEventMonitor { } } catch (NoSuchMethodException e) { // System.out.println("Exception: " + e.toString()); - } catch (SecurityException e) { - System.out.println("Exception: " + e.toString()); } // Look for components which support the getSelectionModel @@ -2056,8 +1971,6 @@ public class SwingEventMonitor extends AWTEventMonitor { } } catch (NoSuchMethodException e) { // System.out.println("Exception: " + e.toString()); - } catch (SecurityException e) { - System.out.println("Exception: " + e.toString()); } break; @@ -2512,8 +2425,6 @@ public class SwingEventMonitor extends AWTEventMonitor { } } catch (NoSuchMethodException e2) { // System.out.println("Exception: " + e2.toString()); - } catch (SecurityException e2) { - System.out.println("Exception: " + e2.toString()); } } diff --git a/src/jdk.accessibility/windows/classes/com/sun/java/accessibility/internal/AccessBridge.java b/src/jdk.accessibility/windows/classes/com/sun/java/accessibility/internal/AccessBridge.java index b5a5943d2d9..e6792b3ef10 100644 --- a/src/jdk.accessibility/windows/classes/com/sun/java/accessibility/internal/AccessBridge.java +++ b/src/jdk.accessibility/windows/classes/com/sun/java/accessibility/internal/AccessBridge.java @@ -160,44 +160,23 @@ public final class AccessBridge { initStatic(); } - @SuppressWarnings({"removal", "restricted"}) + @SuppressWarnings("restricted") private static void initStatic() { // Load the appropriate DLLs boolean is32on64 = false; if (System.getProperty("os.arch").equals("x86")) { // 32 bit JRE // Load jabsysinfo.dll so can determine Win bitness - java.security.AccessController.doPrivileged( - new java.security.PrivilegedAction() { - public Void run() { - System.loadLibrary("jabsysinfo"); - return null; - } - }, null, new java.lang.RuntimePermission("loadLibrary.jabsysinfo") - ); + System.loadLibrary("jabsysinfo"); if (isSysWow()) { // 32 bit JRE on 64 bit OS is32on64 = true; - java.security.AccessController.doPrivileged( - new java.security.PrivilegedAction() { - public Void run() { - System.loadLibrary("javaaccessbridge-32"); - return null; - } - }, null, new java.lang.RuntimePermission("loadLibrary.javaaccessbridge-32") - ); + System.loadLibrary("javaaccessbridge-32"); } } if (!is32on64) { // 32 bit JRE on 32 bit OS or 64 bit JRE on 64 bit OS - java.security.AccessController.doPrivileged( - new java.security.PrivilegedAction() { - public Void run() { - System.loadLibrary("javaaccessbridge"); - return null; - } - }, null, new java.lang.RuntimePermission("loadLibrary.javaaccessbridge") - ); + System.loadLibrary("javaaccessbridge"); } }