8344057: Remove doPrivileged calls from unix platform sources in the java.desktop module

Reviewed-by: prr
This commit is contained in:
Harshitha Onkar 2024-11-20 20:28:12 +00:00
parent da2d7a09f9
commit b9bf447209
25 changed files with 261 additions and 502 deletions

View File

@ -28,8 +28,6 @@ package sun.awt;
import java.io.File; import java.io.File;
import java.awt.GraphicsEnvironment; import java.awt.GraphicsEnvironment;
import java.awt.Toolkit; import java.awt.Toolkit;
import java.security.AccessController;
import java.security.PrivilegedAction;
public class PlatformGraphicsInfo { public class PlatformGraphicsInfo {
@ -47,14 +45,10 @@ public class PlatformGraphicsInfo {
* headless mode, in the case the application did not specify * headless mode, in the case the application did not specify
* a value for the java.awt.headless system property. * a value for the java.awt.headless system property.
*/ */
@SuppressWarnings("removal")
public static boolean getDefaultHeadlessProperty() { public static boolean getDefaultHeadlessProperty() {
boolean noDisplay = final String display = System.getenv("DISPLAY");
AccessController.doPrivileged((PrivilegedAction<Boolean>) () -> { boolean noDisplay = (display == null || display.trim().isEmpty());
final String display = System.getenv("DISPLAY");
return display == null || display.trim().isEmpty();
});
if (noDisplay) { if (noDisplay) {
return true; return true;
} }
@ -67,18 +61,16 @@ public class PlatformGraphicsInfo {
* code is also set up as headless from the start - it is not so easy * code is also set up as headless from the start - it is not so easy
* to try headful and then unwind that and then retry as headless. * to try headful and then unwind that and then retry as headless.
*/ */
boolean headless = boolean headless = false;
AccessController.doPrivileged((PrivilegedAction<Boolean>) () -> { String[] libDirs = System.getProperty("sun.boot.library.path", "").split(":");
String[] libDirs = System.getProperty("sun.boot.library.path", "").split(":"); for (String libDir : libDirs) {
for (String libDir : libDirs) { File headlessLib = new File(libDir, "libawt_headless.so");
File headlessLib = new File(libDir, "libawt_headless.so"); File xawtLib = new File(libDir, "libawt_xawt.so");
File xawtLib = new File(libDir, "libawt_xawt.so"); if (headlessLib.exists() && !xawtLib.exists()) {
if (headlessLib.exists() && !xawtLib.exists()) { headless = true;
return true; break;
} }
} }
return false;
});
return headless; return headless;
} }

View File

@ -105,9 +105,7 @@ public abstract class UNIXToolkit extends SunToolkit
private BufferedImage tmpImage = null; private BufferedImage tmpImage = null;
public static int getDatatransferTimeout() { public static int getDatatransferTimeout() {
@SuppressWarnings("removal") Integer dt = Integer.getInteger("sun.awt.datatransfer.timeout");
Integer dt = AccessController.doPrivileged(
new GetIntegerAction("sun.awt.datatransfer.timeout"));
if (dt == null || dt <= 0) { if (dt == null || dt <= 0) {
return DEFAULT_DATATRANSFER_TIMEOUT; return DEFAULT_DATATRANSFER_TIMEOUT;
} else { } else {
@ -118,18 +116,12 @@ public abstract class UNIXToolkit extends SunToolkit
@Override @Override
public String getDesktop() { public String getDesktop() {
String gnome = "gnome"; String gnome = "gnome";
@SuppressWarnings("removal") String gsi = System.getenv("GNOME_DESKTOP_SESSION_ID");
String gsi = AccessController.doPrivileged(
(PrivilegedAction<String>) ()
-> System.getenv("GNOME_DESKTOP_SESSION_ID"));
if (gsi != null) { if (gsi != null) {
return gnome; return gnome;
} }
@SuppressWarnings("removal") String desktop = System.getenv("XDG_CURRENT_DESKTOP");
String desktop = AccessController.doPrivileged(
(PrivilegedAction<String>) ()
-> System.getenv("XDG_CURRENT_DESKTOP"));
return (desktop != null && desktop.toLowerCase().contains(gnome)) return (desktop != null && desktop.toLowerCase().contains(gnome))
? gnome : null; ? gnome : null;
} }
@ -252,11 +244,7 @@ public abstract class UNIXToolkit extends SunToolkit
result = shouldDisableSystemTray; result = shouldDisableSystemTray;
if (result == null) { if (result == null) {
if ("gnome".equals(getDesktop())) { if ("gnome".equals(getDesktop())) {
@SuppressWarnings("removal") Integer gnomeShellMajorVersion = getGnomeShellMajorVersion();
Integer gnomeShellMajorVersion =
AccessController
.doPrivileged((PrivilegedAction<Integer>)
this::getGnomeShellMajorVersion);
if (gnomeShellMajorVersion == null if (gnomeShellMajorVersion == null
|| gnomeShellMajorVersion < 45) { || gnomeShellMajorVersion < 45) {
@ -486,9 +474,7 @@ public abstract class UNIXToolkit extends SunToolkit
} }
public static GtkVersions getEnabledGtkVersion() { public static GtkVersions getEnabledGtkVersion() {
@SuppressWarnings("removal") String version = System.getProperty("jdk.gtk.version");
String version = AccessController.doPrivileged(
new GetPropertyAction("jdk.gtk.version"));
if ("3".equals(version)) { if ("3".equals(version)) {
return GtkVersions.GTK3; return GtkVersions.GTK3;
} }
@ -499,32 +485,22 @@ public abstract class UNIXToolkit extends SunToolkit
return GtkVersions.getVersion(get_gtk_version()); return GtkVersions.getVersion(get_gtk_version());
} }
@SuppressWarnings("removal")
public static boolean isGtkVerbose() { public static boolean isGtkVerbose() {
return AccessController.doPrivileged((PrivilegedAction<Boolean>)() return Boolean.getBoolean("jdk.gtk.verbose");
-> Boolean.getBoolean("jdk.gtk.verbose"));
} }
private static volatile Boolean isOnWayland = null; private static volatile Boolean isOnWayland = null;
@SuppressWarnings("removal")
public static boolean isOnWayland() { public static boolean isOnWayland() {
Boolean result = isOnWayland; Boolean result = isOnWayland;
if (result == null) { if (result == null) {
synchronized (GTK_LOCK) { synchronized (GTK_LOCK) {
result = isOnWayland; result = isOnWayland;
if (result == null) { if (result == null) {
final String display = System.getenv("WAYLAND_DISPLAY");
isOnWayland isOnWayland
= result = result
= AccessController.doPrivileged( = (display != null && !display.trim().isEmpty());
(PrivilegedAction<Boolean>) () -> {
final String display =
System.getenv("WAYLAND_DISPLAY");
return display != null
&& !display.trim().isEmpty();
}
);
} }
} }
} }

View File

@ -47,8 +47,6 @@ import java.awt.event.ActionEvent;
import java.awt.event.ActionListener; import java.awt.event.ActionListener;
import java.awt.event.MouseAdapter; import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent; import java.awt.event.MouseEvent;
import java.security.AccessController;
import java.security.PrivilegedAction;
import java.text.BreakIterator; import java.text.BreakIterator;
import java.util.concurrent.ArrayBlockingQueue; import java.util.concurrent.ArrayBlockingQueue;
@ -227,16 +225,8 @@ public abstract class InfoWindow extends Window {
textLabel.setText(tooltipString); textLabel.setText(tooltipString);
} }
@SuppressWarnings("removal") Point pointer = !isPointerOverTrayIcon(liveArguments.getBounds())
Point pointer = AccessController.doPrivileged( ? null : MouseInfo.getPointerInfo().getLocation();
new PrivilegedAction<Point>() {
public Point run() {
if (!isPointerOverTrayIcon(liveArguments.getBounds())) {
return null;
}
return MouseInfo.getPointerInfo().getLocation();
}
});
if (pointer == null) { if (pointer == null) {
return; return;
} }

View File

@ -27,8 +27,6 @@ package sun.awt.X11;
import jdk.internal.misc.Unsafe; import jdk.internal.misc.Unsafe;
import java.util.Vector; import java.util.Vector;
import java.security.AccessController;
import java.security.PrivilegedAction;
/** /**
* This class contains the collection of utility functions to help work with * This class contains the collection of utility functions to help work with
@ -43,13 +41,7 @@ class Native {
static int dataModel; static int dataModel;
static { static {
@SuppressWarnings("removal") String dataModelProp = System.getProperty("sun.arch.data.model");
String dataModelProp = AccessController.doPrivileged(
new PrivilegedAction<String>() {
public String run() {
return System.getProperty("sun.arch.data.model");
}
});
try { try {
dataModel = Integer.parseInt(dataModelProp); dataModel = Integer.parseInt(dataModelProp);
} catch (Exception e) { } catch (Exception e) {

View File

@ -29,14 +29,12 @@ import java.awt.datatransfer.Transferable;
import java.awt.datatransfer.DataFlavor; import java.awt.datatransfer.DataFlavor;
import java.util.SortedMap; import java.util.SortedMap;
import java.io.IOException; import java.io.IOException;
import java.security.AccessController;
import java.util.HashMap; import java.util.HashMap;
import java.util.Map; import java.util.Map;
import sun.awt.UNIXToolkit; import sun.awt.UNIXToolkit;
import sun.awt.datatransfer.DataTransferer; import sun.awt.datatransfer.DataTransferer;
import sun.awt.datatransfer.SunClipboard; import sun.awt.datatransfer.SunClipboard;
import sun.awt.datatransfer.ClipboardTransferable; import sun.awt.datatransfer.ClipboardTransferable;
import sun.security.action.GetIntegerAction;
/** /**
* A class which interfaces with the X11 selection service in order to support * A class which interfaces with the X11 selection service in order to support
@ -129,13 +127,11 @@ public final class XClipboard extends SunClipboard implements OwnershipListener
} }
} }
@SuppressWarnings("removal")
private static int getPollInterval() { private static int getPollInterval() {
synchronized (XClipboard.classLock) { synchronized (XClipboard.classLock) {
if (pollInterval <= 0) { if (pollInterval <= 0) {
pollInterval = AccessController.doPrivileged( pollInterval = Integer.getInteger("awt.datatransfer.clipboard.poll.interval"
new GetIntegerAction("awt.datatransfer.clipboard.poll.interval", , defaultPollInterval);
defaultPollInterval));
if (pollInterval <= 0) { if (pollInterval <= 0) {
pollInterval = defaultPollInterval; pollInterval = defaultPollInterval;
} }

View File

@ -35,9 +35,6 @@ import sun.util.logging.PlatformLogger;
import java.util.*; import java.util.*;
import static sun.awt.X11.XEmbedHelper.*; import static sun.awt.X11.XEmbedHelper.*;
import java.security.AccessController;
import sun.security.action.GetBooleanAction;
public class XEmbedCanvasPeer extends XCanvasPeer implements WindowFocusListener, KeyEventPostProcessor, ModalityListener, WindowIDProvider { public class XEmbedCanvasPeer extends XCanvasPeer implements WindowFocusListener, KeyEventPostProcessor, ModalityListener, WindowIDProvider {
private static final PlatformLogger xembedLog = PlatformLogger.getLogger("sun.awt.X11.xembed.XEmbedCanvasPeer"); private static final PlatformLogger xembedLog = PlatformLogger.getLogger("sun.awt.X11.xembed.XEmbedCanvasPeer");
@ -439,12 +436,11 @@ public class XEmbedCanvasPeer extends XCanvasPeer implements WindowFocusListener
} }
} }
@SuppressWarnings("removal")
void canvasFocusLost(FocusEvent e) { void canvasFocusLost(FocusEvent e) {
if (isXEmbedActive() && !e.isTemporary()) { if (isXEmbedActive() && !e.isTemporary()) {
xembedLog.fine("Forwarding FOCUS_LOST"); xembedLog.fine("Forwarding FOCUS_LOST");
int num = 0; int num = 0;
if (AccessController.doPrivileged(new GetBooleanAction("sun.awt.xembed.testing"))) { if (Boolean.getBoolean("sun.awt.xembed.testing")) {
Component opp = e.getOppositeComponent(); Component opp = e.getOppositeComponent();
try { try {
num = Integer.parseInt(opp.getName()); num = Integer.parseInt(opp.getName());

View File

@ -24,9 +24,7 @@
*/ */
package sun.awt.X11; package sun.awt.X11;
import java.security.AccessController;
import sun.awt.SunToolkit; import sun.awt.SunToolkit;
import sun.security.action.GetBooleanAction;
import sun.util.logging.PlatformLogger; import sun.util.logging.PlatformLogger;
/** /**
@ -59,9 +57,7 @@ public final class XErrorHandlerUtil {
/** /**
* Value of sun.awt.noisyerrorhandler system property. * Value of sun.awt.noisyerrorhandler system property.
*/ */
@SuppressWarnings("removal") private static boolean noisyAwtHandler = Boolean.getBoolean("sun.awt.noisyerrorhandler");
private static boolean noisyAwtHandler = AccessController.doPrivileged(
new GetBooleanAction("sun.awt.noisyerrorhandler"));
/** /**
* The flag indicating that {@code init} was called already. * The flag indicating that {@code init} was called already.

View File

@ -32,8 +32,6 @@ import java.awt.peer.*;
import java.io.*; import java.io.*;
import java.util.Locale; import java.util.Locale;
import java.util.Arrays; import java.util.Arrays;
import java.security.AccessController;
import java.security.PrivilegedAction;
import sun.awt.AWTAccessor.ComponentAccessor; import sun.awt.AWTAccessor.ComponentAccessor;
import sun.util.logging.PlatformLogger; import sun.util.logging.PlatformLogger;
@ -139,7 +137,7 @@ class XFileDialogPeer extends XDialogPeer
this.target = target; this.target = target;
} }
@SuppressWarnings({"removal","deprecation"}) @SuppressWarnings("deprecation")
private void init(FileDialog target) { private void init(FileDialog target) {
fileDialog = target; //new Dialog(target, target.getTitle(), false); fileDialog = target; //new Dialog(target, target.getTitle(), false);
this.title = target.getTitle(); this.title = target.getTitle();
@ -151,12 +149,7 @@ class XFileDialogPeer extends XDialogPeer
savedDir = target.getDirectory(); savedDir = target.getDirectory();
// Shouldn't save 'user.dir' to 'savedDir' // Shouldn't save 'user.dir' to 'savedDir'
// since getDirectory() will be incorrect after handleCancel // since getDirectory() will be incorrect after handleCancel
userDir = AccessController.doPrivileged( userDir = System.getProperty("user.dir");
new PrivilegedAction<String>() {
public String run() {
return System.getProperty("user.dir");
}
});
installStrings(); installStrings();
gbl = new GridBagLayout(); gbl = new GridBagLayout();

View File

@ -28,7 +28,6 @@ package sun.awt.X11;
import java.awt.Rectangle; import java.awt.Rectangle;
import java.awt.Toolkit; import java.awt.Toolkit;
import java.awt.peer.RobotPeer; import java.awt.peer.RobotPeer;
import java.security.AccessController;
import sun.awt.AWTAccessor; import sun.awt.AWTAccessor;
import sun.awt.SunToolkit; import sun.awt.SunToolkit;
@ -36,9 +35,7 @@ import sun.awt.UNIXToolkit;
import sun.awt.X11GraphicsConfig; import sun.awt.X11GraphicsConfig;
import sun.awt.X11GraphicsDevice; import sun.awt.X11GraphicsDevice;
import sun.awt.screencast.ScreencastHelper; import sun.awt.screencast.ScreencastHelper;
import sun.security.action.GetPropertyAction;
@SuppressWarnings("removal")
final class XRobotPeer implements RobotPeer { final class XRobotPeer implements RobotPeer {
private static final boolean tryGtk; private static final boolean tryGtk;
@ -50,10 +47,8 @@ final class XRobotPeer implements RobotPeer {
loadNativeLibraries(); loadNativeLibraries();
tryGtk = Boolean.parseBoolean( tryGtk = Boolean.parseBoolean(
AccessController.doPrivileged( System.getProperty("awt.robot.gtk", "true")
new GetPropertyAction("awt.robot.gtk", );
"true")
));
boolean isOnWayland = false; boolean isOnWayland = false;
@ -61,13 +56,12 @@ final class XRobotPeer implements RobotPeer {
isOnWayland = sunToolkit.isRunningOnWayland(); isOnWayland = sunToolkit.isRunningOnWayland();
} }
screenshotMethod = AccessController.doPrivileged( screenshotMethod = System.getProperty(
new GetPropertyAction(
"awt.robot.screenshotMethod", "awt.robot.screenshotMethod",
isOnWayland isOnWayland
? METHOD_SCREENCAST ? METHOD_SCREENCAST
: METHOD_X11 : METHOD_X11
)); );
} }
private static volatile boolean useGtk; private static volatile boolean useGtk;

View File

@ -31,9 +31,6 @@ import java.awt.peer.TaskbarPeer;
import java.awt.event.ActionEvent; import java.awt.event.ActionEvent;
import sun.awt.UNIXToolkit; import sun.awt.UNIXToolkit;
import java.security.AccessController;
import java.security.PrivilegedAction;
import sun.security.action.GetPropertyAction;
final class XTaskbarPeer implements TaskbarPeer { final class XTaskbarPeer implements TaskbarPeer {
@ -44,10 +41,7 @@ final class XTaskbarPeer implements TaskbarPeer {
private static boolean isUnity; private static boolean isUnity;
static { static {
@SuppressWarnings("removal") String de = System.getenv("XDG_CURRENT_DESKTOP");
String de = AccessController.doPrivileged(
(PrivilegedAction<String>) ()
-> System.getenv("XDG_CURRENT_DESKTOP"));
isUnity = "Unity".equals(de); isUnity = "Unity".equals(de);
} }
@ -55,9 +49,7 @@ final class XTaskbarPeer implements TaskbarPeer {
XToolkit.awtLock(); XToolkit.awtLock();
try { try {
if (!initExecuted) { if (!initExecuted) {
@SuppressWarnings("removal") String dname = System.getProperty("java.desktop.appName", "");
String dname = AccessController.doPrivileged(
new GetPropertyAction("java.desktop.appName", ""));
nativeLibraryLoaded = init(dname, nativeLibraryLoaded = init(dname,
UNIXToolkit.getEnabledGtkVersion().ordinal(), UNIXToolkit.getEnabledGtkVersion().ordinal(),
UNIXToolkit.isGtkVerbose()); UNIXToolkit.isGtkVerbose());

View File

@ -111,8 +111,6 @@ import java.awt.peer.TextFieldPeer;
import java.awt.peer.TrayIconPeer; 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.security.AccessController;
import java.security.PrivilegedAction;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Collection; import java.util.Collection;
import java.util.HashMap; import java.util.HashMap;
@ -147,8 +145,6 @@ import sun.awt.util.ThreadGroupUtils;
import sun.font.FontConfigManager; import sun.font.FontConfigManager;
import sun.java2d.SunGraphicsEnvironment; import sun.java2d.SunGraphicsEnvironment;
import sun.print.PrintJob2D; import sun.print.PrintJob2D;
import sun.security.action.GetBooleanAction;
import sun.security.action.GetPropertyAction;
import sun.util.logging.PlatformLogger; import sun.util.logging.PlatformLogger;
import static sun.awt.X11.XlibUtil.scaleDown; import static sun.awt.X11.XlibUtil.scaleDown;
@ -246,9 +242,7 @@ public final class XToolkit extends UNIXToolkit implements Runnable {
static void initSecurityWarning() { static void initSecurityWarning() {
// Enable warning only for internal builds // Enable warning only for internal builds
@SuppressWarnings("removal") String runtime = System.getProperty("java.runtime.version");
String runtime = AccessController.doPrivileged(
new GetPropertyAction("java.runtime.version"));
securityWarningEnabled = (runtime != null && runtime.contains("internal")); securityWarningEnabled = (runtime != null && runtime.contains("internal"));
} }
@ -326,7 +320,6 @@ public final class XToolkit extends UNIXToolkit implements Runnable {
} }
} }
@SuppressWarnings("removal")
void init() { void init() {
awtLock(); awtLock();
try { try {
@ -339,13 +332,10 @@ public final class XToolkit extends UNIXToolkit implements Runnable {
arrowCursor = XlibWrapper.XCreateFontCursor(XToolkit.getDisplay(), arrowCursor = XlibWrapper.XCreateFontCursor(XToolkit.getDisplay(),
XCursorFontConstants.XC_arrow); XCursorFontConstants.XC_arrow);
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;
});
// Detect display mode changes // Detect display mode changes
XlibWrapper.XSelectInput(XToolkit.getDisplay(), XToolkit.getDefaultRootWindow(), XConstants.StructureNotifyMask); XlibWrapper.XSelectInput(XToolkit.getDisplay(), XToolkit.getDefaultRootWindow(), XConstants.StructureNotifyMask);
XToolkit.addEventDispatcher(XToolkit.getDefaultRootWindow(), new XEventDispatcher() { XToolkit.addEventDispatcher(XToolkit.getDefaultRootWindow(), new XEventDispatcher() {
@ -370,28 +360,24 @@ public final class XToolkit extends UNIXToolkit implements Runnable {
} finally { } finally {
awtUnlock(); awtUnlock();
} }
PrivilegedAction<Void> a = () -> { Runnable r = () -> {
Runnable r = () -> { XSystemTrayPeer peer = XSystemTrayPeer.getPeerInstance();
XSystemTrayPeer peer = XSystemTrayPeer.getPeerInstance(); if (peer != null) {
if (peer != null) { peer.dispose();
peer.dispose(); }
} if (xs != null) {
if (xs != null) { ((XAWTXSettings)xs).dispose();
((XAWTXSettings)xs).dispose(); }
} freeXKB();
freeXKB(); if (log.isLoggable(PlatformLogger.Level.FINE)) {
if (log.isLoggable(PlatformLogger.Level.FINE)) { dumpPeers();
dumpPeers(); }
}
};
String name = "XToolkt-Shutdown-Thread";
Thread shutdownThread = new Thread(
ThreadGroupUtils.getRootThreadGroup(), r, name, 0, false);
shutdownThread.setContextClassLoader(null);
Runtime.getRuntime().addShutdownHook(shutdownThread);
return null;
}; };
AccessController.doPrivileged(a); String name = "XToolkt-Shutdown-Thread";
Thread shutdownThread = new Thread(
ThreadGroupUtils.getRootThreadGroup(), r, name, 0, false);
shutdownThread.setContextClassLoader(null);
Runtime.getRuntime().addShutdownHook(shutdownThread);
} }
static String getCorrectXIDString(String val) { static String getCorrectXIDString(String val) {
@ -409,7 +395,6 @@ public final class XToolkit extends UNIXToolkit implements Runnable {
return awtAppClassName; return awtAppClassName;
} }
@SuppressWarnings("removal")
public XToolkit() { public XToolkit() {
super(); super();
if (PerformanceLogger.loggingEnabled()) { if (PerformanceLogger.loggingEnabled()) {
@ -432,16 +417,13 @@ public final class XToolkit extends UNIXToolkit implements Runnable {
init(); init();
XWM.init(); XWM.init();
toolkitThread = AccessController.doPrivileged((PrivilegedAction<Thread>) () -> { String name = "AWT-XAWT";
String name = "AWT-XAWT"; toolkitThread = new Thread(
Thread thread = new Thread(
ThreadGroupUtils.getRootThreadGroup(), this, name, ThreadGroupUtils.getRootThreadGroup(), this, name,
0, false); 0, false);
thread.setContextClassLoader(null); toolkitThread.setContextClassLoader(null);
thread.setPriority(Thread.NORM_PRIORITY + 1); toolkitThread.setPriority(Thread.NORM_PRIORITY + 1);
thread.setDaemon(true); toolkitThread.setDaemon(true);
return thread;
});
toolkitThread.start(); toolkitThread.start();
} }
} }
@ -1120,11 +1102,9 @@ public final class XToolkit extends UNIXToolkit implements Runnable {
* Returns the value of "sun.awt.disableGtkFileDialogs" property. Default * Returns the value of "sun.awt.disableGtkFileDialogs" property. Default
* value is {@code false}. * value is {@code false}.
*/ */
@SuppressWarnings("removal")
public static synchronized boolean getSunAwtDisableGtkFileDialogs() { public static synchronized boolean getSunAwtDisableGtkFileDialogs() {
if (sunAwtDisableGtkFileDialogs == null) { if (sunAwtDisableGtkFileDialogs == null) {
sunAwtDisableGtkFileDialogs = AccessController.doPrivileged( sunAwtDisableGtkFileDialogs = Boolean.getBoolean("sun.awt.disableGtkFileDialogs");
new GetBooleanAction("sun.awt.disableGtkFileDialogs"));
} }
return sunAwtDisableGtkFileDialogs.booleanValue(); return sunAwtDisableGtkFileDialogs.booleanValue();
} }
@ -2139,9 +2119,7 @@ public final class XToolkit extends UNIXToolkit implements Runnable {
} }
private static void setBackingStoreType() { private static void setBackingStoreType() {
@SuppressWarnings("removal") String prop = System.getProperty("sun.awt.backingStore");
String prop = AccessController.doPrivileged(
new sun.security.action.GetPropertyAction("sun.awt.backingStore"));
if (prop == null) { if (prop == null) {
backingStoreType = XConstants.NotUseful; backingStoreType = XConstants.NotUseful;
@ -2565,8 +2543,7 @@ public final class XToolkit extends UNIXToolkit implements Runnable {
* Returns the value of "sun.awt.disablegrab" property. Default * Returns the value of "sun.awt.disablegrab" property. Default
* value is {@code false}. * value is {@code false}.
*/ */
@SuppressWarnings("removal")
public static boolean getSunAwtDisableGrab() { public static boolean getSunAwtDisableGrab() {
return AccessController.doPrivileged(new GetBooleanAction("sun.awt.disablegrab")); return Boolean.getBoolean("sun.awt.disablegrab");
} }
} }

View File

@ -30,8 +30,6 @@ import java.awt.event.*;
import java.awt.peer.TrayIconPeer; import java.awt.peer.TrayIconPeer;
import sun.awt.*; import sun.awt.*;
import java.awt.image.*; import java.awt.image.*;
import java.security.AccessController;
import java.security.PrivilegedAction;
import java.lang.reflect.InvocationTargetException; import java.lang.reflect.InvocationTargetException;
import sun.util.logging.PlatformLogger; import sun.util.logging.PlatformLogger;
@ -66,7 +64,6 @@ public class XTrayIconPeer implements TrayIconPeer,
static final int TRAY_ICON_WIDTH = 24; static final int TRAY_ICON_WIDTH = 24;
static final int TRAY_ICON_HEIGHT = 24; static final int TRAY_ICON_HEIGHT = 24;
@SuppressWarnings("removal")
XTrayIconPeer(TrayIcon target) XTrayIconPeer(TrayIcon target)
throws AWTException throws AWTException
{ {
@ -84,12 +81,7 @@ public class XTrayIconPeer implements TrayIconPeer,
// Fix for 6317038: as EmbeddedFrame is instance of Frame, it is blocked // Fix for 6317038: as EmbeddedFrame is instance of Frame, it is blocked
// by modal dialogs, but in the case of TrayIcon it shouldn't. So we // by modal dialogs, but in the case of TrayIcon it shouldn't. So we
// set ModalExclusion property on it. // set ModalExclusion property on it.
AccessController.doPrivileged(new PrivilegedAction<Object>() { eframe.setModalExclusionType(Dialog.ModalExclusionType.TOOLKIT_EXCLUDE);
public Object run() {
eframe.setModalExclusionType(Dialog.ModalExclusionType.TOOLKIT_EXCLUDE);
return null;
}
});
if (XWM.getWMID() != XWM.METACITY_WM) { if (XWM.getWMID() != XWM.METACITY_WM) {

View File

@ -25,10 +25,7 @@
package sun.awt.X11; package sun.awt.X11;
import java.security.AccessController;
import jdk.internal.misc.Unsafe; import jdk.internal.misc.Unsafe;
import sun.security.action.GetPropertyAction;
final class XlibWrapper { final class XlibWrapper {
@ -585,9 +582,7 @@ static native String XSetLocaleModifiers(String modifier_list);
static final boolean isBuildInternal; static final boolean isBuildInternal;
static { static {
@SuppressWarnings("removal") String dataModelProp = System.getProperty("sun.arch.data.model");
String dataModelProp = AccessController.doPrivileged(
new GetPropertyAction("sun.arch.data.model"));
try { try {
dataModel = Integer.parseInt(dataModelProp); dataModel = Integer.parseInt(dataModelProp);
} catch (Exception e) { } catch (Exception e) {
@ -639,9 +634,7 @@ static native String XSetLocaleModifiers(String modifier_list);
} }
private static boolean getBuildInternal() { private static boolean getBuildInternal() {
@SuppressWarnings("removal") String javaVersion = System.getProperty("java.version");
String javaVersion = AccessController.doPrivileged(
new GetPropertyAction("java.version"));
return javaVersion != null && javaVersion.contains("internal"); return javaVersion != null && javaVersion.contains("internal");
} }

View File

@ -33,8 +33,6 @@ import java.awt.GraphicsEnvironment;
import java.awt.Insets; import java.awt.Insets;
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.Collections; import java.util.Collections;
import java.util.HashMap; import java.util.HashMap;
@ -447,7 +445,6 @@ public final class X11GraphicsDevice extends GraphicsDevice
return modes.toArray(retArray); return modes.toArray(retArray);
} }
@SuppressWarnings("removal")
@Override @Override
public synchronized void setDisplayMode(DisplayMode dm) { public synchronized void setDisplayMode(DisplayMode dm) {
if (!isDisplayChangeSupported()) { if (!isDisplayChangeSupported()) {
@ -474,24 +471,20 @@ public final class X11GraphicsDevice extends GraphicsDevice
// is already in the original DisplayMode at that time, this // is already in the original DisplayMode at that time, this
// hook will have no effect) // hook will have no effect)
shutdownHookRegistered = true; shutdownHookRegistered = true;
PrivilegedAction<Void> a = () -> { Runnable r = () -> {
Runnable r = () -> { Window old = getFullScreenWindow();
Window old = getFullScreenWindow(); if (old != null) {
if (old != null) { exitFullScreenExclusive(old);
exitFullScreenExclusive(old); if (isDisplayChangeSupported()) {
if (isDisplayChangeSupported()) { setDisplayMode(origDisplayMode);
setDisplayMode(origDisplayMode);
}
} }
}; }
String name = "Display-Change-Shutdown-Thread-" + screen;
Thread t = new Thread(
ThreadGroupUtils.getRootThreadGroup(), r, name, 0, false);
t.setContextClassLoader(null);
Runtime.getRuntime().addShutdownHook(t);
return null;
}; };
AccessController.doPrivileged(a); String name = "Display-Change-Shutdown-Thread-" + screen;
Thread t = new Thread(
ThreadGroupUtils.getRootThreadGroup(), r, name, 0, false);
t.setContextClassLoader(null);
Runtime.getRuntime().addShutdownHook(t);
} }
// switch to the new DisplayMode // switch to the new DisplayMode

View File

@ -59,78 +59,71 @@ public final class X11GraphicsEnvironment extends SunGraphicsEnvironment {
initStatic(); initStatic();
} }
@SuppressWarnings({"removal", "restricted"}) @SuppressWarnings("restricted")
private static void initStatic() { private static void initStatic() {
java.security.AccessController.doPrivileged( System.loadLibrary("awt");
new java.security.PrivilegedAction<Object>() {
public Object run() {
System.loadLibrary("awt");
/* /*
* Note: The XToolkit object depends on the static initializer * Note: The XToolkit object depends on the static initializer
* of X11GraphicsEnvironment to initialize the connection to * of X11GraphicsEnvironment to initialize the connection to
* the X11 server. * the X11 server.
*/ */
if (!isHeadless()) { if (!isHeadless()) {
// first check the OGL system property // first check the OGL system property
boolean glxRequested = false; boolean glxRequested = false;
String prop = System.getProperty("sun.java2d.opengl"); String prop = System.getProperty("sun.java2d.opengl");
if (prop != null) { if (prop != null) {
if (prop.equals("true") || prop.equals("t")) { if (prop.equals("true") || prop.equals("t")) {
glxRequested = true; glxRequested = true;
} else if (prop.equals("True") || prop.equals("T")) { } else if (prop.equals("True") || prop.equals("T")) {
glxRequested = true; glxRequested = true;
glxVerbose = true; glxVerbose = true;
} }
} }
// Now check for XRender system property // Now check for XRender system property
boolean xRenderRequested = true; boolean xRenderRequested = true;
boolean xRenderIgnoreLinuxVersion = false; boolean xRenderIgnoreLinuxVersion = false;
String xProp = System.getProperty("sun.java2d.xrender"); String xProp = System.getProperty("sun.java2d.xrender");
if (xProp != null) { if (xProp != null) {
if (xProp.equals("false") || xProp.equals("f")) { if (xProp.equals("false") || xProp.equals("f")) {
xRenderRequested = false; xRenderRequested = false;
} else if (xProp.equals("True") || xProp.equals("T")) { } else if (xProp.equals("True") || xProp.equals("T")) {
xRenderRequested = true; xRenderRequested = true;
xRenderVerbose = true; xRenderVerbose = true;
}
if(xProp.equalsIgnoreCase("t") || xProp.equalsIgnoreCase("true")) {
xRenderIgnoreLinuxVersion = true;
}
}
// initialize the X11 display connection
initDisplay(glxRequested);
// only attempt to initialize GLX if it was requested
if (glxRequested) {
glxAvailable = initGLX();
if (glxVerbose && !glxAvailable) {
System.out.println(
"Could not enable OpenGL " +
"pipeline (GLX 1.3 not available)");
}
}
// only attempt to initialize Xrender if it was requested
if (xRenderRequested) {
xRenderAvailable = initXRender(xRenderVerbose, xRenderIgnoreLinuxVersion);
if (xRenderVerbose && !xRenderAvailable) {
System.out.println(
"Could not enable XRender pipeline");
}
}
if (xRenderAvailable) {
XRSurfaceData.initXRSurfaceData();
}
} }
return null; if (xProp.equalsIgnoreCase("t") || xProp.equalsIgnoreCase("true")) {
xRenderIgnoreLinuxVersion = true;
}
} }
});
// initialize the X11 display connection
initDisplay(glxRequested);
// only attempt to initialize GLX if it was requested
if (glxRequested) {
glxAvailable = initGLX();
if (glxVerbose && !glxAvailable) {
System.out.println(
"Could not enable OpenGL " +
"pipeline (GLX 1.3 not available)");
}
}
// only attempt to initialize Xrender if it was requested
if (xRenderRequested) {
xRenderAvailable = initXRender(xRenderVerbose, xRenderIgnoreLinuxVersion);
if (xRenderVerbose && !xRenderAvailable) {
System.out.println(
"Could not enable XRender pipeline");
}
}
if (xRenderAvailable) {
XRSurfaceData.initXRSurfaceData();
}
}
// Install the correct surface manager factory. // Install the correct surface manager factory.
SurfaceManagerFactory.setInstance(new UnixSurfaceManagerFactory()); SurfaceManagerFactory.setInstance(new UnixSurfaceManagerFactory());
@ -299,9 +292,7 @@ public final class X11GraphicsEnvironment extends SunGraphicsEnvironment {
return true; return true;
} }
@SuppressWarnings("removal") String isRemote = System.getProperty("sun.java2d.remote");
String isRemote = java.security.AccessController.doPrivileged(
new sun.security.action.GetPropertyAction("sun.java2d.remote"));
if (isRemote != null) { if (isRemote != null) {
return isRemote.equals("false"); return isRemote.equals("false");
} }
@ -322,41 +313,35 @@ public final class X11GraphicsEnvironment extends SunGraphicsEnvironment {
return true; return true;
} }
@SuppressWarnings("removal") InetAddress[] remAddr = null;
Boolean result = java.security.AccessController.doPrivileged( Enumeration<InetAddress> locals = null;
new java.security.PrivilegedAction<Boolean>() { Enumeration<NetworkInterface> interfaces = null;
public Boolean run() { try {
InetAddress[] remAddr = null; interfaces = NetworkInterface.getNetworkInterfaces();
Enumeration<InetAddress> locals = null; remAddr = InetAddress.getAllByName(hostName);
Enumeration<NetworkInterface> interfaces = null; if (remAddr == null) {
try { return false;
interfaces = NetworkInterface.getNetworkInterfaces(); }
remAddr = InetAddress.getAllByName(hostName); } catch (UnknownHostException e) {
if (remAddr == null) { System.err.println("Unknown host: " + hostName);
return Boolean.FALSE; return false;
} } catch (SocketException e1) {
} catch (UnknownHostException e) { System.err.println(e1.getMessage());
System.err.println("Unknown host: " + hostName); return false;
return Boolean.FALSE; }
} catch (SocketException e1) {
System.err.println(e1.getMessage());
return Boolean.FALSE;
}
for (; interfaces.hasMoreElements();) { for (; interfaces.hasMoreElements();) {
locals = interfaces.nextElement().getInetAddresses(); locals = interfaces.nextElement().getInetAddresses();
for (; locals.hasMoreElements();) { for (; locals.hasMoreElements();) {
final InetAddress localAddr = locals.nextElement(); final InetAddress localAddr = locals.nextElement();
for (int i = 0; i < remAddr.length; i++) { for (int i = 0; i < remAddr.length; i++) {
if (localAddr.equals(remAddr[i])) { if (localAddr.equals(remAddr[i])) {
return Boolean.TRUE; return true;
}
}
} }
} }
return Boolean.FALSE; }
}}); }
return result.booleanValue(); return false;
} }

View File

@ -27,14 +27,12 @@ package sun.awt.screencast;
import sun.awt.UNIXToolkit; import sun.awt.UNIXToolkit;
import sun.java2d.pipe.Region; import sun.java2d.pipe.Region;
import sun.security.action.GetPropertyAction;
import java.awt.GraphicsConfiguration; import java.awt.GraphicsConfiguration;
import java.awt.GraphicsEnvironment; import java.awt.GraphicsEnvironment;
import java.awt.Rectangle; import java.awt.Rectangle;
import java.awt.Toolkit; import java.awt.Toolkit;
import java.awt.geom.AffineTransform; import java.awt.geom.AffineTransform;
import java.security.AccessController;
import java.util.Arrays; import java.util.Arrays;
import java.util.List; import java.util.List;
import java.util.Set; import java.util.Set;
@ -48,7 +46,6 @@ import java.util.stream.IntStream;
* org.freedesktop.portal.ScreenCast API</a> * org.freedesktop.portal.ScreenCast API</a>
*/ */
@SuppressWarnings("removal")
public class ScreencastHelper { public class ScreencastHelper {
static final boolean SCREENCAST_DEBUG; static final boolean SCREENCAST_DEBUG;
@ -70,13 +67,7 @@ public class ScreencastHelper {
} }
static { static {
SCREENCAST_DEBUG = Boolean.parseBoolean( SCREENCAST_DEBUG = Boolean.getBoolean("awt.robot.screenshotDebug");
AccessController.doPrivileged(
new GetPropertyAction(
"awt.robot.screenshotDebug",
"false"
)
));
boolean loadFailed = false; boolean loadFailed = false;

View File

@ -37,8 +37,6 @@ import java.nio.file.WatchEvent;
import java.nio.file.WatchKey; import java.nio.file.WatchKey;
import java.nio.file.WatchService; import java.nio.file.WatchService;
import java.nio.file.attribute.PosixFilePermission; import java.nio.file.attribute.PosixFilePermission;
import java.security.AccessController;
import java.security.PrivilegedAction;
import java.util.Arrays; import java.util.Arrays;
import java.util.HashSet; import java.util.HashSet;
import java.util.LinkedHashSet; import java.util.LinkedHashSet;
@ -73,18 +71,8 @@ final class TokenStorage {
private static final Path PROPS_PATH; private static final Path PROPS_PATH;
private static final Path PROP_FILENAME; private static final Path PROP_FILENAME;
@SuppressWarnings("removal")
private static void doPrivilegedRunnable(Runnable runnable) {
AccessController.doPrivileged((PrivilegedAction<Void>) () -> {
runnable.run();
return null;
});
}
static { static {
@SuppressWarnings("removal") Path propsPath = setupPath();
Path propsPath = AccessController
.doPrivileged((PrivilegedAction<Path>) () -> setupPath());
PROPS_PATH = propsPath; PROPS_PATH = propsPath;
@ -226,9 +214,9 @@ final class TokenStorage {
} }
if (kind == ENTRY_CREATE) { if (kind == ENTRY_CREATE) {
doPrivilegedRunnable(() -> setFilePermission(PROPS_PATH)); setFilePermission(PROPS_PATH);
} else if (kind == ENTRY_MODIFY) { } else if (kind == ENTRY_MODIFY) {
doPrivilegedRunnable(() -> readTokens(PROPS_PATH)); readTokens(PROPS_PATH);
} else if (kind == ENTRY_DELETE) { } else if (kind == ENTRY_DELETE) {
synchronized (PROPS) { synchronized (PROPS) {
PROPS.clear(); PROPS.clear();
@ -244,25 +232,23 @@ final class TokenStorage {
private static WatchService watchService; private static WatchService watchService;
private static void setupWatch() { private static void setupWatch() {
doPrivilegedRunnable(() -> { try {
try { watchService =
watchService = FileSystems.getDefault().newWatchService();
FileSystems.getDefault().newWatchService();
PROPS_PATH PROPS_PATH
.getParent() .getParent()
.register(watchService, .register(watchService,
ENTRY_CREATE, ENTRY_CREATE,
ENTRY_DELETE, ENTRY_DELETE,
ENTRY_MODIFY); ENTRY_MODIFY);
} catch (Exception e) { } catch (Exception e) {
if (SCREENCAST_DEBUG) { if (SCREENCAST_DEBUG) {
System.err.printf("Token storage: failed to setup " + System.err.printf("Token storage: failed to setup " +
"file watch %s\n", e); "file watch %s\n", e);
}
} }
}); }
if (watchService != null) { if (watchService != null) {
new WatcherThread(watchService).start(); new WatcherThread(watchService).start();
@ -317,7 +303,7 @@ final class TokenStorage {
} }
if (changed) { if (changed) {
doPrivilegedRunnable(() -> store(PROPS_PATH, "save tokens")); store(PROPS_PATH, "save tokens");
} }
} }
} }
@ -372,7 +358,7 @@ final class TokenStorage {
.toList(); .toList();
} }
doPrivilegedRunnable(() -> removeMalformedRecords(malformed)); removeMalformedRecords(malformed);
// 1. Try to find exact matches // 1. Try to find exact matches
for (TokenItem tokenItem : allTokenItems) { for (TokenItem tokenItem : allTokenItems) {

View File

@ -363,11 +363,6 @@ public class FcFontConfiguration extends FontConfiguration {
private File getFcInfoFile() { private File getFcInfoFile() {
if (fcInfoFileName == null) { if (fcInfoFileName == null) {
// NB need security permissions to get true IP address, and
// we should have those as the whole initialisation is in a
// doPrivileged block. But in this case no exception is thrown,
// and it returns the loop back address, and so we end up with
// "localhost"
String hostname; String hostname;
try { try {
hostname = InetAddress.getLocalHost().getHostName(); hostname = InetAddress.getLocalHost().getHostName();

View File

@ -210,9 +210,7 @@ public abstract class X11SurfaceData extends XSurfaceData {
initIDs(XORComposite.class); initIDs(XORComposite.class);
@SuppressWarnings("removal") String xtextpipe = System.getProperty("sun.java2d.xtextpipe");
String xtextpipe = java.security.AccessController.doPrivileged
(new sun.security.action.GetPropertyAction("sun.java2d.xtextpipe"));
if (xtextpipe == null || "true".startsWith(xtextpipe)) { if (xtextpipe == null || "true".startsWith(xtextpipe)) {
if ("true".equals(xtextpipe)) { if ("true".equals(xtextpipe)) {
// Only verbose if they use the full string "true" // Only verbose if they use the full string "true"
@ -248,9 +246,7 @@ public abstract class X11SurfaceData extends XSurfaceData {
if (GraphicsEnvironment.isHeadless()) { if (GraphicsEnvironment.isHeadless()) {
accelerationEnabled = Boolean.FALSE; accelerationEnabled = Boolean.FALSE;
} else { } else {
@SuppressWarnings("removal") String prop = System.getProperty("sun.java2d.pmoffscreen");
String prop = java.security.AccessController.doPrivileged(
new sun.security.action.GetPropertyAction("sun.java2d.pmoffscreen"));
if (prop != null) { if (prop != null) {
// true iff prop==true, false otherwise // true iff prop==true, false otherwise
accelerationEnabled = Boolean.valueOf(prop); accelerationEnabled = Boolean.valueOf(prop);

View File

@ -30,8 +30,6 @@ import java.awt.Composite;
import java.awt.Paint; import java.awt.Paint;
import java.awt.geom.AffineTransform; import java.awt.geom.AffineTransform;
import java.awt.geom.NoninvertibleTransformException; import java.awt.geom.NoninvertibleTransformException;
import java.security.AccessController;
import java.security.PrivilegedAction;
import sun.awt.image.PixelConverter; import sun.awt.image.PixelConverter;
import sun.font.XRTextRenderer; import sun.font.XRTextRenderer;
@ -93,13 +91,7 @@ public class XRCompositeManager {
private XRCompositeManager(XRSurfaceData surface) { private XRCompositeManager(XRSurfaceData surface) {
con = new XRBackendNative(); con = new XRBackendNative();
@SuppressWarnings("removal") String gradProp = System.getProperty("sun.java2d.xrgradcache");
String gradProp =
AccessController.doPrivileged(new PrivilegedAction<String>() {
public String run() {
return System.getProperty("sun.java2d.xrgradcache");
}
});
enableGradCache = gradProp == null || enableGradCache = gradProp == null ||
!(gradProp.equalsIgnoreCase("false") || !(gradProp.equalsIgnoreCase("false") ||

View File

@ -90,16 +90,10 @@ public class CUPSPrinter {
initStatic(); initStatic();
} }
@SuppressWarnings({"removal", "restricted"}) @SuppressWarnings("restricted")
private static void initStatic() { private static void initStatic() {
// load awt library to access native code // load awt library to access native code
java.security.AccessController.doPrivileged( System.loadLibrary("awt");
new java.security.PrivilegedAction<Void>() {
public Void run() {
System.loadLibrary("awt");
return null;
}
});
libFound = initIDs(); libFound = initIDs();
if (libFound) { if (libFound) {
cupsServer = getCupsServer(); cupsServer = getCupsServer();
@ -308,18 +302,12 @@ public class CUPSPrinter {
IPPPrintService.getIPPConnection(url); IPPPrintService.getIPPConnection(url);
if (urlConnection != null) { if (urlConnection != null) {
@SuppressWarnings("removal") OutputStream os = null;
OutputStream os = java.security.AccessController. try {
doPrivileged(new java.security.PrivilegedAction<OutputStream>() { os = urlConnection.getOutputStream();
public OutputStream run() { } catch (Exception e) {
try { IPPPrintService.debug_println(debugPrefix+e);
return urlConnection.getOutputStream(); }
} catch (Exception e) {
IPPPrintService.debug_println(debugPrefix+e);
}
return null;
}
});
if (os == null) { if (os == null) {
return null; return null;
@ -424,17 +412,11 @@ public class CUPSPrinter {
IPPPrintService.getIPPConnection(url); IPPPrintService.getIPPConnection(url);
if (urlConnection != null) { if (urlConnection != null) {
@SuppressWarnings("removal") OutputStream os = null;
OutputStream os = java.security.AccessController. try {
doPrivileged(new java.security.PrivilegedAction<OutputStream>() { os = urlConnection.getOutputStream();
public OutputStream run() { } catch (Exception e) {
try { }
return urlConnection.getOutputStream();
} catch (Exception e) {
}
return null;
}
});
if (os == null) { if (os == null) {
return null; return null;
@ -507,12 +489,9 @@ public class CUPSPrinter {
return domainSocketPathname; return domainSocketPathname;
} }
@SuppressWarnings("removal")
private static boolean isSandboxedApp() { private static boolean isSandboxedApp() {
if (PrintServiceLookupProvider.isMac()) { if (PrintServiceLookupProvider.isMac()) {
return java.security.AccessController return (System.getenv("APP_SANDBOX_CONTAINER_ID") != null);
.doPrivileged((java.security.PrivilegedAction<Boolean>) () ->
System.getenv("APP_SANDBOX_CONTAINER_ID") != null);
} }
return false; return false;
} }

View File

@ -119,9 +119,7 @@ public class IPPPrintService implements PrintService, SunPrinterJobService {
private static final String FORCE_PIPE_PROP = "sun.print.ippdebug"; private static final String FORCE_PIPE_PROP = "sun.print.ippdebug";
static { static {
@SuppressWarnings("removal") String debugStr = System.getProperty(FORCE_PIPE_PROP);
String debugStr = java.security.AccessController.doPrivileged(
new sun.security.action.GetPropertyAction(FORCE_PIPE_PROP));
debugPrint = "true".equalsIgnoreCase(debugStr); debugPrint = "true".equalsIgnoreCase(debugStr);
} }
@ -1874,18 +1872,12 @@ public class IPPPrintService implements PrintService, SunPrinterJobService {
AttributeClass.TAG_URI, AttributeClass.TAG_URI,
""+myURI)}; ""+myURI)};
@SuppressWarnings("removal")
OutputStream os = java.security.AccessController.
doPrivileged(new java.security.PrivilegedAction<OutputStream>() {
public OutputStream run() {
try {
return urlConnection.getOutputStream();
} catch (Exception e) {
}
return null;
}
});
OutputStream os = null;
try {
os = urlConnection.getOutputStream();
} catch (Exception e) {
}
if (os == null) { if (os == null) {
return; return;
} }

View File

@ -28,12 +28,8 @@ package sun.print;
import java.io.BufferedReader; import java.io.BufferedReader;
import java.io.IOException; import java.io.IOException;
import java.net.MalformedURLException; import java.net.MalformedURLException;
import java.security.PrivilegedAction;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Vector; import java.util.Vector;
import java.security.AccessController;
import java.security.PrivilegedActionException;
import java.security.PrivilegedExceptionAction;
import javax.print.DocFlavor; import javax.print.DocFlavor;
import javax.print.MultiDocPrintService; import javax.print.MultiDocPrintService;
import javax.print.PrintService; import javax.print.PrintService;
@ -95,9 +91,7 @@ public class PrintServiceLookupProvider extends PrintServiceLookup
* can be used to force the printing code to poll or not poll * can be used to force the printing code to poll or not poll
* for PrintServices. * for PrintServices.
*/ */
@SuppressWarnings("removal") String pollStr = System.getProperty("sun.java2d.print.polling");
String pollStr = java.security.AccessController.doPrivileged(
new sun.security.action.GetPropertyAction("sun.java2d.print.polling"));
if (pollStr != null) { if (pollStr != null) {
if (pollStr.equalsIgnoreCase("true")) { if (pollStr.equalsIgnoreCase("true")) {
@ -111,10 +105,7 @@ public class PrintServiceLookupProvider extends PrintServiceLookup
* can be used to specify minimum refresh time (in seconds) * can be used to specify minimum refresh time (in seconds)
* for polling PrintServices. The default is 120. * for polling PrintServices. The default is 120.
*/ */
@SuppressWarnings("removal") String refreshTimeStr = System.getProperty("sun.java2d.print.minRefreshTime");
String refreshTimeStr = java.security.AccessController.doPrivileged(
new sun.security.action.GetPropertyAction(
"sun.java2d.print.minRefreshTime"));
if (refreshTimeStr != null) { if (refreshTimeStr != null) {
try { try {
@ -132,9 +123,7 @@ public class PrintServiceLookupProvider extends PrintServiceLookup
* take lots of time if thousands of printers are attached to a server. * take lots of time if thousands of printers are attached to a server.
*/ */
if (isAIX()) { if (isAIX()) {
@SuppressWarnings("removal") String aixPrinterEnumerator = System.getProperty("sun.java2d.print.aix.lpstat");
String aixPrinterEnumerator = java.security.AccessController.doPrivileged(
new sun.security.action.GetPropertyAction("sun.java2d.print.aix.lpstat"));
if (aixPrinterEnumerator != null) { if (aixPrinterEnumerator != null) {
if (aixPrinterEnumerator.equalsIgnoreCase("lpstat")) { if (aixPrinterEnumerator.equalsIgnoreCase("lpstat")) {
@ -202,18 +191,15 @@ public class PrintServiceLookupProvider extends PrintServiceLookup
return BSD_LPD; return BSD_LPD;
} }
@SuppressWarnings("removal")
public PrintServiceLookupProvider() { public PrintServiceLookupProvider() {
// start the printer listener thread // start the printer listener thread
if (pollServices) { if (pollServices) {
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();
IPPPrintService.debug_println(debugPrefix+"polling turned on"); IPPPrintService.debug_println(debugPrefix+"polling turned on");
} }
} }
@ -871,7 +857,6 @@ public class PrintServiceLookupProvider extends PrintServiceLookup
return printerNames.toArray(new String[printerNames.size()]); return printerNames.toArray(new String[printerNames.size()]);
} }
@SuppressWarnings("removal")
static String[] execCmd(final String command) { static String[] execCmd(final String command) {
ArrayList<String> results = null; ArrayList<String> results = null;
try { try {
@ -886,51 +871,46 @@ public class PrintServiceLookupProvider extends PrintServiceLookup
cmd[2] = "LC_ALL=C " + command; cmd[2] = "LC_ALL=C " + command;
} }
results = AccessController.doPrivileged( Process proc;
new PrivilegedExceptionAction<ArrayList<String>>() { BufferedReader bufferedReader = null;
public ArrayList<String> run() throws IOException { File f = Files.createTempFile("prn", "xc")
.toFile();
cmd[2] = cmd[2] + ">" + f.getAbsolutePath();
Process proc; proc = Runtime.getRuntime().exec(cmd);
BufferedReader bufferedReader = null; try {
File f = Files.createTempFile("prn","xc").toFile(); boolean done = false; // in case of interrupt.
cmd[2] = cmd[2]+">"+f.getAbsolutePath(); while (!done) {
try {
proc = Runtime.getRuntime().exec(cmd); proc.waitFor();
try { done = true;
boolean done = false; // in case of interrupt. } catch (InterruptedException ignored) {
while (!done) {
try {
proc.waitFor();
done = true;
} catch (InterruptedException e) {
}
}
if (proc.exitValue() == 0) {
FileReader reader = new FileReader(f);
bufferedReader = new BufferedReader(reader);
String line;
ArrayList<String> results = new ArrayList<>();
while ((line = bufferedReader.readLine())
!= null) {
results.add(line);
}
return results;
}
} finally {
f.delete();
// promptly close all streams.
if (bufferedReader != null) {
bufferedReader.close();
}
proc.getInputStream().close();
proc.getErrorStream().close();
proc.getOutputStream().close();
}
return null;
} }
}); }
} catch (PrivilegedActionException e) {
if (proc.exitValue() == 0) {
FileReader reader = new FileReader(f);
bufferedReader = new BufferedReader(reader);
String line;
while ((line = bufferedReader.readLine())
!= null) {
results.add(line);
}
}
} finally {
f.delete();
// promptly close all streams.
if (bufferedReader != null) {
bufferedReader.close();
}
proc.getInputStream()
.close();
proc.getErrorStream()
.close();
proc.getOutputStream()
.close();
}
} catch (IOException ignored) {
} }
if (results == null) { if (results == null) {
return new String[0]; return new String[0];

View File

@ -86,7 +86,6 @@ import java.awt.print.Printable;
import java.awt.print.PrinterException; import java.awt.print.PrinterException;
public class UnixPrintJob implements CancelablePrintJob { public class UnixPrintJob implements CancelablePrintJob {
private static String debugPrefix = "UnixPrintJob>> "; private static String debugPrefix = "UnixPrintJob>> ";
@ -525,8 +524,7 @@ public class UnixPrintJob implements CancelablePrintJob {
// now spool the print data. // now spool the print data.
PrinterOpener po = new PrinterOpener(); PrinterOpener po = new PrinterOpener();
@SuppressWarnings("removal") po.run();
var dummy = java.security.AccessController.doPrivileged(po);
if (po.pex != null) { if (po.pex != null) {
throw po.pex; throw po.pex;
} }
@ -599,8 +597,7 @@ public class UnixPrintJob implements CancelablePrintJob {
if (mDestType == UnixPrintJob.DESTPRINTER) { if (mDestType == UnixPrintJob.DESTPRINTER) {
PrinterSpooler spooler = new PrinterSpooler(); PrinterSpooler spooler = new PrinterSpooler();
@SuppressWarnings("removal") spooler.run();
var dummy2 = java.security.AccessController.doPrivileged(spooler);
if (spooler.pex != null) { if (spooler.pex != null) {
throw spooler.pex; throw spooler.pex;
} }
@ -911,9 +908,7 @@ public class UnixPrintJob implements CancelablePrintJob {
private String mDestination, mOptions=""; private String mDestination, mOptions="";
private boolean mNoJobSheet = false; private boolean mNoJobSheet = false;
// Inner class to run "privileged" to open the printer output stream. private class PrinterOpener {
private class PrinterOpener implements java.security.PrivilegedAction<OutputStream> {
PrintException pex; PrintException pex;
OutputStream result; OutputStream result;
@ -941,9 +936,7 @@ public class UnixPrintJob implements CancelablePrintJob {
} }
} }
// Inner class to run "privileged" to invoke the system print command private class PrinterSpooler {
private class PrinterSpooler implements java.security.PrivilegedAction<Object> {
PrintException pex; PrintException pex;
private void handleProcessFailure(final Process failedProcess, private void handleProcessFailure(final Process failedProcess,

View File

@ -145,9 +145,7 @@ public class UnixPrintService implements PrintService, AttributeUpdater,
"| grep -E '^[ 0-9a-zA-Z_-]*@' | awk '{print $4}'" "| grep -E '^[ 0-9a-zA-Z_-]*@' | awk '{print $4}'"
}; };
@SuppressWarnings("removal") private static String encoding = System.getProperty("file.encoding");
private static String encoding = java.security.AccessController.doPrivileged(
new sun.security.action.GetPropertyAction("file.encoding"));
/* let's try to support a few of these */ /* let's try to support a few of these */
private static final Class<?>[] serviceAttrCats = { private static final Class<?>[] serviceAttrCats = {