From 92271af6358d38a49b02fb02020f9459c55fca26 Mon Sep 17 00:00:00 2001 From: Harshitha Onkar Date: Mon, 18 Nov 2024 19:19:51 +0000 Subject: [PATCH] 8344058: Remove doPrivileged calls from macos platform sources in the java.desktop module Reviewed-by: prr, aivanov --- .../macosx/classes/apple/laf/JRSUIUtils.java | 6 +- .../classes/com/apple/eio/FileManager.java | 10 +-- .../classes/com/apple/laf/AquaFileView.java | 10 +-- .../com/apple/laf/AquaImageFactory.java | 16 +--- .../com/apple/laf/AquaLookAndFeel.java | 18 +--- .../classes/com/apple/laf/AquaMenuBarUI.java | 13 +-- .../com/apple/laf/AquaNativeResources.java | 10 +-- .../com/apple/laf/AquaUtilControlSize.java | 6 +- .../classes/com/apple/laf/AquaUtils.java | 31 ++----- .../classes/com/apple/laf/ScreenMenu.java | 10 +-- .../classes/sun/awt/PlatformGraphicsInfo.java | 7 +- .../macosx/classes/sun/font/CFontManager.java | 26 ++---- .../macosx/classes/sun/java2d/MacOSFlags.java | 89 +++++++++---------- .../sun/java2d/metal/MTLGraphicsConfig.java | 9 +- .../sun/java2d/metal/MTLRenderQueue.java | 6 +- .../classes/sun/lwawt/LWComponentPeer.java | 45 ++++------ .../macosx/classes/sun/lwawt/LWToolkit.java | 35 ++++---- .../sun/lwawt/macosx/CAccessibility.java | 10 +-- .../lwawt/macosx/CDragSourceContextPeer.java | 3 +- .../classes/sun/lwawt/macosx/CFileDialog.java | 10 +-- .../sun/lwawt/macosx/CPlatformWindow.java | 6 +- .../classes/sun/lwawt/macosx/CPrinterJob.java | 12 +-- .../classes/sun/lwawt/macosx/CTrayIcon.java | 7 +- .../classes/sun/lwawt/macosx/LWCToolkit.java | 56 ++++-------- 24 files changed, 136 insertions(+), 315 deletions(-) diff --git a/src/java.desktop/macosx/classes/apple/laf/JRSUIUtils.java b/src/java.desktop/macosx/classes/apple/laf/JRSUIUtils.java index bed22b8d4ee..d6c051c17ab 100644 --- a/src/java.desktop/macosx/classes/apple/laf/JRSUIUtils.java +++ b/src/java.desktop/macosx/classes/apple/laf/JRSUIUtils.java @@ -25,12 +25,9 @@ package apple.laf; -import java.security.AccessController; - import apple.laf.JRSUIConstants.Hit; import apple.laf.JRSUIConstants.ScrollBarPart; import com.apple.laf.AquaImageFactory.NineSliceMetrics; -import sun.security.action.GetPropertyAction; public final class JRSUIUtils { @@ -69,8 +66,7 @@ public final class JRSUIUtils { final int majorVersion, final int minorVersion, final boolean inclusive, final boolean matchBelow, final boolean matchAbove) { // split the "x.y.z" version number - @SuppressWarnings("removal") - String osVersion = AccessController.doPrivileged(new GetPropertyAction("os.version")); + String osVersion = System.getProperty("os.version"); String[] fragments = osVersion.split("\\."); if (fragments.length < 2) return false; diff --git a/src/java.desktop/macosx/classes/com/apple/eio/FileManager.java b/src/java.desktop/macosx/classes/com/apple/eio/FileManager.java index 1a77ddd7600..5449e3ff9e2 100644 --- a/src/java.desktop/macosx/classes/com/apple/eio/FileManager.java +++ b/src/java.desktop/macosx/classes/com/apple/eio/FileManager.java @@ -58,15 +58,9 @@ public class FileManager { loadOSXLibrary(); } - @SuppressWarnings({"removal", "restricted"}) + @SuppressWarnings("restricted") private static void loadOSXLibrary() { - java.security.AccessController.doPrivileged( - new java.security.PrivilegedAction() { - public Void run() { - System.loadLibrary("osx"); - return null; - } - }); + System.loadLibrary("osx"); } /** diff --git a/src/java.desktop/macosx/classes/com/apple/laf/AquaFileView.java b/src/java.desktop/macosx/classes/com/apple/laf/AquaFileView.java index 34e5b7c9b7c..32b43dba295 100644 --- a/src/java.desktop/macosx/classes/com/apple/laf/AquaFileView.java +++ b/src/java.desktop/macosx/classes/com/apple/laf/AquaFileView.java @@ -65,15 +65,9 @@ class AquaFileView extends FileView { loadOSXUILibrary(); } - @SuppressWarnings({"removal", "restricted"}) + @SuppressWarnings("restricted") private static void loadOSXUILibrary() { - java.security.AccessController.doPrivileged( - new java.security.PrivilegedAction() { - public Void run() { - System.loadLibrary("osxui"); - return null; - } - }); + System.loadLibrary("osxui"); } // TODO: Un-comment this out when the native version exists diff --git a/src/java.desktop/macosx/classes/com/apple/laf/AquaImageFactory.java b/src/java.desktop/macosx/classes/com/apple/laf/AquaImageFactory.java index 2fddf6483a5..9cf3b920f91 100644 --- a/src/java.desktop/macosx/classes/com/apple/laf/AquaImageFactory.java +++ b/src/java.desktop/macosx/classes/com/apple/laf/AquaImageFactory.java @@ -27,11 +27,11 @@ package com.apple.laf; import java.awt.*; import java.awt.image.BufferedImage; -import java.security.PrivilegedAction; import javax.swing.*; import javax.swing.plaf.*; +import com.apple.eawt.Application; import sun.lwawt.macosx.LWCToolkit; import apple.laf.JRSUIConstants.AlignmentHorizontal; import apple.laf.JRSUIConstants.AlignmentVertical; @@ -82,22 +82,12 @@ public class AquaImageFactory { return getAppIconCompositedOn(lockIcon); } - @SuppressWarnings("removal") static Image getGenericJavaIcon() { - return java.security.AccessController.doPrivileged(new PrivilegedAction() { - public Image run() { - return com.apple.eawt.Application.getApplication().getDockIconImage(); - } - }); + return Application.getApplication().getDockIconImage(); } - @SuppressWarnings("removal") static String getPathToThisApplication() { - return java.security.AccessController.doPrivileged(new PrivilegedAction() { - public String run() { - return FileManager.getPathToApplicationBundle(); - } - }); + return FileManager.getPathToApplicationBundle(); } static IconUIResource getAppIconCompositedOn(final SystemIcon systemIcon) { diff --git a/src/java.desktop/macosx/classes/com/apple/laf/AquaLookAndFeel.java b/src/java.desktop/macosx/classes/com/apple/laf/AquaLookAndFeel.java index 9748f900827..34a39525a74 100644 --- a/src/java.desktop/macosx/classes/com/apple/laf/AquaLookAndFeel.java +++ b/src/java.desktop/macosx/classes/com/apple/laf/AquaLookAndFeel.java @@ -154,22 +154,10 @@ public class AquaLookAndFeel extends BasicLookAndFeel { * @see #uninitialize * @see UIManager#setLookAndFeel */ - @SuppressWarnings({"removal", "restricted"}) + @SuppressWarnings("restricted") public void initialize() { - java.security.AccessController.doPrivileged(new PrivilegedAction() { - public Void run() { - System.loadLibrary("osxui"); - return null; - } - }); - - java.security.AccessController.doPrivileged(new PrivilegedAction(){ - @Override - public Void run() { - JRSUIControl.initJRSUI(); - return null; - } - }); + System.loadLibrary("osxui"); + JRSUIControl.initJRSUI(); super.initialize(); final ScreenPopupFactory spf = new ScreenPopupFactory(); diff --git a/src/java.desktop/macosx/classes/com/apple/laf/AquaMenuBarUI.java b/src/java.desktop/macosx/classes/com/apple/laf/AquaMenuBarUI.java index f252e310750..1c9ad2c929d 100644 --- a/src/java.desktop/macosx/classes/com/apple/laf/AquaMenuBarUI.java +++ b/src/java.desktop/macosx/classes/com/apple/laf/AquaMenuBarUI.java @@ -29,7 +29,6 @@ import java.awt.Component; import java.awt.Dimension; import java.awt.Graphics; import java.awt.MenuBar; -import java.security.AccessController; import javax.swing.JComponent; import javax.swing.JFrame; @@ -38,18 +37,13 @@ import javax.swing.plaf.ComponentUI; import javax.swing.plaf.basic.BasicMenuBarUI; import sun.lwawt.macosx.LWCToolkit; -import sun.security.action.GetBooleanAction; // MenuBar implementation for Mac L&F -@SuppressWarnings({"removal", "restricted"}) +@SuppressWarnings("restricted") public class AquaMenuBarUI extends BasicMenuBarUI implements ScreenMenuBarProvider { static { - java.security.AccessController.doPrivileged( - (java.security.PrivilegedAction) () -> { - System.loadLibrary("osxui"); - return null; - }); + System.loadLibrary("osxui"); } // Utilities @@ -151,7 +145,6 @@ public class AquaMenuBarUI extends BasicMenuBarUI implements ScreenMenuBarProvid public static boolean getScreenMenuBarProperty() { // Do not allow AWT to set the screen menu bar if it's embedded in another UI toolkit if (LWCToolkit.isEmbedded()) return false; - return AccessController.doPrivileged(new GetBooleanAction( - AquaLookAndFeel.sPropertyPrefix + "useScreenMenuBar")); + return Boolean.getBoolean(AquaLookAndFeel.sPropertyPrefix + "useScreenMenuBar"); } } diff --git a/src/java.desktop/macosx/classes/com/apple/laf/AquaNativeResources.java b/src/java.desktop/macosx/classes/com/apple/laf/AquaNativeResources.java index a8abf1a6cd8..ee813fc7104 100644 --- a/src/java.desktop/macosx/classes/com/apple/laf/AquaNativeResources.java +++ b/src/java.desktop/macosx/classes/com/apple/laf/AquaNativeResources.java @@ -32,16 +32,10 @@ import javax.swing.plaf.UIResource; import com.apple.laf.AquaUtils.RecyclableSingleton; -@SuppressWarnings({"removal", "restricted"}) +@SuppressWarnings("restricted") public class AquaNativeResources { static { - java.security.AccessController.doPrivileged( - new java.security.PrivilegedAction() { - public Void run() { - System.loadLibrary("osxui"); - return null; - } - }); + System.loadLibrary("osxui"); } // TODO: removing CColorPaint for now diff --git a/src/java.desktop/macosx/classes/com/apple/laf/AquaUtilControlSize.java b/src/java.desktop/macosx/classes/com/apple/laf/AquaUtilControlSize.java index 0bd1ce9609d..51b02a7f5d4 100644 --- a/src/java.desktop/macosx/classes/com/apple/laf/AquaUtilControlSize.java +++ b/src/java.desktop/macosx/classes/com/apple/laf/AquaUtilControlSize.java @@ -27,7 +27,6 @@ package com.apple.laf; import java.awt.*; import java.beans.*; -import java.security.AccessController; import javax.swing.*; import javax.swing.border.Border; @@ -38,7 +37,6 @@ import apple.laf.JRSUIConstants.*; import com.apple.laf.AquaUtils.RecyclableSingleton; import com.apple.laf.AquaUtils.RecyclableSingletonFromDefaultConstructor; -import sun.security.action.GetPropertyAction; public class AquaUtilControlSize { protected static final String CLIENT_PROPERTY_KEY = "JComponent.sizeVariant"; @@ -72,9 +70,7 @@ public class AquaUtilControlSize { } private static Size getDefaultSize() { - @SuppressWarnings("removal") - final String sizeProperty = AccessController.doPrivileged( - new GetPropertyAction(SYSTEM_PROPERTY_KEY)); + final String sizeProperty = System.getProperty(SYSTEM_PROPERTY_KEY); final JRSUIConstants.Size size = getSizeFromString(sizeProperty); if (size != null) return size; return JRSUIConstants.Size.REGULAR; diff --git a/src/java.desktop/macosx/classes/com/apple/laf/AquaUtils.java b/src/java.desktop/macosx/classes/com/apple/laf/AquaUtils.java index 712f597f9ef..d40d50b1b5c 100644 --- a/src/java.desktop/macosx/classes/com/apple/laf/AquaUtils.java +++ b/src/java.desktop/macosx/classes/com/apple/laf/AquaUtils.java @@ -29,8 +29,6 @@ import java.awt.*; import java.awt.image.*; import java.lang.ref.SoftReference; import java.lang.reflect.Method; -import java.security.AccessController; -import java.security.PrivilegedAction; import java.util.*; import javax.swing.*; @@ -41,7 +39,6 @@ import sun.awt.AppContext; import sun.lwawt.macosx.CPlatformWindow; import sun.reflect.misc.ReflectUtil; -import sun.security.action.GetPropertyAction; import sun.swing.SwingUtilities2; import com.apple.laf.AquaImageFactory.SlicedImageControl; @@ -205,9 +202,7 @@ final class AquaUtils { private static final RecyclableSingleton enableAnimations = new RecyclableSingleton() { @Override protected Boolean getInstance() { - @SuppressWarnings("removal") - final String sizeProperty = (String) AccessController.doPrivileged((PrivilegedAction)new GetPropertyAction( - ANIMATIONS_PROPERTY)); + final String sizeProperty = System.getProperty(ANIMATIONS_PROPERTY); return !"false".equals(sizeProperty); // should be true by default } }; @@ -332,25 +327,17 @@ final class AquaUtils { } } - @SuppressWarnings("removal") private static final RecyclableSingleton getJComponentGetFlagMethod = new RecyclableSingleton() { @Override protected Method getInstance() { - return AccessController.doPrivileged( - new PrivilegedAction() { - @Override - public Method run() { - try { - final Method method = JComponent.class.getDeclaredMethod( - "getFlag", new Class[] { int.class }); - method.setAccessible(true); - return method; - } catch (final Throwable ignored) { - return null; - } - } - } - ); + try { + final Method method = JComponent.class.getDeclaredMethod( + "getFlag", new Class[]{int.class}); + method.setAccessible(true); + return method; + } catch (final Throwable ignored) { + return null; + } } }; diff --git a/src/java.desktop/macosx/classes/com/apple/laf/ScreenMenu.java b/src/java.desktop/macosx/classes/com/apple/laf/ScreenMenu.java index d8d0928c55f..ef4e4c5707a 100644 --- a/src/java.desktop/macosx/classes/com/apple/laf/ScreenMenu.java +++ b/src/java.desktop/macosx/classes/com/apple/laf/ScreenMenu.java @@ -45,15 +45,9 @@ final class ScreenMenu extends Menu loadAWTLibrary(); } - @SuppressWarnings({"removal", "restricted"}) + @SuppressWarnings("restricted") private static void loadAWTLibrary() { - java.security.AccessController.doPrivileged( - new java.security.PrivilegedAction() { - public Void run() { - System.loadLibrary("awt"); - return null; - } - }); + System.loadLibrary("awt"); } // screen menu stuff diff --git a/src/java.desktop/macosx/classes/sun/awt/PlatformGraphicsInfo.java b/src/java.desktop/macosx/classes/sun/awt/PlatformGraphicsInfo.java index 6af002fc04f..571bc5c5479 100644 --- a/src/java.desktop/macosx/classes/sun/awt/PlatformGraphicsInfo.java +++ b/src/java.desktop/macosx/classes/sun/awt/PlatformGraphicsInfo.java @@ -27,17 +27,12 @@ package sun.awt; import java.awt.GraphicsEnvironment; import java.awt.Toolkit; -import java.security.AccessController; -import java.security.PrivilegedAction; -@SuppressWarnings({"removal", "restricted"}) +@SuppressWarnings({"restricted"}) public class PlatformGraphicsInfo { static { - AccessController.doPrivileged((PrivilegedAction) () -> { System.loadLibrary("awt"); - return null; - }); } public static GraphicsEnvironment createGE() { diff --git a/src/java.desktop/macosx/classes/sun/font/CFontManager.java b/src/java.desktop/macosx/classes/sun/font/CFontManager.java index baab3257153..f9455a6d102 100644 --- a/src/java.desktop/macosx/classes/sun/font/CFontManager.java +++ b/src/java.desktop/macosx/classes/sun/font/CFontManager.java @@ -27,8 +27,6 @@ package sun.font; import java.awt.*; import java.io.File; -import java.security.AccessController; -import java.security.PrivilegedAction; import java.util.ArrayList; import java.util.HashMap; import java.util.Hashtable; @@ -147,10 +145,7 @@ public final class CFontManager extends SunFontManager { protected void registerFontsInDir(final String dirName, boolean useJavaRasterizer, int fontRank, boolean defer, boolean resolveSymLinks) { - @SuppressWarnings("removal") - String[] files = AccessController.doPrivileged((PrivilegedAction) () -> { - return new File(dirName).list(getTrueTypeFilter()); - }); + String[] files = new File(dirName).list(getTrueTypeFilter()); if (files == null) { return; @@ -205,24 +200,17 @@ public final class CFontManager extends SunFontManager { Object waitForFontsToBeLoaded = new Object(); private boolean loadedAllFonts = false; - @SuppressWarnings("removal") + public void loadFonts() { synchronized(waitForFontsToBeLoaded) { super.loadFonts(); - java.security.AccessController.doPrivileged( - new java.security.PrivilegedAction() { - public Object run() { - if (!loadedAllFonts) { - loadNativeFonts(); - registerItalicDerived(); - loadedAllFonts = true; - } - return null; - } - } - ); + if (!loadedAllFonts) { + loadNativeFonts(); + registerItalicDerived(); + loadedAllFonts = true; + } String defaultFont = "Lucida Grande"; String defaultFallback = "Lucida Grande"; diff --git a/src/java.desktop/macosx/classes/sun/java2d/MacOSFlags.java b/src/java.desktop/macosx/classes/sun/java2d/MacOSFlags.java index 37b573a339b..033b9ad8362 100644 --- a/src/java.desktop/macosx/classes/sun/java2d/MacOSFlags.java +++ b/src/java.desktop/macosx/classes/sun/java2d/MacOSFlags.java @@ -25,7 +25,6 @@ package sun.java2d; -import java.security.PrivilegedAction; import sun.java2d.metal.MTLGraphicsConfig; import sun.java2d.opengl.CGLGraphicsConfig; @@ -83,59 +82,53 @@ public class MacOSFlags { return false; } - @SuppressWarnings("removal") private static void initJavaFlags() { - java.security.AccessController.doPrivileged( - (PrivilegedAction) () -> { - PropertyState oglState = getBooleanProp("sun.java2d.opengl", PropertyState.UNSPECIFIED); - PropertyState metalState = getBooleanProp("sun.java2d.metal", PropertyState.UNSPECIFIED); + PropertyState oglState = getBooleanProp("sun.java2d.opengl", PropertyState.UNSPECIFIED); + PropertyState metalState = getBooleanProp("sun.java2d.metal", PropertyState.UNSPECIFIED); - // Handle invalid combinations to use the default rendering pipeline - // The default rendering pipeline is Metal - if ((oglState == PropertyState.UNSPECIFIED && metalState == PropertyState.UNSPECIFIED) || - (oglState == PropertyState.DISABLED && metalState == PropertyState.DISABLED) || - (oglState == PropertyState.ENABLED && metalState == PropertyState.ENABLED)) { - metalState = PropertyState.ENABLED; // Enable default pipeline - oglState = PropertyState.DISABLED; // Disable non-default pipeline - } + // Handle invalid combinations to use the default rendering pipeline + // The default rendering pipeline is Metal + if ((oglState == PropertyState.UNSPECIFIED && metalState == PropertyState.UNSPECIFIED) || + (oglState == PropertyState.DISABLED && metalState == PropertyState.DISABLED) || + (oglState == PropertyState.ENABLED && metalState == PropertyState.ENABLED)) { + metalState = PropertyState.ENABLED; // Enable default pipeline + oglState = PropertyState.DISABLED; // Disable non-default pipeline + } - if (metalState == PropertyState.UNSPECIFIED) { - if (oglState == PropertyState.DISABLED) { - oglEnabled = false; - metalEnabled = true; - } else { - oglEnabled = true; - metalEnabled = false; - } - } else if (metalState == PropertyState.ENABLED) { - oglEnabled = false; - metalEnabled = true; - } else if (metalState == PropertyState.DISABLED) { - oglEnabled = true; - metalEnabled = false; - } + if (metalState == PropertyState.UNSPECIFIED) { + if (oglState == PropertyState.DISABLED) { + oglEnabled = false; + metalEnabled = true; + } else { + oglEnabled = true; + metalEnabled = false; + } + } else if (metalState == PropertyState.ENABLED) { + oglEnabled = false; + metalEnabled = true; + } else if (metalState == PropertyState.DISABLED) { + oglEnabled = true; + metalEnabled = false; + } - oglVerbose = isBooleanPropTrueVerbose("sun.java2d.opengl"); - metalVerbose = isBooleanPropTrueVerbose("sun.java2d.metal"); + oglVerbose = isBooleanPropTrueVerbose("sun.java2d.opengl"); + metalVerbose = isBooleanPropTrueVerbose("sun.java2d.metal"); - if (oglEnabled && !metalEnabled) { - // Check whether OGL is available - if (!CGLGraphicsConfig.isCGLAvailable()) { - if (oglVerbose) { - System.out.println("Could not enable OpenGL pipeline (CGL not available)"); - } - oglEnabled = false; - metalEnabled = true; - } - } + if (oglEnabled && !metalEnabled) { + // Check whether OGL is available + if (!CGLGraphicsConfig.isCGLAvailable()) { + if (oglVerbose) { + System.out.println("Could not enable OpenGL pipeline (CGL not available)"); + } + oglEnabled = false; + metalEnabled = true; + } + } - // At this point one of the rendering pipeline must be enabled. - if (!metalEnabled && !oglEnabled) { - throw new InternalError("Error - unable to initialize any rendering pipeline."); - } - - return null; - }); + // At this point one of the rendering pipeline must be enabled. + if (!metalEnabled && !oglEnabled) { + throw new InternalError("Error - unable to initialize any rendering pipeline."); + } } public static boolean isMetalEnabled() { diff --git a/src/java.desktop/macosx/classes/sun/java2d/metal/MTLGraphicsConfig.java b/src/java.desktop/macosx/classes/sun/java2d/metal/MTLGraphicsConfig.java index 2b70c39146b..f3867ce88c1 100644 --- a/src/java.desktop/macosx/classes/sun/java2d/metal/MTLGraphicsConfig.java +++ b/src/java.desktop/macosx/classes/sun/java2d/metal/MTLGraphicsConfig.java @@ -58,8 +58,6 @@ import java.awt.image.DirectColorModel; import java.awt.image.VolatileImage; import java.awt.image.WritableRaster; import java.io.File; -import java.security.AccessController; -import java.security.PrivilegedAction; import static sun.java2d.metal.MTLContext.MTLContextCaps.CAPS_EXT_GRAD_SHADER; import static sun.java2d.pipe.hw.AccelSurface.TEXTURE; @@ -73,11 +71,10 @@ public final class MTLGraphicsConfig extends CGraphicsConfig { private static ImageCapabilities imageCaps = new MTLImageCaps(); - @SuppressWarnings("removal") - private static final String mtlShadersLib = AccessController.doPrivileged( - (PrivilegedAction) () -> + + private static final String mtlShadersLib = System.getProperty("java.home", "") + File.separator + - "lib" + File.separator + "shaders.metallib"); + "lib" + File.separator + "shaders.metallib"; private BufferCapabilities bufferCaps; diff --git a/src/java.desktop/macosx/classes/sun/java2d/metal/MTLRenderQueue.java b/src/java.desktop/macosx/classes/sun/java2d/metal/MTLRenderQueue.java index 57b412f5b13..7970aa919f1 100644 --- a/src/java.desktop/macosx/classes/sun/java2d/metal/MTLRenderQueue.java +++ b/src/java.desktop/macosx/classes/sun/java2d/metal/MTLRenderQueue.java @@ -29,9 +29,6 @@ import sun.awt.util.ThreadGroupUtils; import sun.java2d.pipe.RenderBuffer; import sun.java2d.pipe.RenderQueue; -import java.security.AccessController; -import java.security.PrivilegedAction; - import static sun.java2d.pipe.BufferedOpCodes.DISPOSE_CONFIG; import static sun.java2d.pipe.BufferedOpCodes.SYNC; @@ -46,13 +43,12 @@ public class MTLRenderQueue extends RenderQueue { private static MTLRenderQueue theInstance; private final QueueFlusher flusher; - @SuppressWarnings("removal") private MTLRenderQueue() { /* * The thread must be a member of a thread group * which will not get GCed before VM exit. */ - flusher = AccessController.doPrivileged((PrivilegedAction) QueueFlusher::new); + flusher = new QueueFlusher(); } /** diff --git a/src/java.desktop/macosx/classes/sun/lwawt/LWComponentPeer.java b/src/java.desktop/macosx/classes/sun/lwawt/LWComponentPeer.java index f37e4ad7425..b487b14fd79 100644 --- a/src/java.desktop/macosx/classes/sun/lwawt/LWComponentPeer.java +++ b/src/java.desktop/macosx/classes/sun/lwawt/LWComponentPeer.java @@ -58,8 +58,6 @@ import java.awt.peer.ComponentPeer; import java.awt.peer.ContainerPeer; import java.awt.peer.KeyboardFocusManagerPeer; import java.lang.reflect.Field; -import java.security.AccessController; -import java.security.PrivilegedAction; import java.util.concurrent.atomic.AtomicBoolean; import javax.swing.JComponent; @@ -260,37 +258,26 @@ public abstract class LWComponentPeer * This method must be called under Toolkit.getDefaultToolkit() lock * and followed by setToolkitAWTEventListener() */ - @SuppressWarnings("removal") protected final AWTEventListener getToolkitAWTEventListener() { - return AccessController.doPrivileged(new PrivilegedAction() { - public AWTEventListener run() { - Toolkit toolkit = Toolkit.getDefaultToolkit(); - try { - Field field = Toolkit.class.getDeclaredField("eventListener"); - field.setAccessible(true); - return (AWTEventListener) field.get(toolkit); - } catch (Exception e) { - throw new InternalError(e.toString()); - } - } - }); + Toolkit toolkit = Toolkit.getDefaultToolkit(); + try { + Field field = Toolkit.class.getDeclaredField("eventListener"); + field.setAccessible(true); + return (AWTEventListener) field.get(toolkit); + } catch (Exception e) { + throw new InternalError(e.toString()); + } } - @SuppressWarnings("removal") protected final void setToolkitAWTEventListener(final AWTEventListener listener) { - AccessController.doPrivileged(new PrivilegedAction() { - public Void run() { - Toolkit toolkit = Toolkit.getDefaultToolkit(); - try { - Field field = Toolkit.class.getDeclaredField("eventListener"); - field.setAccessible(true); - field.set(toolkit, listener); - } catch (Exception e) { - throw new InternalError(e.toString()); - } - return null; - } - }); + Toolkit toolkit = Toolkit.getDefaultToolkit(); + try { + Field field = Toolkit.class.getDeclaredField("eventListener"); + field.setAccessible(true); + field.set(toolkit, listener); + } catch (Exception e) { + throw new InternalError(e.toString()); + } } /** diff --git a/src/java.desktop/macosx/classes/sun/lwawt/LWToolkit.java b/src/java.desktop/macosx/classes/sun/lwawt/LWToolkit.java index 6f38e62c46d..9a08fae9f4e 100644 --- a/src/java.desktop/macosx/classes/sun/lwawt/LWToolkit.java +++ b/src/java.desktop/macosx/classes/sun/lwawt/LWToolkit.java @@ -31,7 +31,6 @@ import java.awt.datatransfer.*; import java.awt.dnd.DropTarget; import java.awt.image.*; import java.awt.peer.*; -import java.security.*; import java.util.*; import sun.awt.*; @@ -69,27 +68,23 @@ public abstract class LWToolkit extends SunToolkit implements Runnable { * This method waits for the toolkit to be completely initialized * and returns before the message pump is started. */ - @SuppressWarnings("removal") protected final void init() { AWTAutoShutdown.notifyToolkitThreadBusy(); - AccessController.doPrivileged((PrivilegedAction) () -> { - Runnable shutdownRunnable = () -> { - shutdown(); - waitForRunState(STATE_CLEANUP); - }; - Thread shutdown = new Thread( - ThreadGroupUtils.getRootThreadGroup(), shutdownRunnable, - "AWT-Shutdown", 0, false); - shutdown.setContextClassLoader(null); - Runtime.getRuntime().addShutdownHook(shutdown); - String name = "AWT-LW"; - Thread toolkitThread = new Thread( - ThreadGroupUtils.getRootThreadGroup(), this, name, 0, false); - toolkitThread.setDaemon(true); - toolkitThread.setPriority(Thread.NORM_PRIORITY + 1); - toolkitThread.start(); - return null; - }); + Runnable shutdownRunnable = () -> { + shutdown(); + waitForRunState(STATE_CLEANUP); + }; + Thread shutdown = new Thread( + ThreadGroupUtils.getRootThreadGroup(), shutdownRunnable, + "AWT-Shutdown", 0, false); + shutdown.setContextClassLoader(null); + Runtime.getRuntime().addShutdownHook(shutdown); + String name = "AWT-LW"; + Thread toolkitThread = new Thread( + ThreadGroupUtils.getRootThreadGroup(), this, name, 0, false); + toolkitThread.setDaemon(true); + toolkitThread.setPriority(Thread.NORM_PRIORITY + 1); + toolkitThread.start(); waitForRunState(STATE_MESSAGELOOP); } diff --git a/src/java.desktop/macosx/classes/sun/lwawt/macosx/CAccessibility.java b/src/java.desktop/macosx/classes/sun/lwawt/macosx/CAccessibility.java index 436ab6138fa..417750507aa 100644 --- a/src/java.desktop/macosx/classes/sun/lwawt/macosx/CAccessibility.java +++ b/src/java.desktop/macosx/classes/sun/lwawt/macosx/CAccessibility.java @@ -77,16 +77,10 @@ class CAccessibility implements PropertyChangeListener { loadAWTLibrary(); } - @SuppressWarnings({"removal", "restricted"}) + @SuppressWarnings("restricted") private static void loadAWTLibrary() { // Need to load the native library for this code. - java.security.AccessController.doPrivileged( - new java.security.PrivilegedAction() { - public Void run() { - System.loadLibrary("awt"); - return null; - } - }); + System.loadLibrary("awt"); } static CAccessibility sAccessibility; diff --git a/src/java.desktop/macosx/classes/sun/lwawt/macosx/CDragSourceContextPeer.java b/src/java.desktop/macosx/classes/sun/lwawt/macosx/CDragSourceContextPeer.java index dbf595a55e1..c36cdd27f3f 100644 --- a/src/java.desktop/macosx/classes/sun/lwawt/macosx/CDragSourceContextPeer.java +++ b/src/java.desktop/macosx/classes/sun/lwawt/macosx/CDragSourceContextPeer.java @@ -59,8 +59,7 @@ public final class CDragSourceContextPeer extends SunDragSourceContextPeer { private static double fMaxImageSize = 128.0; static { - @SuppressWarnings("removal") - String propValue = java.security.AccessController.doPrivileged(new sun.security.action.GetPropertyAction("apple.awt.dnd.defaultDragImageSize")); + String propValue = System.getProperty("apple.awt.dnd.defaultDragImageSize"); if (propValue != null) { try { double value = Double.parseDouble(propValue); diff --git a/src/java.desktop/macosx/classes/sun/lwawt/macosx/CFileDialog.java b/src/java.desktop/macosx/classes/sun/lwawt/macosx/CFileDialog.java index 169aea8127e..090a90554f0 100644 --- a/src/java.desktop/macosx/classes/sun/lwawt/macosx/CFileDialog.java +++ b/src/java.desktop/macosx/classes/sun/lwawt/macosx/CFileDialog.java @@ -51,12 +51,10 @@ import java.awt.peer.ContainerPeer; import java.awt.peer.FileDialogPeer; import java.io.File; import java.io.FilenameFilter; -import java.security.AccessController; import java.util.List; import sun.awt.AWTAccessor; import sun.java2d.pipe.Region; -import sun.security.action.GetBooleanAction; class CFileDialog implements FileDialogPeer { @@ -65,12 +63,8 @@ class CFileDialog implements FileDialogPeer { @Override public void run() { try { - @SuppressWarnings("removal") - boolean navigateApps = !AccessController.doPrivileged( - new GetBooleanAction("apple.awt.use-file-dialog-packages")); - @SuppressWarnings("removal") - boolean chooseDirectories = AccessController.doPrivileged( - new GetBooleanAction("apple.awt.fileDialogForDirectories")); + boolean navigateApps = !Boolean.getBoolean("apple.awt.use-file-dialog-packages"); + boolean chooseDirectories = Boolean.getBoolean("apple.awt.fileDialogForDirectories"); int dialogMode = target.getMode(); String title = target.getTitle(); diff --git a/src/java.desktop/macosx/classes/sun/lwawt/macosx/CPlatformWindow.java b/src/java.desktop/macosx/classes/sun/lwawt/macosx/CPlatformWindow.java index 1bf77f5ee69..3af1b4bcdda 100644 --- a/src/java.desktop/macosx/classes/sun/lwawt/macosx/CPlatformWindow.java +++ b/src/java.desktop/macosx/classes/sun/lwawt/macosx/CPlatformWindow.java @@ -46,7 +46,6 @@ import java.awt.event.WindowStateListener; import java.beans.PropertyChangeEvent; import java.beans.PropertyChangeListener; import java.lang.reflect.InvocationTargetException; -import java.security.AccessController; import java.util.ArrayList; import java.util.Arrays; import java.util.Comparator; @@ -70,7 +69,6 @@ import sun.lwawt.LWToolkit; import sun.lwawt.LWWindowPeer; import sun.lwawt.LWWindowPeer.PeerType; import sun.lwawt.PlatformWindow; -import sun.security.action.GetPropertyAction; import sun.util.logging.PlatformLogger; public class CPlatformWindow extends CFRetainedResource implements PlatformWindow { @@ -131,9 +129,7 @@ public class CPlatformWindow extends CFRetainedResource implements PlatformWindo // This system property is named as jdk.* because it is not specific to AWT // and it is also used in JavaFX - @SuppressWarnings("removal") - public static final String MAC_OS_TABBED_WINDOW = AccessController.doPrivileged( - new GetPropertyAction("jdk.allowMacOSTabbedWindows")); + public static final String MAC_OS_TABBED_WINDOW = System.getProperty("jdk.allowMacOSTabbedWindows"); // Yeah, I know. But it's easier to deal with ints from JNI static final int MODELESS = 0; diff --git a/src/java.desktop/macosx/classes/sun/lwawt/macosx/CPrinterJob.java b/src/java.desktop/macosx/classes/sun/lwawt/macosx/CPrinterJob.java index 416a3ee002b..cbb39e24c1a 100644 --- a/src/java.desktop/macosx/classes/sun/lwawt/macosx/CPrinterJob.java +++ b/src/java.desktop/macosx/classes/sun/lwawt/macosx/CPrinterJob.java @@ -31,8 +31,6 @@ import java.awt.geom.Rectangle2D; import java.awt.image.BufferedImage; import java.awt.print.*; import java.net.URI; -import java.security.AccessController; -import java.security.PrivilegedAction; import java.util.concurrent.atomic.AtomicReference; import javax.print.*; @@ -284,7 +282,6 @@ public final class CPrinterJob extends RasterPrinterJob { return destinationAttr; } - @SuppressWarnings("removal") @Override public void print(PrintRequestAttributeSet attributes) throws PrinterException { // NOTE: Some of this code is copied from RasterPrinterJob. @@ -344,14 +341,7 @@ public final class CPrinterJob extends RasterPrinterJob { onEventThread = true; - printingLoop = AccessController.doPrivileged(new PrivilegedAction() { - @Override - public SecondaryLoop run() { - return Toolkit.getDefaultToolkit() - .getSystemEventQueue() - .createSecondaryLoop(); - } - }); + printingLoop = Toolkit.getDefaultToolkit().getSystemEventQueue().createSecondaryLoop(); try { // Fire off the print rendering loop on the AppKit thread, and don't have diff --git a/src/java.desktop/macosx/classes/sun/lwawt/macosx/CTrayIcon.java b/src/java.desktop/macosx/classes/sun/lwawt/macosx/CTrayIcon.java index 7d35f859a7a..4ca923c75b6 100644 --- a/src/java.desktop/macosx/classes/sun/lwawt/macosx/CTrayIcon.java +++ b/src/java.desktop/macosx/classes/sun/lwawt/macosx/CTrayIcon.java @@ -45,8 +45,6 @@ import java.awt.geom.Point2D; import java.awt.image.BufferedImage; import java.awt.image.ImageObserver; import java.awt.peer.TrayIconPeer; -import java.security.AccessController; -import java.security.PrivilegedAction; import javax.swing.Icon; import javax.swing.UIManager; @@ -71,10 +69,7 @@ public class CTrayIcon extends CFRetainedResource implements TrayIconPeer { // events between MOUSE_PRESSED and MOUSE_RELEASED for particular button private static int mouseClickButtons = 0; - @SuppressWarnings("removal") - private static final boolean useTemplateImages = AccessController.doPrivileged((PrivilegedAction) - () -> Boolean.getBoolean("apple.awt.enableTemplateImages") - ); + private static final boolean useTemplateImages = Boolean.getBoolean("apple.awt.enableTemplateImages"); CTrayIcon(TrayIcon target) { super(0, true); diff --git a/src/java.desktop/macosx/classes/sun/lwawt/macosx/LWCToolkit.java b/src/java.desktop/macosx/classes/sun/lwawt/macosx/LWCToolkit.java index 9a9be0e65c7..d3ffcfc7730 100644 --- a/src/java.desktop/macosx/classes/sun/lwawt/macosx/LWCToolkit.java +++ b/src/java.desktop/macosx/classes/sun/lwawt/macosx/LWCToolkit.java @@ -87,8 +87,6 @@ import java.lang.reflect.InvocationTargetException; import java.lang.reflect.UndeclaredThrowableException; import java.net.MalformedURLException; import java.net.URL; -import java.security.AccessController; -import java.security.PrivilegedAction; import java.util.HashMap; import java.util.Locale; import java.util.Map; @@ -146,24 +144,14 @@ public final class LWCToolkit extends LWToolkit { static { System.err.flush(); - @SuppressWarnings({"removal", "restricted"}) - ResourceBundle platformResources = java.security.AccessController.doPrivileged( - new java.security.PrivilegedAction() { - @Override - public ResourceBundle run() { - ResourceBundle platformResources = null; - try { - platformResources = ResourceBundle.getBundle("sun.awt.resources.awtosx"); - } catch (MissingResourceException e) { - // No resource file; defaults will be used. - } + ResourceBundle platformResources = null; + try { + platformResources = ResourceBundle.getBundle("sun.awt.resources.awtosx"); + } catch (MissingResourceException e) { + // No resource file; defaults will be used. + } - System.loadLibrary("awt"); - System.loadLibrary("fontmanager"); - - return platformResources; - } - }); + loadLibrary(); if (!GraphicsEnvironment.isHeadless() && !PlatformGraphicsInfo.isInAquaSession()) @@ -178,32 +166,28 @@ public final class LWCToolkit extends LWToolkit { } } + @SuppressWarnings("restricted") + private static void loadLibrary() { + System.loadLibrary("awt"); + System.loadLibrary("fontmanager"); + } + /* * If true we operate in normal mode and nested runloop is executed in JavaRunLoopMode * If false we operate in singleThreaded FX/AWT interop mode and nested loop uses NSDefaultRunLoopMode */ - @SuppressWarnings("removal") private static final boolean inAWT - = AccessController.doPrivileged(new PrivilegedAction() { - @Override - public Boolean run() { - return !Boolean.parseBoolean( + = !Boolean.parseBoolean( System.getProperty("javafx.embed.singleThread", "false")); - } - }); - @SuppressWarnings("removal") public LWCToolkit() { final String extraButtons = "sun.awt.enableExtraMouseButtons"; - AccessController.doPrivileged((PrivilegedAction) () -> { areExtraMouseButtonsEnabled = Boolean.parseBoolean(System.getProperty(extraButtons, "true")); //set system property if not yet assigned - System.setProperty(extraButtons, ""+areExtraMouseButtonsEnabled); + System.setProperty(extraButtons, "" + areExtraMouseButtonsEnabled); initAppkit(ThreadGroupUtils.getRootThreadGroup(), GraphicsEnvironment.isHeadless()); - return null; - }); } /* @@ -254,13 +238,9 @@ public final class LWCToolkit extends LWToolkit { } // This is only called from native code. - @SuppressWarnings("removal") static void systemColorsChanged() { EventQueue.invokeLater(() -> { - AccessController.doPrivileged( (PrivilegedAction) () -> { AWTAccessor.getSystemColorAccessor().updateSystemColors(); - return null; - }); }); } @@ -592,13 +572,9 @@ public final class LWCToolkit extends LWToolkit { private static final String APPKIT_THREAD_NAME = "AppKit Thread"; // Intended to be called from the LWCToolkit.m only. - @SuppressWarnings("removal") private static void installToolkitThreadInJava() { Thread.currentThread().setName(APPKIT_THREAD_NAME); - AccessController.doPrivileged((PrivilegedAction) () -> { - Thread.currentThread().setContextClassLoader(null); - return null; - }); + Thread.currentThread().setContextClassLoader(null); } @Override