8344058: Remove doPrivileged calls from macos platform sources in the java.desktop module

Reviewed-by: prr, aivanov
This commit is contained in:
Harshitha Onkar 2024-11-18 19:19:51 +00:00
parent 70eb95f848
commit 92271af635
24 changed files with 136 additions and 315 deletions

View File

@ -25,12 +25,9 @@
package apple.laf; package apple.laf;
import java.security.AccessController;
import apple.laf.JRSUIConstants.Hit; import apple.laf.JRSUIConstants.Hit;
import apple.laf.JRSUIConstants.ScrollBarPart; import apple.laf.JRSUIConstants.ScrollBarPart;
import com.apple.laf.AquaImageFactory.NineSliceMetrics; import com.apple.laf.AquaImageFactory.NineSliceMetrics;
import sun.security.action.GetPropertyAction;
public final class JRSUIUtils { public final class JRSUIUtils {
@ -69,8 +66,7 @@ public final class JRSUIUtils {
final int majorVersion, final int minorVersion, final boolean inclusive, final int majorVersion, final int minorVersion, final boolean inclusive,
final boolean matchBelow, final boolean matchAbove) { final boolean matchBelow, final boolean matchAbove) {
// split the "x.y.z" version number // split the "x.y.z" version number
@SuppressWarnings("removal") String osVersion = System.getProperty("os.version");
String osVersion = AccessController.doPrivileged(new GetPropertyAction("os.version"));
String[] fragments = osVersion.split("\\."); String[] fragments = osVersion.split("\\.");
if (fragments.length < 2) return false; if (fragments.length < 2) return false;

View File

@ -58,15 +58,9 @@ public class FileManager {
loadOSXLibrary(); loadOSXLibrary();
} }
@SuppressWarnings({"removal", "restricted"}) @SuppressWarnings("restricted")
private static void loadOSXLibrary() { private static void loadOSXLibrary() {
java.security.AccessController.doPrivileged(
new java.security.PrivilegedAction<Void>() {
public Void run() {
System.loadLibrary("osx"); System.loadLibrary("osx");
return null;
}
});
} }
/** /**

View File

@ -65,15 +65,9 @@ class AquaFileView extends FileView {
loadOSXUILibrary(); loadOSXUILibrary();
} }
@SuppressWarnings({"removal", "restricted"}) @SuppressWarnings("restricted")
private static void loadOSXUILibrary() { private static void loadOSXUILibrary() {
java.security.AccessController.doPrivileged(
new java.security.PrivilegedAction<Void>() {
public Void run() {
System.loadLibrary("osxui"); System.loadLibrary("osxui");
return null;
}
});
} }
// TODO: Un-comment this out when the native version exists // TODO: Un-comment this out when the native version exists

View File

@ -27,11 +27,11 @@ package com.apple.laf;
import java.awt.*; import java.awt.*;
import java.awt.image.BufferedImage; import java.awt.image.BufferedImage;
import java.security.PrivilegedAction;
import javax.swing.*; import javax.swing.*;
import javax.swing.plaf.*; import javax.swing.plaf.*;
import com.apple.eawt.Application;
import sun.lwawt.macosx.LWCToolkit; import sun.lwawt.macosx.LWCToolkit;
import apple.laf.JRSUIConstants.AlignmentHorizontal; import apple.laf.JRSUIConstants.AlignmentHorizontal;
import apple.laf.JRSUIConstants.AlignmentVertical; import apple.laf.JRSUIConstants.AlignmentVertical;
@ -82,23 +82,13 @@ public class AquaImageFactory {
return getAppIconCompositedOn(lockIcon); return getAppIconCompositedOn(lockIcon);
} }
@SuppressWarnings("removal")
static Image getGenericJavaIcon() { static Image getGenericJavaIcon() {
return java.security.AccessController.doPrivileged(new PrivilegedAction<Image>() { return Application.getApplication().getDockIconImage();
public Image run() {
return com.apple.eawt.Application.getApplication().getDockIconImage();
}
});
} }
@SuppressWarnings("removal")
static String getPathToThisApplication() { static String getPathToThisApplication() {
return java.security.AccessController.doPrivileged(new PrivilegedAction<String>() {
public String run() {
return FileManager.getPathToApplicationBundle(); return FileManager.getPathToApplicationBundle();
} }
});
}
static IconUIResource getAppIconCompositedOn(final SystemIcon systemIcon) { static IconUIResource getAppIconCompositedOn(final SystemIcon systemIcon) {
systemIcon.setSize(kAlertIconSize, kAlertIconSize); systemIcon.setSize(kAlertIconSize, kAlertIconSize);

View File

@ -154,22 +154,10 @@ public class AquaLookAndFeel extends BasicLookAndFeel {
* @see #uninitialize * @see #uninitialize
* @see UIManager#setLookAndFeel * @see UIManager#setLookAndFeel
*/ */
@SuppressWarnings({"removal", "restricted"}) @SuppressWarnings("restricted")
public void initialize() { public void initialize() {
java.security.AccessController.doPrivileged(new PrivilegedAction<Void>() {
public Void run() {
System.loadLibrary("osxui"); System.loadLibrary("osxui");
return null;
}
});
java.security.AccessController.doPrivileged(new PrivilegedAction<Void>(){
@Override
public Void run() {
JRSUIControl.initJRSUI(); JRSUIControl.initJRSUI();
return null;
}
});
super.initialize(); super.initialize();
final ScreenPopupFactory spf = new ScreenPopupFactory(); final ScreenPopupFactory spf = new ScreenPopupFactory();

View File

@ -29,7 +29,6 @@ import java.awt.Component;
import java.awt.Dimension; import java.awt.Dimension;
import java.awt.Graphics; import java.awt.Graphics;
import java.awt.MenuBar; import java.awt.MenuBar;
import java.security.AccessController;
import javax.swing.JComponent; import javax.swing.JComponent;
import javax.swing.JFrame; import javax.swing.JFrame;
@ -38,18 +37,13 @@ import javax.swing.plaf.ComponentUI;
import javax.swing.plaf.basic.BasicMenuBarUI; import javax.swing.plaf.basic.BasicMenuBarUI;
import sun.lwawt.macosx.LWCToolkit; import sun.lwawt.macosx.LWCToolkit;
import sun.security.action.GetBooleanAction;
// MenuBar implementation for Mac L&F // MenuBar implementation for Mac L&F
@SuppressWarnings({"removal", "restricted"}) @SuppressWarnings("restricted")
public class AquaMenuBarUI extends BasicMenuBarUI implements ScreenMenuBarProvider { public class AquaMenuBarUI extends BasicMenuBarUI implements ScreenMenuBarProvider {
static { static {
java.security.AccessController.doPrivileged(
(java.security.PrivilegedAction<Void>) () -> {
System.loadLibrary("osxui"); System.loadLibrary("osxui");
return null;
});
} }
// Utilities // Utilities
@ -151,7 +145,6 @@ public class AquaMenuBarUI extends BasicMenuBarUI implements ScreenMenuBarProvid
public static boolean getScreenMenuBarProperty() { public static boolean getScreenMenuBarProperty() {
// Do not allow AWT to set the screen menu bar if it's embedded in another UI toolkit // Do not allow AWT to set the screen menu bar if it's embedded in another UI toolkit
if (LWCToolkit.isEmbedded()) return false; if (LWCToolkit.isEmbedded()) return false;
return AccessController.doPrivileged(new GetBooleanAction( return Boolean.getBoolean(AquaLookAndFeel.sPropertyPrefix + "useScreenMenuBar");
AquaLookAndFeel.sPropertyPrefix + "useScreenMenuBar"));
} }
} }

View File

@ -32,16 +32,10 @@ import javax.swing.plaf.UIResource;
import com.apple.laf.AquaUtils.RecyclableSingleton; import com.apple.laf.AquaUtils.RecyclableSingleton;
@SuppressWarnings({"removal", "restricted"}) @SuppressWarnings("restricted")
public class AquaNativeResources { public class AquaNativeResources {
static { static {
java.security.AccessController.doPrivileged(
new java.security.PrivilegedAction<Void>() {
public Void run() {
System.loadLibrary("osxui"); System.loadLibrary("osxui");
return null;
}
});
} }
// TODO: removing CColorPaint for now // TODO: removing CColorPaint for now

View File

@ -27,7 +27,6 @@ package com.apple.laf;
import java.awt.*; import java.awt.*;
import java.beans.*; import java.beans.*;
import java.security.AccessController;
import javax.swing.*; import javax.swing.*;
import javax.swing.border.Border; import javax.swing.border.Border;
@ -38,7 +37,6 @@ import apple.laf.JRSUIConstants.*;
import com.apple.laf.AquaUtils.RecyclableSingleton; import com.apple.laf.AquaUtils.RecyclableSingleton;
import com.apple.laf.AquaUtils.RecyclableSingletonFromDefaultConstructor; import com.apple.laf.AquaUtils.RecyclableSingletonFromDefaultConstructor;
import sun.security.action.GetPropertyAction;
public class AquaUtilControlSize { public class AquaUtilControlSize {
protected static final String CLIENT_PROPERTY_KEY = "JComponent.sizeVariant"; protected static final String CLIENT_PROPERTY_KEY = "JComponent.sizeVariant";
@ -72,9 +70,7 @@ public class AquaUtilControlSize {
} }
private static Size getDefaultSize() { private static Size getDefaultSize() {
@SuppressWarnings("removal") final String sizeProperty = System.getProperty(SYSTEM_PROPERTY_KEY);
final String sizeProperty = AccessController.doPrivileged(
new GetPropertyAction(SYSTEM_PROPERTY_KEY));
final JRSUIConstants.Size size = getSizeFromString(sizeProperty); final JRSUIConstants.Size size = getSizeFromString(sizeProperty);
if (size != null) return size; if (size != null) return size;
return JRSUIConstants.Size.REGULAR; return JRSUIConstants.Size.REGULAR;

View File

@ -29,8 +29,6 @@ import java.awt.*;
import java.awt.image.*; import java.awt.image.*;
import java.lang.ref.SoftReference; import java.lang.ref.SoftReference;
import java.lang.reflect.Method; import java.lang.reflect.Method;
import java.security.AccessController;
import java.security.PrivilegedAction;
import java.util.*; import java.util.*;
import javax.swing.*; import javax.swing.*;
@ -41,7 +39,6 @@ import sun.awt.AppContext;
import sun.lwawt.macosx.CPlatformWindow; import sun.lwawt.macosx.CPlatformWindow;
import sun.reflect.misc.ReflectUtil; import sun.reflect.misc.ReflectUtil;
import sun.security.action.GetPropertyAction;
import sun.swing.SwingUtilities2; import sun.swing.SwingUtilities2;
import com.apple.laf.AquaImageFactory.SlicedImageControl; import com.apple.laf.AquaImageFactory.SlicedImageControl;
@ -205,9 +202,7 @@ final class AquaUtils {
private static final RecyclableSingleton<Boolean> enableAnimations = new RecyclableSingleton<Boolean>() { private static final RecyclableSingleton<Boolean> enableAnimations = new RecyclableSingleton<Boolean>() {
@Override @Override
protected Boolean getInstance() { protected Boolean getInstance() {
@SuppressWarnings("removal") final String sizeProperty = System.getProperty(ANIMATIONS_PROPERTY);
final String sizeProperty = (String) AccessController.doPrivileged((PrivilegedAction<?>)new GetPropertyAction(
ANIMATIONS_PROPERTY));
return !"false".equals(sizeProperty); // should be true by default return !"false".equals(sizeProperty); // should be true by default
} }
}; };
@ -332,26 +327,18 @@ final class AquaUtils {
} }
} }
@SuppressWarnings("removal")
private static final RecyclableSingleton<Method> getJComponentGetFlagMethod = new RecyclableSingleton<Method>() { private static final RecyclableSingleton<Method> getJComponentGetFlagMethod = new RecyclableSingleton<Method>() {
@Override @Override
protected Method getInstance() { protected Method getInstance() {
return AccessController.doPrivileged(
new PrivilegedAction<Method>() {
@Override
public Method run() {
try { try {
final Method method = JComponent.class.getDeclaredMethod( final Method method = JComponent.class.getDeclaredMethod(
"getFlag", new Class<?>[] { int.class }); "getFlag", new Class<?>[]{int.class});
method.setAccessible(true); method.setAccessible(true);
return method; return method;
} catch (final Throwable ignored) { } catch (final Throwable ignored) {
return null; return null;
} }
} }
}
);
}
}; };
private static final int OPAQUE_SET_FLAG = 24; // private int JComponent.OPAQUE_SET private static final int OPAQUE_SET_FLAG = 24; // private int JComponent.OPAQUE_SET

View File

@ -45,15 +45,9 @@ final class ScreenMenu extends Menu
loadAWTLibrary(); loadAWTLibrary();
} }
@SuppressWarnings({"removal", "restricted"}) @SuppressWarnings("restricted")
private static void loadAWTLibrary() { private static void loadAWTLibrary() {
java.security.AccessController.doPrivileged(
new java.security.PrivilegedAction<Void>() {
public Void run() {
System.loadLibrary("awt"); System.loadLibrary("awt");
return null;
}
});
} }
// screen menu stuff // screen menu stuff

View File

@ -27,17 +27,12 @@ package sun.awt;
import java.awt.GraphicsEnvironment; import java.awt.GraphicsEnvironment;
import java.awt.Toolkit; import java.awt.Toolkit;
import java.security.AccessController;
import java.security.PrivilegedAction;
@SuppressWarnings({"removal", "restricted"}) @SuppressWarnings({"restricted"})
public class PlatformGraphicsInfo { public class PlatformGraphicsInfo {
static { static {
AccessController.doPrivileged((PrivilegedAction<Void>) () -> {
System.loadLibrary("awt"); System.loadLibrary("awt");
return null;
});
} }
public static GraphicsEnvironment createGE() { public static GraphicsEnvironment createGE() {

View File

@ -27,8 +27,6 @@ package sun.font;
import java.awt.*; import java.awt.*;
import java.io.File; import java.io.File;
import java.security.AccessController;
import java.security.PrivilegedAction;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.HashMap; import java.util.HashMap;
import java.util.Hashtable; import java.util.Hashtable;
@ -147,10 +145,7 @@ public final class CFontManager extends SunFontManager {
protected void registerFontsInDir(final String dirName, boolean useJavaRasterizer, protected void registerFontsInDir(final String dirName, boolean useJavaRasterizer,
int fontRank, boolean defer, boolean resolveSymLinks) { int fontRank, boolean defer, boolean resolveSymLinks) {
@SuppressWarnings("removal") String[] files = new File(dirName).list(getTrueTypeFilter());
String[] files = AccessController.doPrivileged((PrivilegedAction<String[]>) () -> {
return new File(dirName).list(getTrueTypeFilter());
});
if (files == null) { if (files == null) {
return; return;
@ -205,24 +200,17 @@ public final class CFontManager extends SunFontManager {
Object waitForFontsToBeLoaded = new Object(); Object waitForFontsToBeLoaded = new Object();
private boolean loadedAllFonts = false; private boolean loadedAllFonts = false;
@SuppressWarnings("removal")
public void loadFonts() public void loadFonts()
{ {
synchronized(waitForFontsToBeLoaded) synchronized(waitForFontsToBeLoaded)
{ {
super.loadFonts(); super.loadFonts();
java.security.AccessController.doPrivileged(
new java.security.PrivilegedAction<Object>() {
public Object run() {
if (!loadedAllFonts) { if (!loadedAllFonts) {
loadNativeFonts(); loadNativeFonts();
registerItalicDerived(); registerItalicDerived();
loadedAllFonts = true; loadedAllFonts = true;
} }
return null;
}
}
);
String defaultFont = "Lucida Grande"; String defaultFont = "Lucida Grande";
String defaultFallback = "Lucida Grande"; String defaultFallback = "Lucida Grande";

View File

@ -25,7 +25,6 @@
package sun.java2d; package sun.java2d;
import java.security.PrivilegedAction;
import sun.java2d.metal.MTLGraphicsConfig; import sun.java2d.metal.MTLGraphicsConfig;
import sun.java2d.opengl.CGLGraphicsConfig; import sun.java2d.opengl.CGLGraphicsConfig;
@ -83,10 +82,7 @@ public class MacOSFlags {
return false; return false;
} }
@SuppressWarnings("removal")
private static void initJavaFlags() { private static void initJavaFlags() {
java.security.AccessController.doPrivileged(
(PrivilegedAction<Object>) () -> {
PropertyState oglState = getBooleanProp("sun.java2d.opengl", PropertyState.UNSPECIFIED); PropertyState oglState = getBooleanProp("sun.java2d.opengl", PropertyState.UNSPECIFIED);
PropertyState metalState = getBooleanProp("sun.java2d.metal", PropertyState.UNSPECIFIED); PropertyState metalState = getBooleanProp("sun.java2d.metal", PropertyState.UNSPECIFIED);
@ -133,9 +129,6 @@ public class MacOSFlags {
if (!metalEnabled && !oglEnabled) { if (!metalEnabled && !oglEnabled) {
throw new InternalError("Error - unable to initialize any rendering pipeline."); throw new InternalError("Error - unable to initialize any rendering pipeline.");
} }
return null;
});
} }
public static boolean isMetalEnabled() { public static boolean isMetalEnabled() {

View File

@ -58,8 +58,6 @@ import java.awt.image.DirectColorModel;
import java.awt.image.VolatileImage; import java.awt.image.VolatileImage;
import java.awt.image.WritableRaster; import java.awt.image.WritableRaster;
import java.io.File; 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.metal.MTLContext.MTLContextCaps.CAPS_EXT_GRAD_SHADER;
import static sun.java2d.pipe.hw.AccelSurface.TEXTURE; import static sun.java2d.pipe.hw.AccelSurface.TEXTURE;
@ -73,11 +71,10 @@ public final class MTLGraphicsConfig extends CGraphicsConfig
{ {
private static ImageCapabilities imageCaps = new MTLImageCaps(); private static ImageCapabilities imageCaps = new MTLImageCaps();
@SuppressWarnings("removal")
private static final String mtlShadersLib = AccessController.doPrivileged( private static final String mtlShadersLib =
(PrivilegedAction<String>) () ->
System.getProperty("java.home", "") + File.separator + System.getProperty("java.home", "") + File.separator +
"lib" + File.separator + "shaders.metallib"); "lib" + File.separator + "shaders.metallib";
private BufferCapabilities bufferCaps; private BufferCapabilities bufferCaps;

View File

@ -29,9 +29,6 @@ import sun.awt.util.ThreadGroupUtils;
import sun.java2d.pipe.RenderBuffer; import sun.java2d.pipe.RenderBuffer;
import sun.java2d.pipe.RenderQueue; 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.DISPOSE_CONFIG;
import static sun.java2d.pipe.BufferedOpCodes.SYNC; import static sun.java2d.pipe.BufferedOpCodes.SYNC;
@ -46,13 +43,12 @@ public class MTLRenderQueue extends RenderQueue {
private static MTLRenderQueue theInstance; private static MTLRenderQueue theInstance;
private final QueueFlusher flusher; private final QueueFlusher flusher;
@SuppressWarnings("removal")
private MTLRenderQueue() { private MTLRenderQueue() {
/* /*
* The thread must be a member of a thread group * The thread must be a member of a thread group
* which will not get GCed before VM exit. * which will not get GCed before VM exit.
*/ */
flusher = AccessController.doPrivileged((PrivilegedAction<QueueFlusher>) QueueFlusher::new); flusher = new QueueFlusher();
} }
/** /**

View File

@ -58,8 +58,6 @@ import java.awt.peer.ComponentPeer;
import java.awt.peer.ContainerPeer; import java.awt.peer.ContainerPeer;
import java.awt.peer.KeyboardFocusManagerPeer; import java.awt.peer.KeyboardFocusManagerPeer;
import java.lang.reflect.Field; import java.lang.reflect.Field;
import java.security.AccessController;
import java.security.PrivilegedAction;
import java.util.concurrent.atomic.AtomicBoolean; import java.util.concurrent.atomic.AtomicBoolean;
import javax.swing.JComponent; import javax.swing.JComponent;
@ -260,10 +258,7 @@ public abstract class LWComponentPeer<T extends Component, D extends JComponent>
* This method must be called under Toolkit.getDefaultToolkit() lock * This method must be called under Toolkit.getDefaultToolkit() lock
* and followed by setToolkitAWTEventListener() * and followed by setToolkitAWTEventListener()
*/ */
@SuppressWarnings("removal")
protected final AWTEventListener getToolkitAWTEventListener() { protected final AWTEventListener getToolkitAWTEventListener() {
return AccessController.doPrivileged(new PrivilegedAction<AWTEventListener>() {
public AWTEventListener run() {
Toolkit toolkit = Toolkit.getDefaultToolkit(); Toolkit toolkit = Toolkit.getDefaultToolkit();
try { try {
Field field = Toolkit.class.getDeclaredField("eventListener"); Field field = Toolkit.class.getDeclaredField("eventListener");
@ -273,13 +268,8 @@ public abstract class LWComponentPeer<T extends Component, D extends JComponent>
throw new InternalError(e.toString()); throw new InternalError(e.toString());
} }
} }
});
}
@SuppressWarnings("removal")
protected final void setToolkitAWTEventListener(final AWTEventListener listener) { protected final void setToolkitAWTEventListener(final AWTEventListener listener) {
AccessController.doPrivileged(new PrivilegedAction<Void>() {
public Void run() {
Toolkit toolkit = Toolkit.getDefaultToolkit(); Toolkit toolkit = Toolkit.getDefaultToolkit();
try { try {
Field field = Toolkit.class.getDeclaredField("eventListener"); Field field = Toolkit.class.getDeclaredField("eventListener");
@ -288,9 +278,6 @@ public abstract class LWComponentPeer<T extends Component, D extends JComponent>
} catch (Exception e) { } catch (Exception e) {
throw new InternalError(e.toString()); throw new InternalError(e.toString());
} }
return null;
}
});
} }
/** /**

View File

@ -31,7 +31,6 @@ import java.awt.datatransfer.*;
import java.awt.dnd.DropTarget; import java.awt.dnd.DropTarget;
import java.awt.image.*; import java.awt.image.*;
import java.awt.peer.*; import java.awt.peer.*;
import java.security.*;
import java.util.*; import java.util.*;
import sun.awt.*; import sun.awt.*;
@ -69,10 +68,8 @@ public abstract class LWToolkit extends SunToolkit implements Runnable {
* This method waits for the toolkit to be completely initialized * This method waits for the toolkit to be completely initialized
* and returns before the message pump is started. * and returns before the message pump is started.
*/ */
@SuppressWarnings("removal")
protected final void init() { protected final void init() {
AWTAutoShutdown.notifyToolkitThreadBusy(); AWTAutoShutdown.notifyToolkitThreadBusy();
AccessController.doPrivileged((PrivilegedAction<Void>) () -> {
Runnable shutdownRunnable = () -> { Runnable shutdownRunnable = () -> {
shutdown(); shutdown();
waitForRunState(STATE_CLEANUP); waitForRunState(STATE_CLEANUP);
@ -88,8 +85,6 @@ public abstract class LWToolkit extends SunToolkit implements Runnable {
toolkitThread.setDaemon(true); toolkitThread.setDaemon(true);
toolkitThread.setPriority(Thread.NORM_PRIORITY + 1); toolkitThread.setPriority(Thread.NORM_PRIORITY + 1);
toolkitThread.start(); toolkitThread.start();
return null;
});
waitForRunState(STATE_MESSAGELOOP); waitForRunState(STATE_MESSAGELOOP);
} }

View File

@ -77,16 +77,10 @@ class CAccessibility implements PropertyChangeListener {
loadAWTLibrary(); loadAWTLibrary();
} }
@SuppressWarnings({"removal", "restricted"}) @SuppressWarnings("restricted")
private static void loadAWTLibrary() { private static void loadAWTLibrary() {
// Need to load the native library for this code. // Need to load the native library for this code.
java.security.AccessController.doPrivileged(
new java.security.PrivilegedAction<Void>() {
public Void run() {
System.loadLibrary("awt"); System.loadLibrary("awt");
return null;
}
});
} }
static CAccessibility sAccessibility; static CAccessibility sAccessibility;

View File

@ -59,8 +59,7 @@ public final class CDragSourceContextPeer extends SunDragSourceContextPeer {
private static double fMaxImageSize = 128.0; private static double fMaxImageSize = 128.0;
static { static {
@SuppressWarnings("removal") String propValue = System.getProperty("apple.awt.dnd.defaultDragImageSize");
String propValue = java.security.AccessController.doPrivileged(new sun.security.action.GetPropertyAction("apple.awt.dnd.defaultDragImageSize"));
if (propValue != null) { if (propValue != null) {
try { try {
double value = Double.parseDouble(propValue); double value = Double.parseDouble(propValue);

View File

@ -51,12 +51,10 @@ import java.awt.peer.ContainerPeer;
import java.awt.peer.FileDialogPeer; import java.awt.peer.FileDialogPeer;
import java.io.File; import java.io.File;
import java.io.FilenameFilter; import java.io.FilenameFilter;
import java.security.AccessController;
import java.util.List; import java.util.List;
import sun.awt.AWTAccessor; import sun.awt.AWTAccessor;
import sun.java2d.pipe.Region; import sun.java2d.pipe.Region;
import sun.security.action.GetBooleanAction;
class CFileDialog implements FileDialogPeer { class CFileDialog implements FileDialogPeer {
@ -65,12 +63,8 @@ class CFileDialog implements FileDialogPeer {
@Override @Override
public void run() { public void run() {
try { try {
@SuppressWarnings("removal") boolean navigateApps = !Boolean.getBoolean("apple.awt.use-file-dialog-packages");
boolean navigateApps = !AccessController.doPrivileged( boolean chooseDirectories = Boolean.getBoolean("apple.awt.fileDialogForDirectories");
new GetBooleanAction("apple.awt.use-file-dialog-packages"));
@SuppressWarnings("removal")
boolean chooseDirectories = AccessController.doPrivileged(
new GetBooleanAction("apple.awt.fileDialogForDirectories"));
int dialogMode = target.getMode(); int dialogMode = target.getMode();
String title = target.getTitle(); String title = target.getTitle();

View File

@ -46,7 +46,6 @@ import java.awt.event.WindowStateListener;
import java.beans.PropertyChangeEvent; import java.beans.PropertyChangeEvent;
import java.beans.PropertyChangeListener; import java.beans.PropertyChangeListener;
import java.lang.reflect.InvocationTargetException; import java.lang.reflect.InvocationTargetException;
import java.security.AccessController;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Arrays; import java.util.Arrays;
import java.util.Comparator; import java.util.Comparator;
@ -70,7 +69,6 @@ import sun.lwawt.LWToolkit;
import sun.lwawt.LWWindowPeer; import sun.lwawt.LWWindowPeer;
import sun.lwawt.LWWindowPeer.PeerType; import sun.lwawt.LWWindowPeer.PeerType;
import sun.lwawt.PlatformWindow; import sun.lwawt.PlatformWindow;
import sun.security.action.GetPropertyAction;
import sun.util.logging.PlatformLogger; import sun.util.logging.PlatformLogger;
public class CPlatformWindow extends CFRetainedResource implements PlatformWindow { 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 // This system property is named as jdk.* because it is not specific to AWT
// and it is also used in JavaFX // and it is also used in JavaFX
@SuppressWarnings("removal") public static final String MAC_OS_TABBED_WINDOW = System.getProperty("jdk.allowMacOSTabbedWindows");
public static final String MAC_OS_TABBED_WINDOW = AccessController.doPrivileged(
new GetPropertyAction("jdk.allowMacOSTabbedWindows"));
// Yeah, I know. But it's easier to deal with ints from JNI // Yeah, I know. But it's easier to deal with ints from JNI
static final int MODELESS = 0; static final int MODELESS = 0;

View File

@ -31,8 +31,6 @@ import java.awt.geom.Rectangle2D;
import java.awt.image.BufferedImage; import java.awt.image.BufferedImage;
import java.awt.print.*; import java.awt.print.*;
import java.net.URI; import java.net.URI;
import java.security.AccessController;
import java.security.PrivilegedAction;
import java.util.concurrent.atomic.AtomicReference; import java.util.concurrent.atomic.AtomicReference;
import javax.print.*; import javax.print.*;
@ -284,7 +282,6 @@ public final class CPrinterJob extends RasterPrinterJob {
return destinationAttr; return destinationAttr;
} }
@SuppressWarnings("removal")
@Override @Override
public void print(PrintRequestAttributeSet attributes) throws PrinterException { public void print(PrintRequestAttributeSet attributes) throws PrinterException {
// NOTE: Some of this code is copied from RasterPrinterJob. // NOTE: Some of this code is copied from RasterPrinterJob.
@ -344,14 +341,7 @@ public final class CPrinterJob extends RasterPrinterJob {
onEventThread = true; onEventThread = true;
printingLoop = AccessController.doPrivileged(new PrivilegedAction<SecondaryLoop>() { printingLoop = Toolkit.getDefaultToolkit().getSystemEventQueue().createSecondaryLoop();
@Override
public SecondaryLoop run() {
return Toolkit.getDefaultToolkit()
.getSystemEventQueue()
.createSecondaryLoop();
}
});
try { try {
// Fire off the print rendering loop on the AppKit thread, and don't have // Fire off the print rendering loop on the AppKit thread, and don't have

View File

@ -45,8 +45,6 @@ import java.awt.geom.Point2D;
import java.awt.image.BufferedImage; import java.awt.image.BufferedImage;
import java.awt.image.ImageObserver; import java.awt.image.ImageObserver;
import java.awt.peer.TrayIconPeer; import java.awt.peer.TrayIconPeer;
import java.security.AccessController;
import java.security.PrivilegedAction;
import javax.swing.Icon; import javax.swing.Icon;
import javax.swing.UIManager; 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 // events between MOUSE_PRESSED and MOUSE_RELEASED for particular button
private static int mouseClickButtons = 0; private static int mouseClickButtons = 0;
@SuppressWarnings("removal") private static final boolean useTemplateImages = Boolean.getBoolean("apple.awt.enableTemplateImages");
private static final boolean useTemplateImages = AccessController.doPrivileged((PrivilegedAction<Boolean>)
() -> Boolean.getBoolean("apple.awt.enableTemplateImages")
);
CTrayIcon(TrayIcon target) { CTrayIcon(TrayIcon target) {
super(0, true); super(0, true);

View File

@ -87,8 +87,6 @@ import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.UndeclaredThrowableException; import java.lang.reflect.UndeclaredThrowableException;
import java.net.MalformedURLException; import java.net.MalformedURLException;
import java.net.URL; import java.net.URL;
import java.security.AccessController;
import java.security.PrivilegedAction;
import java.util.HashMap; import java.util.HashMap;
import java.util.Locale; import java.util.Locale;
import java.util.Map; import java.util.Map;
@ -146,11 +144,6 @@ public final class LWCToolkit extends LWToolkit {
static { static {
System.err.flush(); System.err.flush();
@SuppressWarnings({"removal", "restricted"})
ResourceBundle platformResources = java.security.AccessController.doPrivileged(
new java.security.PrivilegedAction<ResourceBundle>() {
@Override
public ResourceBundle run() {
ResourceBundle platformResources = null; ResourceBundle platformResources = null;
try { try {
platformResources = ResourceBundle.getBundle("sun.awt.resources.awtosx"); platformResources = ResourceBundle.getBundle("sun.awt.resources.awtosx");
@ -158,12 +151,7 @@ public final class LWCToolkit extends LWToolkit {
// No resource file; defaults will be used. // No resource file; defaults will be used.
} }
System.loadLibrary("awt"); loadLibrary();
System.loadLibrary("fontmanager");
return platformResources;
}
});
if (!GraphicsEnvironment.isHeadless() && if (!GraphicsEnvironment.isHeadless() &&
!PlatformGraphicsInfo.isInAquaSession()) !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 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 * If false we operate in singleThreaded FX/AWT interop mode and nested loop uses NSDefaultRunLoopMode
*/ */
@SuppressWarnings("removal")
private static final boolean inAWT private static final boolean inAWT
= AccessController.doPrivileged(new PrivilegedAction<Boolean>() { = !Boolean.parseBoolean(
@Override
public Boolean run() {
return !Boolean.parseBoolean(
System.getProperty("javafx.embed.singleThread", "false")); System.getProperty("javafx.embed.singleThread", "false"));
}
});
@SuppressWarnings("removal")
public LWCToolkit() { public LWCToolkit() {
final String extraButtons = "sun.awt.enableExtraMouseButtons"; final String extraButtons = "sun.awt.enableExtraMouseButtons";
AccessController.doPrivileged((PrivilegedAction<Void>) () -> {
areExtraMouseButtonsEnabled = areExtraMouseButtonsEnabled =
Boolean.parseBoolean(System.getProperty(extraButtons, "true")); Boolean.parseBoolean(System.getProperty(extraButtons, "true"));
//set system property if not yet assigned //set system property if not yet assigned
System.setProperty(extraButtons, ""+areExtraMouseButtonsEnabled); System.setProperty(extraButtons, "" + areExtraMouseButtonsEnabled);
initAppkit(ThreadGroupUtils.getRootThreadGroup(), initAppkit(ThreadGroupUtils.getRootThreadGroup(),
GraphicsEnvironment.isHeadless()); GraphicsEnvironment.isHeadless());
return null;
});
} }
/* /*
@ -254,13 +238,9 @@ public final class LWCToolkit extends LWToolkit {
} }
// This is only called from native code. // This is only called from native code.
@SuppressWarnings("removal")
static void systemColorsChanged() { static void systemColorsChanged() {
EventQueue.invokeLater(() -> { EventQueue.invokeLater(() -> {
AccessController.doPrivileged( (PrivilegedAction<Object>) () -> {
AWTAccessor.getSystemColorAccessor().updateSystemColors(); AWTAccessor.getSystemColorAccessor().updateSystemColors();
return null;
});
}); });
} }
@ -592,13 +572,9 @@ public final class LWCToolkit extends LWToolkit {
private static final String APPKIT_THREAD_NAME = "AppKit Thread"; private static final String APPKIT_THREAD_NAME = "AppKit Thread";
// Intended to be called from the LWCToolkit.m only. // Intended to be called from the LWCToolkit.m only.
@SuppressWarnings("removal")
private static void installToolkitThreadInJava() { private static void installToolkitThreadInJava() {
Thread.currentThread().setName(APPKIT_THREAD_NAME); Thread.currentThread().setName(APPKIT_THREAD_NAME);
AccessController.doPrivileged((PrivilegedAction<Void>) () -> {
Thread.currentThread().setContextClassLoader(null); Thread.currentThread().setContextClassLoader(null);
return null;
});
} }
@Override @Override