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; package com.sun.java.swing.plaf.windows;
import java.security.AccessController;
import sun.security.action.GetBooleanAction;
import java.util.*; import java.util.*;
import java.beans.PropertyChangeListener; import java.beans.PropertyChangeListener;
import java.beans.PropertyChangeEvent; import java.beans.PropertyChangeEvent;
@ -67,9 +64,8 @@ import sun.awt.AppContext;
*/ */
class AnimationController implements ActionListener, PropertyChangeListener { class AnimationController implements ActionListener, PropertyChangeListener {
@SuppressWarnings("removal")
private static final boolean VISTA_ANIMATION_DISABLED = private static final boolean VISTA_ANIMATION_DISABLED =
AccessController.doPrivileged(new GetBooleanAction("swing.disablevistaanimation")); Boolean.getBoolean("swing.disablevistaanimation");
private static final Object ANIMATION_CONTROLLER_KEY = 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.ImageFilter;
import java.awt.image.ImageProducer; import java.awt.image.ImageProducer;
import java.awt.image.RGBImageFilter; import java.awt.image.RGBImageFilter;
import java.security.AccessController;
import javax.swing.AbstractAction; import javax.swing.AbstractAction;
import javax.swing.Action; import javax.swing.Action;
@ -90,7 +89,6 @@ import sun.awt.OSInfo;
import sun.awt.SunToolkit; import sun.awt.SunToolkit;
import sun.awt.shell.ShellFolder; import sun.awt.shell.ShellFolder;
import sun.font.FontUtilities; import sun.font.FontUtilities;
import sun.security.action.GetPropertyAction;
import sun.swing.DefaultLayoutStyle; import sun.swing.DefaultLayoutStyle;
import sun.swing.ImageIconUIResource; import sun.swing.ImageIconUIResource;
import sun.swing.MnemonicHandler; import sun.swing.MnemonicHandler;
@ -184,9 +182,7 @@ public class WindowsLookAndFeel extends BasicLookAndFeel
// performance and compatibility issues, so allow this feature // performance and compatibility issues, so allow this feature
// to be switched off either at runtime or programmatically // to be switched off either at runtime or programmatically
// //
@SuppressWarnings("removal") String systemFonts = System.getProperty("swing.useSystemFontSettings");
String systemFonts = java.security.AccessController.doPrivileged(
new GetPropertyAction("swing.useSystemFontSettings"));
useSystemFontSettings = systemFonts == null || Boolean.parseBoolean(systemFonts); useSystemFontSettings = systemFonts == null || Boolean.parseBoolean(systemFonts);
if (useSystemFontSettings) { if (useSystemFontSettings) {
@ -596,8 +592,7 @@ public class WindowsLookAndFeel extends BasicLookAndFeel
if (!(this instanceof WindowsClassicLookAndFeel) && if (!(this instanceof WindowsClassicLookAndFeel) &&
(OSInfo.getOSType() == OSInfo.OSType.WINDOWS && (OSInfo.getOSType() == OSInfo.OSType.WINDOWS &&
OSInfo.getWindowsVersion().compareTo(OSInfo.WINDOWS_XP) >= 0)) { OSInfo.getWindowsVersion().compareTo(OSInfo.WINDOWS_XP) >= 0)) {
@SuppressWarnings("removal") String prop = System.getProperty("swing.noxp");
String prop = AccessController.doPrivileged(new GetPropertyAction("swing.noxp"));
if (prop == null) { if (prop == null) {
// These desktop properties are not used directly, but are needed to // 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.BufferedImage;
import java.awt.image.DataBufferInt; import java.awt.image.DataBufferInt;
import java.awt.image.WritableRaster; import java.awt.image.WritableRaster;
import java.security.AccessController;
import java.util.HashMap; import java.util.HashMap;
import javax.swing.AbstractButton; import javax.swing.AbstractButton;
@ -79,7 +78,6 @@ import javax.swing.text.JTextComponent;
import sun.awt.image.SunWritableRaster; import sun.awt.image.SunWritableRaster;
import sun.awt.windows.ThemeReader; import sun.awt.windows.ThemeReader;
import sun.security.action.GetPropertyAction;
import sun.swing.CachedPainter; import sun.swing.CachedPainter;
import static com.sun.java.swing.plaf.windows.TMSchema.Part; 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 * @return the singleton instance of this class or null if XP styles
* are not active or if this is not Windows XP * are not active or if this is not Windows XP
*/ */
@SuppressWarnings("removal")
static synchronized XPStyle getXP() { static synchronized XPStyle getXP() {
if (themeActive == null) { if (themeActive == null) {
Toolkit toolkit = Toolkit.getDefaultToolkit(); Toolkit toolkit = Toolkit.getDefaultToolkit();
@ -134,9 +131,8 @@ class XPStyle {
themeActive = Boolean.FALSE; themeActive = Boolean.FALSE;
} }
if (themeActive.booleanValue()) { if (themeActive.booleanValue()) {
GetPropertyAction propertyAction = String propertyAction = System.getProperty("swing.noxp");
new GetPropertyAction("swing.noxp"); if (propertyAction == null &&
if (AccessController.doPrivileged(propertyAction) == null &&
ThemeReader.isThemed() && ThemeReader.isThemed() &&
!(UIManager.getLookAndFeel() !(UIManager.getLookAndFeel()
instanceof WindowsClassicLookAndFeel)) { instanceof WindowsClassicLookAndFeel)) {

View File

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

View File

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

View File

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

View File

@ -35,7 +35,6 @@ import java.awt.geom.AffineTransform;
import java.awt.image.BufferedImage; import java.awt.image.BufferedImage;
import java.awt.image.DataBufferInt; import java.awt.image.DataBufferInt;
import java.awt.image.VolatileImage; import java.awt.image.VolatileImage;
import java.security.AccessController;
import sun.awt.image.BufImgSurfaceData; import sun.awt.image.BufImgSurfaceData;
import sun.java2d.DestSurfaceProvider; import sun.java2d.DestSurfaceProvider;
import sun.java2d.InvalidPipeException; import sun.java2d.InvalidPipeException;
@ -45,7 +44,6 @@ import sun.java2d.pipe.RenderQueue;
import sun.java2d.pipe.BufferedContext; import sun.java2d.pipe.BufferedContext;
import sun.java2d.pipe.hw.AccelGraphicsConfig; import sun.java2d.pipe.hw.AccelGraphicsConfig;
import sun.java2d.pipe.hw.AccelSurface; import sun.java2d.pipe.hw.AccelSurface;
import sun.security.action.GetPropertyAction;
import static java.awt.image.VolatileImage.*; import static java.awt.image.VolatileImage.*;
import static sun.java2d.pipe.hw.AccelSurface.*; import static sun.java2d.pipe.hw.AccelSurface.*;
@ -66,14 +64,10 @@ abstract class TranslucentWindowPainter {
protected WWindowPeer peer; protected WWindowPeer peer;
// REMIND: we probably would want to remove this later // REMIND: we probably would want to remove this later
@SuppressWarnings("removal") private static final boolean forceOpt =
private static final boolean forceOpt = Boolean.getBoolean("sun.java2d.twp.forceopt");
Boolean.parseBoolean(AccessController.doPrivileged( private static final boolean forceSW =
new GetPropertyAction("sun.java2d.twp.forceopt", "false"))); Boolean.getBoolean("sun.java2d.twp.forcesw");
@SuppressWarnings("removal")
private static final boolean forceSW =
Boolean.parseBoolean(AccessController.doPrivileged(
new GetPropertyAction("sun.java2d.twp.forcesw", "false")));
/** /**
* Creates an instance of the painter for particular peer. * 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 java.awt.image.*;
import sun.awt.image.ByteInterleavedRaster; import sun.awt.image.ByteInterleavedRaster;
import sun.security.action.GetPropertyAction;
import java.awt.peer.FramePeer; import java.awt.peer.FramePeer;
import java.security.PrivilegedAction;
import java.security.AccessController;
@SuppressWarnings("serial") // JDK-implementation class @SuppressWarnings("serial") // JDK-implementation class
public class WEmbeddedFrame extends EmbeddedFrame { public class WEmbeddedFrame extends EmbeddedFrame {
@ -60,9 +57,7 @@ public class WEmbeddedFrame extends EmbeddedFrame {
*/ */
private boolean isEmbeddedInIE = false; private boolean isEmbeddedInIE = false;
@SuppressWarnings("removal") private static String printScale = System.getProperty("sun.java2d.print.pluginscalefactor");
private static String printScale = AccessController.doPrivileged(
new GetPropertyAction("sun.java2d.print.pluginscalefactor"));
public WEmbeddedFrame() { public WEmbeddedFrame() {
this((long)0); this((long)0);
@ -181,7 +176,6 @@ public class WEmbeddedFrame extends EmbeddedFrame {
} }
} }
@SuppressWarnings("removal")
protected static int getPrintScaleFactor() { protected static int getPrintScaleFactor() {
// check if value is already cached // check if value is already cached
if (pScale != 0) if (pScale != 0)
@ -189,13 +183,7 @@ public class WEmbeddedFrame extends EmbeddedFrame {
if (printScale == null) { if (printScale == null) {
// if no system property is specified, // if no system property is specified,
// check for environment setting // check for environment setting
printScale = AccessController.doPrivileged( printScale = System.getenv("JAVA2D_PLUGIN_PRINT_SCALE");
new PrivilegedAction<String>() {
public String run() {
return System.getenv("JAVA2D_PLUGIN_PRINT_SCALE");
}
}
);
} }
int default_printDC_scale = 4; int default_printDC_scale = 4;
int scale = default_printDC_scale; int scale = default_printDC_scale;

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -176,65 +176,57 @@ public class WindowsFlags {
return (propString != null) ? true : false; return (propString != null) ? true : false;
} }
@SuppressWarnings("removal")
private static void initJavaFlags() { private static void initJavaFlags() {
java.security.AccessController.doPrivileged( magPresent = getBooleanProp(
new java.security.PrivilegedAction<Object>() "javax.accessibility.screen_magnifier_present", false);
{ boolean ddEnabled =
public Object run() { !getBooleanProp("sun.java2d.noddraw", magPresent);
magPresent = getBooleanProp( boolean ddOffscreenEnabled =
"javax.accessibility.screen_magnifier_present", false); getBooleanProp("sun.java2d.ddoffscreen", ddEnabled);
boolean ddEnabled = d3dEnabled = getBooleanProp("sun.java2d.d3d",
!getBooleanProp("sun.java2d.noddraw", magPresent); ddEnabled && ddOffscreenEnabled);
boolean ddOffscreenEnabled = d3dOnScreenEnabled =
getBooleanProp("sun.java2d.ddoffscreen", ddEnabled); getBooleanProp("sun.java2d.d3d.onscreen", d3dEnabled);
d3dEnabled = getBooleanProp("sun.java2d.d3d", oglEnabled = getBooleanProp("sun.java2d.opengl", false);
ddEnabled && ddOffscreenEnabled); if (oglEnabled) {
d3dOnScreenEnabled = oglVerbose = isBooleanPropTrueVerbose("sun.java2d.opengl");
getBooleanProp("sun.java2d.d3d.onscreen", d3dEnabled); if (WGLGraphicsConfig.isWGLAvailable()) {
oglEnabled = getBooleanProp("sun.java2d.opengl", false); d3dEnabled = false;
if (oglEnabled) { } else {
oglVerbose = isBooleanPropTrueVerbose("sun.java2d.opengl"); if (oglVerbose) {
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) {
System.out.println( System.out.println(
"Warning: offscreenSharing has been enabled. " + "Could not enable OpenGL pipeline " +
"The use of this capability will change in future " + "(WGL not available)");
"releases and applications that depend on it " +
"may not work correctly");
} }
*/ oglEnabled = false;
return null;
} }
}); }
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("WindowsFlags (Java):");
System.out.println(" ddEnabled: " + ddEnabled + "\n" + System.out.println(" ddEnabled: " + ddEnabled + "\n" +

View File

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