8344059: Remove doPrivileged calls from windows platform sources in the java.desktop module

Reviewed-by: kcr, prr
This commit is contained in:
Prasanta Sadhukhan 2024-11-19 03:11:31 +00:00
parent 37298844c9
commit 9e92a9e2ba
17 changed files with 187 additions and 354 deletions

View File

@ -25,9 +25,6 @@
package com.sun.java.swing.plaf.windows;
import java.security.AccessController;
import sun.security.action.GetBooleanAction;
import java.util.*;
import java.beans.PropertyChangeListener;
import java.beans.PropertyChangeEvent;
@ -67,9 +64,8 @@ import sun.awt.AppContext;
*/
class AnimationController implements ActionListener, PropertyChangeListener {
@SuppressWarnings("removal")
private static final boolean VISTA_ANIMATION_DISABLED =
AccessController.doPrivileged(new GetBooleanAction("swing.disablevistaanimation"));
Boolean.getBoolean("swing.disablevistaanimation");
private static final Object ANIMATION_CONTROLLER_KEY =

View File

@ -58,7 +58,6 @@ import java.awt.image.FilteredImageSource;
import java.awt.image.ImageFilter;
import java.awt.image.ImageProducer;
import java.awt.image.RGBImageFilter;
import java.security.AccessController;
import javax.swing.AbstractAction;
import javax.swing.Action;
@ -90,7 +89,6 @@ import sun.awt.OSInfo;
import sun.awt.SunToolkit;
import sun.awt.shell.ShellFolder;
import sun.font.FontUtilities;
import sun.security.action.GetPropertyAction;
import sun.swing.DefaultLayoutStyle;
import sun.swing.ImageIconUIResource;
import sun.swing.MnemonicHandler;
@ -184,9 +182,7 @@ public class WindowsLookAndFeel extends BasicLookAndFeel
// performance and compatibility issues, so allow this feature
// to be switched off either at runtime or programmatically
//
@SuppressWarnings("removal")
String systemFonts = java.security.AccessController.doPrivileged(
new GetPropertyAction("swing.useSystemFontSettings"));
String systemFonts = System.getProperty("swing.useSystemFontSettings");
useSystemFontSettings = systemFonts == null || Boolean.parseBoolean(systemFonts);
if (useSystemFontSettings) {
@ -596,8 +592,7 @@ public class WindowsLookAndFeel extends BasicLookAndFeel
if (!(this instanceof WindowsClassicLookAndFeel) &&
(OSInfo.getOSType() == OSInfo.OSType.WINDOWS &&
OSInfo.getWindowsVersion().compareTo(OSInfo.WINDOWS_XP) >= 0)) {
@SuppressWarnings("removal")
String prop = AccessController.doPrivileged(new GetPropertyAction("swing.noxp"));
String prop = System.getProperty("swing.noxp");
if (prop == null) {
// These desktop properties are not used directly, but are needed to

View File

@ -55,7 +55,6 @@ import java.awt.geom.AffineTransform;
import java.awt.image.BufferedImage;
import java.awt.image.DataBufferInt;
import java.awt.image.WritableRaster;
import java.security.AccessController;
import java.util.HashMap;
import javax.swing.AbstractButton;
@ -79,7 +78,6 @@ import javax.swing.text.JTextComponent;
import sun.awt.image.SunWritableRaster;
import sun.awt.windows.ThemeReader;
import sun.security.action.GetPropertyAction;
import sun.swing.CachedPainter;
import static com.sun.java.swing.plaf.windows.TMSchema.Part;
@ -124,7 +122,6 @@ class XPStyle {
* @return the singleton instance of this class or null if XP styles
* are not active or if this is not Windows XP
*/
@SuppressWarnings("removal")
static synchronized XPStyle getXP() {
if (themeActive == null) {
Toolkit toolkit = Toolkit.getDefaultToolkit();
@ -134,9 +131,8 @@ class XPStyle {
themeActive = Boolean.FALSE;
}
if (themeActive.booleanValue()) {
GetPropertyAction propertyAction =
new GetPropertyAction("swing.noxp");
if (AccessController.doPrivileged(propertyAction) == null &&
String propertyAction = System.getProperty("swing.noxp");
if (propertyAction == null &&
ThemeReader.isThemed() &&
!(UIManager.getLookAndFeel()
instanceof WindowsClassicLookAndFeel)) {

View File

@ -39,15 +39,9 @@ public class PlatformGraphicsInfo {
hasDisplays = hasDisplays0();
}
@SuppressWarnings({"removal", "restricted"})
@SuppressWarnings("restricted")
private static void loadAWTLibrary() {
java.security.AccessController.doPrivileged(
new java.security.PrivilegedAction<Void>() {
public Void run() {
System.loadLibrary("awt");
return null;
}
});
System.loadLibrary("awt");
}
private static native boolean hasDisplays0();

View File

@ -29,13 +29,12 @@ package sun.awt;
import java.awt.FontFormatException;
import java.awt.GraphicsEnvironment;
import java.io.File;
import java.security.AccessController;
import java.security.PrivilegedAction;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Locale;
import java.util.NoSuchElementException;
import java.util.StringTokenizer;
import java.util.function.Supplier;
import sun.awt.windows.WFontConfiguration;
import sun.font.FontManager;
@ -47,24 +46,21 @@ import sun.font.TrueTypeFont;
*/
public final class Win32FontManager extends SunFontManager {
@SuppressWarnings("removal")
private static final TrueTypeFont eudcFont =
AccessController.doPrivileged(new PrivilegedAction<TrueTypeFont>() {
public TrueTypeFont run() {
String eudcFile = getEUDCFontFile();
if (eudcFile != null) {
try {
/* Must use Java rasteriser since GDI doesn't
* enumerate (allow direct use) of EUDC fonts.
*/
return new TrueTypeFont(eudcFile, null, 0,
true, false);
} catch (FontFormatException e) {
}
((Supplier<TrueTypeFont>) () -> {
String eudcFile = getEUDCFontFile();
if (eudcFile != null) {
try {
/* Must use Java rasteriser since GDI doesn't
* enumerate (allow direct use) of EUDC fonts.
*/
return new TrueTypeFont(eudcFile, null, 0,
true, false);
} catch (FontFormatException e) {
}
return null;
}
});
return null;
}).get();
/* Used on Windows to obtain from the windows registry the name
* of a file containing the system EUFC font. If running in one of
@ -78,20 +74,14 @@ public final class Win32FontManager extends SunFontManager {
return eudcFont;
}
@SuppressWarnings("removal")
public Win32FontManager() {
super();
AccessController.doPrivileged(new PrivilegedAction<Object>() {
public Object run() {
/* Register the JRE fonts so that the native platform can
* access them. This is used only on Windows so that when
* printing the printer driver can access the fonts.
*/
registerJREFontsWithPlatform(jreFontDirName);
return null;
}
});
/* Register the JRE fonts so that the native platform can
* access them. This is used only on Windows so that when
* printing the printer driver can access the fonts.
*/
registerJREFontsWithPlatform(jreFontDirName);
}
/**
@ -213,21 +203,15 @@ public final class Win32FontManager extends SunFontManager {
info[1] = "c:\\windows\\fonts";
final String[] dirs = getPlatformFontDirs(true);
if (dirs.length > 1) {
@SuppressWarnings("removal")
String dir = (String)
AccessController.doPrivileged(new PrivilegedAction<Object>() {
public Object run() {
for (int i=0; i<dirs.length; i++) {
String path =
dirs[i] + File.separator + "arial.ttf";
File file = new File(path);
if (file.exists()) {
return dirs[i];
}
}
return null;
}
});
String dir = null;
for (int i=0; i<dirs.length; i++) {
String path = dirs[i] + File.separator + "arial.ttf";
File file = new File(path);
if (file.exists()) {
dir = dirs[i];
break;
}
}
if (dir != null) {
info[1] = dir;
}
@ -248,7 +232,6 @@ public final class Win32FontManager extends SunFontManager {
fontsForPrinting = pathName;
}
@SuppressWarnings("removal")
public static void registerJREFontsForPrinting() {
final String pathName;
synchronized (Win32GraphicsEnvironment.class) {
@ -259,22 +242,15 @@ public final class Win32FontManager extends SunFontManager {
pathName = fontsForPrinting;
fontsForPrinting = null;
}
java.security.AccessController.doPrivileged(
new java.security.PrivilegedAction<Object>() {
public Object run() {
File f1 = new File(pathName);
String[] ls = f1.list(SunFontManager.getInstance().
getTrueTypeFilter());
if (ls == null) {
return null;
}
for (int i=0; i <ls.length; i++ ) {
File fontFile = new File(f1, ls[i]);
registerFontWithPlatform(fontFile.getAbsolutePath());
}
return null;
}
});
File f1 = new File(pathName);
String[] ls = f1.list(SunFontManager.getInstance().
getTrueTypeFilter());
if (ls != null) {
for (int i=0; i <ls.length; i++ ) {
File fontFile = new File(f1, ls[i]);
registerFontWithPlatform(fontFile.getAbsolutePath());
}
}
}
private static native void registerFontWithPlatform(String fontName);

View File

@ -100,9 +100,7 @@ public class Win32GraphicsDevice extends GraphicsDevice implements
// is run as an NT service. To prevent the loading of ddraw.dll
// completely, sun.awt.nopixfmt should be set as well. Apps which use
// OpenGL w/ Java probably don't want to set this.
@SuppressWarnings("removal")
String nopixfmt = java.security.AccessController.doPrivileged(
new sun.security.action.GetPropertyAction("sun.awt.nopixfmt"));
String nopixfmt = System.getProperty("sun.awt.nopixfmt");
pfDisabled = (nopixfmt != null);
initIDs();
}

View File

@ -31,8 +31,6 @@ import java.awt.image.BufferedImage;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.security.AccessController;
import java.security.PrivilegedAction;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
@ -478,12 +476,7 @@ final class Win32ShellFolderManager2 extends ShellFolderManager {
if (dir != null && dir == getDrives()) {
return true;
} else {
@SuppressWarnings("removal")
String path = AccessController.doPrivileged(new PrivilegedAction<String>() {
public String run() {
return dir.getAbsolutePath();
}
});
String path = dir.getAbsolutePath();
return (path.startsWith("\\\\") && path.indexOf("\\", 2) < 0); //Network path
}
@ -572,25 +565,17 @@ final class Win32ShellFolderManager2 extends ShellFolderManager {
private static class ComInvoker extends ThreadPoolExecutor implements ThreadFactory, ShellFolder.Invoker {
private static Thread comThread;
@SuppressWarnings("removal")
private ComInvoker() {
super(1, 1, 0, TimeUnit.DAYS, new LinkedBlockingQueue<>());
allowCoreThreadTimeOut(false);
setThreadFactory(this);
final Runnable shutdownHook = () -> AccessController.doPrivileged((PrivilegedAction<Void>) () -> {
shutdownNow();
return null;
});
AccessController.doPrivileged((PrivilegedAction<Void>) () -> {
Thread t = new Thread(
ThreadGroupUtils.getRootThreadGroup(), shutdownHook,
"ShellFolder", 0, false);
Runtime.getRuntime().addShutdownHook(t);
return null;
});
final Runnable shutdownHook = () -> shutdownNow();
Thread t = new Thread(
ThreadGroupUtils.getRootThreadGroup(), shutdownHook,
"ShellFolder", 0, false);
Runtime.getRuntime().addShutdownHook(t);
}
@SuppressWarnings("removal")
public synchronized Thread newThread(final Runnable task) {
final Runnable comRun = new Runnable() {
public void run() {
@ -602,27 +587,22 @@ final class Win32ShellFolderManager2 extends ShellFolderManager {
}
}
};
comThread = AccessController.doPrivileged((PrivilegedAction<Thread>) () -> {
String name = "Swing-Shell";
/* The thread must be a member of a thread group
* which will not get GCed before VM exit.
* Make its parent the top-level thread group.
*/
Thread thread = new Thread(
ThreadGroupUtils.getRootThreadGroup(), comRun, name,
0, false);
thread.setDaemon(true);
/* This is important, since this thread running at lower priority
leads to memory consumption when listDrives() function is called
repeatedly.
*/
thread.setPriority(Thread.MAX_PRIORITY);
return thread;
});
/* The thread must be a member of a thread group
* which will not get GCed before VM exit.
* Make its parent the top-level thread group.
*/
comThread = new Thread(
ThreadGroupUtils.getRootThreadGroup(), comRun, "Swing-Shell",
0, false);
comThread.setDaemon(true);
/* This is important, since this thread running at lower priority
leads to memory consumption when listDrives() function is called
repeatedly.
*/
comThread.setPriority(Thread.MAX_PRIORITY);
return comThread;
}
@SuppressWarnings("removal")
public <T> T invoke(Callable<T> task) throws Exception {
if (Thread.currentThread() == comThread) {
// if it's already called from the COM
@ -640,13 +620,8 @@ final class Win32ShellFolderManager2 extends ShellFolderManager {
try {
return future.get();
} catch (InterruptedException e) {
AccessController.doPrivileged(new PrivilegedAction<Void>() {
public Void run() {
future.cancel(true);
future.cancel(true);
return null;
}
});
throw e;
} catch (ExecutionException e) {

View File

@ -35,7 +35,6 @@ import java.awt.geom.AffineTransform;
import java.awt.image.BufferedImage;
import java.awt.image.DataBufferInt;
import java.awt.image.VolatileImage;
import java.security.AccessController;
import sun.awt.image.BufImgSurfaceData;
import sun.java2d.DestSurfaceProvider;
import sun.java2d.InvalidPipeException;
@ -45,7 +44,6 @@ import sun.java2d.pipe.RenderQueue;
import sun.java2d.pipe.BufferedContext;
import sun.java2d.pipe.hw.AccelGraphicsConfig;
import sun.java2d.pipe.hw.AccelSurface;
import sun.security.action.GetPropertyAction;
import static java.awt.image.VolatileImage.*;
import static sun.java2d.pipe.hw.AccelSurface.*;
@ -66,14 +64,10 @@ abstract class TranslucentWindowPainter {
protected WWindowPeer peer;
// REMIND: we probably would want to remove this later
@SuppressWarnings("removal")
private static final boolean forceOpt =
Boolean.parseBoolean(AccessController.doPrivileged(
new GetPropertyAction("sun.java2d.twp.forceopt", "false")));
@SuppressWarnings("removal")
private static final boolean forceSW =
Boolean.parseBoolean(AccessController.doPrivileged(
new GetPropertyAction("sun.java2d.twp.forcesw", "false")));
private static final boolean forceOpt =
Boolean.getBoolean("sun.java2d.twp.forceopt");
private static final boolean forceSW =
Boolean.getBoolean("sun.java2d.twp.forcesw");
/**
* Creates an instance of the painter for particular peer.

View File

@ -32,11 +32,8 @@ import java.awt.peer.ComponentPeer;
import java.awt.image.*;
import sun.awt.image.ByteInterleavedRaster;
import sun.security.action.GetPropertyAction;
import java.awt.peer.FramePeer;
import java.security.PrivilegedAction;
import java.security.AccessController;
@SuppressWarnings("serial") // JDK-implementation class
public class WEmbeddedFrame extends EmbeddedFrame {
@ -60,9 +57,7 @@ public class WEmbeddedFrame extends EmbeddedFrame {
*/
private boolean isEmbeddedInIE = false;
@SuppressWarnings("removal")
private static String printScale = AccessController.doPrivileged(
new GetPropertyAction("sun.java2d.print.pluginscalefactor"));
private static String printScale = System.getProperty("sun.java2d.print.pluginscalefactor");
public WEmbeddedFrame() {
this((long)0);
@ -181,7 +176,6 @@ public class WEmbeddedFrame extends EmbeddedFrame {
}
}
@SuppressWarnings("removal")
protected static int getPrintScaleFactor() {
// check if value is already cached
if (pScale != 0)
@ -189,13 +183,7 @@ public class WEmbeddedFrame extends EmbeddedFrame {
if (printScale == null) {
// if no system property is specified,
// check for environment setting
printScale = AccessController.doPrivileged(
new PrivilegedAction<String>() {
public String run() {
return System.getenv("JAVA2D_PLUGIN_PRINT_SCALE");
}
}
);
printScale = System.getenv("JAVA2D_PLUGIN_PRINT_SCALE");
}
int default_printDC_scale = 4;
int scale = default_printDC_scale;

View File

@ -30,8 +30,6 @@ import java.awt.dnd.DropTarget;
import java.awt.peer.*;
import java.io.File;
import java.io.FilenameFilter;
import java.security.AccessController;
import java.security.PrivilegedAction;
import java.util.ResourceBundle;
import java.util.MissingResourceException;
import java.util.Vector;
@ -197,19 +195,13 @@ final class WFileDialogPeer extends WWindowPeer implements FileDialogPeer {
//This whole static block is a part of 4152317 fix
static {
@SuppressWarnings("removal")
String filterString = AccessController.doPrivileged(
new PrivilegedAction<String>() {
@Override
public String run() {
try {
ResourceBundle rb = ResourceBundle.getBundle("sun.awt.windows.awtLocalization");
return rb.getString("allFiles");
} catch (MissingResourceException e) {
return "All Files";
}
}
});
String filterString;
try {
ResourceBundle rb = ResourceBundle.getBundle("sun.awt.windows.awtLocalization");
filterString = rb.getString("allFiles");
} catch (MissingResourceException e) {
filterString = "All Files";
}
setFilterString(filterString);
}

View File

@ -32,11 +32,9 @@ import java.awt.GraphicsConfiguration;
import java.awt.MenuBar;
import java.awt.Rectangle;
import java.awt.peer.FramePeer;
import java.security.AccessController;
import sun.awt.AWTAccessor;
import sun.awt.im.InputMethodManager;
import sun.security.action.GetPropertyAction;
import static sun.java2d.SunGraphicsEnvironment.getGCDeviceBounds;
import static sun.java2d.SunGraphicsEnvironment.toDeviceSpaceAbs;
@ -80,11 +78,8 @@ class WFramePeer extends WWindowPeer implements FramePeer {
private native void setMaximizedBounds(int x, int y, int w, int h);
private native void clearMaximizedBounds();
@SuppressWarnings("removal")
private static final boolean keepOnMinimize = "true".equals(
AccessController.doPrivileged(
new GetPropertyAction(
"sun.awt.keepWorkingSetOnMinimize")));
System.getProperty("sun.awt.keepWorkingSetOnMinimize"));
@Override
public final void setMaximizedBounds(Rectangle b) {

View File

@ -29,11 +29,8 @@ import java.util.MissingResourceException;
import java.awt.*;
import java.awt.peer.*;
import java.awt.event.ActionEvent;
import java.security.AccessController;
import java.security.PrivilegedAction;
import sun.util.logging.PlatformLogger;
@SuppressWarnings("removal")
class WMenuItemPeer extends WObjectPeer implements MenuItemPeer {
private static final PlatformLogger log = PlatformLogger.getLogger("sun.awt.WMenuItemPeer");
@ -146,20 +143,15 @@ class WMenuItemPeer extends WObjectPeer implements MenuItemPeer {
private static Font defaultMenuFont;
static {
defaultMenuFont = AccessController.doPrivileged(
new PrivilegedAction <Font> () {
public Font run() {
try {
ResourceBundle rb = ResourceBundle.getBundle("sun.awt.windows.awtLocalization");
return Font.decode(rb.getString("menuFont"));
} catch (MissingResourceException e) {
if (log.isLoggable(PlatformLogger.Level.FINE)) {
log.fine("WMenuItemPeer: " + e.getMessage()+". Using default MenuItem font.", e);
}
return new Font("SanSerif", Font.PLAIN, 11);
}
}
});
try {
ResourceBundle rb = ResourceBundle.getBundle("sun.awt.windows.awtLocalization");
defaultMenuFont = Font.decode(rb.getString("menuFont"));
} catch (MissingResourceException e) {
if (log.isLoggable(PlatformLogger.Level.FINE)) {
log.fine("WMenuItemPeer: " + e.getMessage()+". Using default MenuItem font.", e);
}
defaultMenuFont = new Font("SanSerif", Font.PLAIN, 11);
}
}
static Font getDefaultFont() {

View File

@ -95,11 +95,8 @@ final class WPathGraphics extends PathGraphics {
private static boolean useGDITextLayout = true;
private static boolean preferGDITextLayout = false;
static {
@SuppressWarnings("removal")
String textLayoutStr =
java.security.AccessController.doPrivileged(
new sun.security.action.GetPropertyAction(
"sun.java2d.print.enableGDITextLayout"));
String textLayoutStr = System.getProperty(
"sun.java2d.print.enableGDITextLayout");
if (textLayoutStr != null) {
useGDITextLayout = Boolean.getBoolean(textLayoutStr);

View File

@ -112,8 +112,6 @@ import java.awt.peer.TrayIconPeer;
import java.awt.peer.WindowPeer;
import java.beans.PropertyChangeListener;
import java.lang.ref.WeakReference;
import java.security.AccessController;
import java.security.PrivilegedAction;
import java.util.Hashtable;
import java.util.Locale;
import java.util.Map;
@ -168,17 +166,11 @@ public final class WToolkit extends SunToolkit implements Runnable {
*/
private static native void initIDs();
private static boolean loaded = false;
@SuppressWarnings({"removal", "restricted"})
@SuppressWarnings("restricted")
public static void loadLibraries() {
if (!loaded) {
java.security.AccessController.doPrivileged(
new java.security.PrivilegedAction<Void>() {
@Override
public Void run() {
System.loadLibrary("awt");
return null;
}
});
System.loadLibrary("awt");
loaded = true;
}
}
@ -208,7 +200,6 @@ public final class WToolkit extends SunToolkit implements Runnable {
private static native boolean startToolkitThread(Runnable thread, ThreadGroup rootThreadGroup);
@SuppressWarnings("removal")
public WToolkit() {
// Startup toolkit threads
if (PerformanceLogger.loggingEnabled()) {
@ -225,16 +216,12 @@ public final class WToolkit extends SunToolkit implements Runnable {
AWTAutoShutdown.notifyToolkitThreadBusy();
// Find a root TG and attach toolkit thread to it
ThreadGroup rootTG = AccessController.doPrivileged(
(PrivilegedAction<ThreadGroup>) ThreadGroupUtils::getRootThreadGroup);
ThreadGroup rootTG = ThreadGroupUtils.getRootThreadGroup();
if (!startToolkitThread(this, rootTG)) {
final String name = "AWT-Windows";
AccessController.doPrivileged((PrivilegedAction<Void>) () -> {
Thread toolkitThread = new Thread(rootTG, this, name, 0, false);
toolkitThread.setDaemon(true);
toolkitThread.start();
return null;
});
Thread toolkitThread = new Thread(rootTG, this, name, 0, false);
toolkitThread.setDaemon(true);
toolkitThread.start();
}
try {
@ -251,36 +238,25 @@ public final class WToolkit extends SunToolkit implements Runnable {
// by the native system though.
setDynamicLayout(true);
final String extraButtons = "sun.awt.enableExtraMouseButtons";
AccessController.doPrivileged((PrivilegedAction<Void>) () -> {
areExtraMouseButtonsEnabled =
Boolean.parseBoolean(System.getProperty(extraButtons, "true"));
//set system property if not yet assigned
System.setProperty(extraButtons, ""+areExtraMouseButtonsEnabled);
return null;
});
areExtraMouseButtonsEnabled =
Boolean.parseBoolean(System.getProperty(extraButtons, "true"));
//set system property if not yet assigned
System.setProperty(extraButtons, ""+areExtraMouseButtonsEnabled);
setExtraMouseButtonsEnabledNative(areExtraMouseButtonsEnabled);
}
@SuppressWarnings("removal")
private void registerShutdownHook() {
AccessController.doPrivileged((PrivilegedAction<Void>) () -> {
Thread shutdown = new Thread(
ThreadGroupUtils.getRootThreadGroup(), this::shutdown,
"ToolkitShutdown", 0, false);
shutdown.setContextClassLoader(null);
Runtime.getRuntime().addShutdownHook(shutdown);
return null;
});
}
Thread shutdown = new Thread(
ThreadGroupUtils.getRootThreadGroup(), this::shutdown,
"ToolkitShutdown", 0, false);
shutdown.setContextClassLoader(null);
Runtime.getRuntime().addShutdownHook(shutdown);
}
@SuppressWarnings("removal")
@Override
public void run() {
AccessController.doPrivileged((PrivilegedAction<Void>) () -> {
Thread.currentThread().setContextClassLoader(null);
Thread.currentThread().setPriority(Thread.NORM_PRIORITY + 1);
return null;
});
Thread.currentThread().setContextClassLoader(null);
Thread.currentThread().setPriority(Thread.NORM_PRIORITY + 1);
boolean startPump = init();

View File

@ -32,8 +32,6 @@ import java.awt.Font;
import java.awt.Graphics2D;
import java.awt.Rectangle;
import java.awt.Window;
import java.security.AccessController;
import java.security.PrivilegedAction;
import java.util.ArrayList;
import java.util.HashMap;
@ -91,25 +89,21 @@ public class D3DScreenUpdateManager extends ScreenUpdateManager
*/
private HashMap<D3DWindowSurfaceData, GDIWindowSurfaceData> gdiSurfaces;
@SuppressWarnings("removal")
public D3DScreenUpdateManager() {
done = false;
AccessController.doPrivileged((PrivilegedAction<Void>) () -> {
Runnable shutdownRunnable = () -> {
done = true;
wakeUpUpdateThread();
};
Thread shutdown = new Thread(
ThreadGroupUtils.getRootThreadGroup(), shutdownRunnable,
"ScreenUpdater", 0, false);
shutdown.setContextClassLoader(null);
try {
Runtime.getRuntime().addShutdownHook(shutdown);
} catch (Exception e) {
done = true;
}
return null;
});
Runnable shutdownRunnable = () -> {
done = true;
wakeUpUpdateThread();
};
Thread shutdown = new Thread(
ThreadGroupUtils.getRootThreadGroup(), shutdownRunnable,
"ScreenUpdater", 0, false);
shutdown.setContextClassLoader(null);
try {
Runtime.getRuntime().addShutdownHook(shutdown);
} catch (Exception e) {
done = true;
}
}
/**
@ -345,19 +339,15 @@ public class D3DScreenUpdateManager extends ScreenUpdateManager
* If the update thread hasn't yet been created, it will be;
* otherwise it is awaken
*/
@SuppressWarnings("removal")
private synchronized void startUpdateThread() {
if (screenUpdater == null) {
screenUpdater = AccessController.doPrivileged((PrivilegedAction<Thread>) () -> {
String name = "D3D Screen Updater";
Thread t = new Thread(
String name = "D3D Screen Updater";
screenUpdater = new Thread(
ThreadGroupUtils.getRootThreadGroup(), this, name,
0, false);
// REMIND: should it be higher?
t.setPriority(Thread.NORM_PRIORITY + 2);
t.setDaemon(true);
return t;
});
// REMIND: should it be higher?
screenUpdater.setPriority(Thread.NORM_PRIORITY + 2);
screenUpdater.setDaemon(true);
screenUpdater.start();
} else {
wakeUpUpdateThread();

View File

@ -176,65 +176,57 @@ public class WindowsFlags {
return (propString != null) ? true : false;
}
@SuppressWarnings("removal")
private static void initJavaFlags() {
java.security.AccessController.doPrivileged(
new java.security.PrivilegedAction<Object>()
{
public Object run() {
magPresent = getBooleanProp(
"javax.accessibility.screen_magnifier_present", false);
boolean ddEnabled =
!getBooleanProp("sun.java2d.noddraw", magPresent);
boolean ddOffscreenEnabled =
getBooleanProp("sun.java2d.ddoffscreen", ddEnabled);
d3dEnabled = getBooleanProp("sun.java2d.d3d",
ddEnabled && ddOffscreenEnabled);
d3dOnScreenEnabled =
getBooleanProp("sun.java2d.d3d.onscreen", d3dEnabled);
oglEnabled = getBooleanProp("sun.java2d.opengl", false);
if (oglEnabled) {
oglVerbose = isBooleanPropTrueVerbose("sun.java2d.opengl");
if (WGLGraphicsConfig.isWGLAvailable()) {
d3dEnabled = false;
} else {
if (oglVerbose) {
System.out.println(
"Could not enable OpenGL pipeline " +
"(WGL not available)");
}
oglEnabled = false;
}
}
gdiBlitEnabled = getBooleanProp("sun.java2d.gdiBlit", true);
d3dSet = getPropertySet("sun.java2d.d3d");
if (d3dSet) {
d3dVerbose = isBooleanPropTrueVerbose("sun.java2d.d3d");
}
offscreenSharingEnabled =
getBooleanProp("sun.java2d.offscreenSharing", false);
String dpiOverride = System.getProperty("sun.java2d.dpiaware");
if (dpiOverride != null) {
setHighDPIAware = dpiOverride.equalsIgnoreCase("true");
} else {
String sunLauncherProperty =
System.getProperty("sun.java.launcher", "unknown");
setHighDPIAware =
sunLauncherProperty.equalsIgnoreCase("SUN_STANDARD");
}
/*
// Output info based on some non-default flags:
if (offscreenSharingEnabled) {
magPresent = getBooleanProp(
"javax.accessibility.screen_magnifier_present", false);
boolean ddEnabled =
!getBooleanProp("sun.java2d.noddraw", magPresent);
boolean ddOffscreenEnabled =
getBooleanProp("sun.java2d.ddoffscreen", ddEnabled);
d3dEnabled = getBooleanProp("sun.java2d.d3d",
ddEnabled && ddOffscreenEnabled);
d3dOnScreenEnabled =
getBooleanProp("sun.java2d.d3d.onscreen", d3dEnabled);
oglEnabled = getBooleanProp("sun.java2d.opengl", false);
if (oglEnabled) {
oglVerbose = isBooleanPropTrueVerbose("sun.java2d.opengl");
if (WGLGraphicsConfig.isWGLAvailable()) {
d3dEnabled = false;
} else {
if (oglVerbose) {
System.out.println(
"Warning: offscreenSharing has been enabled. " +
"The use of this capability will change in future " +
"releases and applications that depend on it " +
"may not work correctly");
"Could not enable OpenGL pipeline " +
"(WGL not available)");
}
*/
return null;
oglEnabled = false;
}
});
}
gdiBlitEnabled = getBooleanProp("sun.java2d.gdiBlit", true);
d3dSet = getPropertySet("sun.java2d.d3d");
if (d3dSet) {
d3dVerbose = isBooleanPropTrueVerbose("sun.java2d.d3d");
}
offscreenSharingEnabled =
getBooleanProp("sun.java2d.offscreenSharing", false);
String dpiOverride = System.getProperty("sun.java2d.dpiaware");
if (dpiOverride != null) {
setHighDPIAware = dpiOverride.equalsIgnoreCase("true");
} else {
String sunLauncherProperty =
System.getProperty("sun.java.launcher", "unknown");
setHighDPIAware =
sunLauncherProperty.equalsIgnoreCase("SUN_STANDARD");
}
/*
// Output info based on some non-default flags:
if (offscreenSharingEnabled) {
System.out.println(
"Warning: offscreenSharing has been enabled. " +
"The use of this capability will change in future " +
"releases and applications that depend on it " +
"may not work correctly");
}
*/
/*
System.out.println("WindowsFlags (Java):");
System.out.println(" ddEnabled: " + ddEnabled + "\n" +

View File

@ -25,8 +25,6 @@
package sun.print;
import java.security.AccessController;
import java.security.PrivilegedAction;
import java.util.ArrayList;
import javax.print.DocFlavor;
@ -54,15 +52,9 @@ public class PrintServiceLookupProvider extends PrintServiceLookup {
loadAWTLibrary();
}
@SuppressWarnings({"removal", "restricted"})
@SuppressWarnings("restricted")
private static void loadAWTLibrary() {
java.security.AccessController.doPrivileged(
new java.security.PrivilegedAction<Void>() {
public Void run() {
System.loadLibrary("awt");
return null;
}
});
System.loadLibrary("awt");
}
/* The singleton win32 print lookup service.
@ -85,31 +77,26 @@ public class PrintServiceLookupProvider extends PrintServiceLookup {
return win32PrintLUS;
}
@SuppressWarnings("removal")
public PrintServiceLookupProvider() {
if (win32PrintLUS == null) {
win32PrintLUS = this;
// start the local printer listener thread
AccessController.doPrivileged((PrivilegedAction<Thread>) () -> {
Thread thr = new Thread(ThreadGroupUtils.getRootThreadGroup(),
new PrinterChangeListener(),
"PrinterListener", 0, false);
thr.setContextClassLoader(null);
thr.setDaemon(true);
return thr;
}).start();
Thread thr = new Thread(ThreadGroupUtils.getRootThreadGroup(),
new PrinterChangeListener(),
"PrinterListener", 0, false);
thr.setContextClassLoader(null);
thr.setDaemon(true);
thr.start();
// start the remote printer listener thread
AccessController.doPrivileged((PrivilegedAction<Thread>) () -> {
Thread thr = new Thread(ThreadGroupUtils.getRootThreadGroup(),
new RemotePrinterChangeListener(),
"RemotePrinterListener", 0, false);
thr.setContextClassLoader(null);
thr.setDaemon(true);
return thr;
}).start();
Thread thr1 = new Thread(ThreadGroupUtils.getRootThreadGroup(),
new RemotePrinterChangeListener(),
"RemotePrinterListener", 0, false);
thr1.setContextClassLoader(null);
thr1.setDaemon(true);
thr1.start();
} /* else condition ought to never happen! */
}