Skip to content

8344060: Remove doPrivileged calls from shared implementation code in the java.desktop module : part 1 #22133

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 6 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
47 changes: 13 additions & 34 deletions src/java.desktop/share/classes/sun/awt/SunToolkit.java
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,6 @@
import java.io.InputStream;
import java.lang.reflect.InvocationTargetException;
import java.net.URL;
import java.security.AccessController;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Locale;
Expand All @@ -100,8 +99,6 @@
import sun.awt.image.URLImageSource;
import sun.font.FontDesignMetrics;
import sun.net.util.URLUtil;
import sun.security.action.GetBooleanAction;
import sun.security.action.GetPropertyAction;
import sun.util.logging.PlatformLogger;

import static java.awt.RenderingHints.KEY_TEXT_ANTIALIASING;
Expand All @@ -122,14 +119,12 @@ public abstract class SunToolkit extends Toolkit
initStatic();
}

@SuppressWarnings("removal")
private static void initStatic() {
if (AccessController.doPrivileged(new GetBooleanAction("sun.awt.nativedebug"))) {
if (Boolean.getBoolean("sun.awt.nativedebug")) {
DebugSettings.init();
}
touchKeyboardAutoShowIsEnabled = Boolean.parseBoolean(
GetPropertyAction.privilegedGetProperty(
"awt.touchKeyboardAutoShowIsEnabled", "true"));
System.getProperty("awt.touchKeyboardAutoShowIsEnabled", "true"));
}

/**
Expand Down Expand Up @@ -231,9 +226,8 @@ public abstract KeyboardFocusManagerPeer getKeyboardFocusManagerPeer()
* }
*/

@SuppressWarnings("removal")
private static final ReentrantLock AWT_LOCK = new ReentrantLock(
AccessController.doPrivileged(new GetBooleanAction("awt.lock.fair")));
Boolean.getBoolean("awt.lock.fair"));
private static final Condition AWT_LOCK_COND = AWT_LOCK.newCondition();

public static final void awtLock() {
Expand Down Expand Up @@ -672,18 +666,16 @@ private void disableBackgroundEraseImpl(Component component) {
* Returns the value of "sun.awt.noerasebackground" property. Default
* value is {@code false}.
*/
@SuppressWarnings("removal")
public static boolean getSunAwtNoerasebackground() {
return AccessController.doPrivileged(new GetBooleanAction("sun.awt.noerasebackground"));
return Boolean.getBoolean("sun.awt.noerasebackground");
}

/**
* Returns the value of "sun.awt.erasebackgroundonresize" property. Default
* value is {@code false}.
*/
@SuppressWarnings("removal")
public static boolean getSunAwtErasebackgroundonresize() {
return AccessController.doPrivileged(new GetBooleanAction("sun.awt.erasebackgroundonresize"));
return Boolean.getBoolean("sun.awt.erasebackgroundonresize");
}


Expand Down Expand Up @@ -1157,15 +1149,12 @@ public boolean enableInputMethodsForTextComponent() {
/**
* Returns the locale in which the runtime was started.
*/
@SuppressWarnings("removal")
public static Locale getStartupLocale() {
if (startupLocale == null) {
String language, region, country, variant;
language = AccessController.doPrivileged(
new GetPropertyAction("user.language", "en"));
language = System.getProperty("user.language", "en");
// for compatibility, check for old user.region property
region = AccessController.doPrivileged(
new GetPropertyAction("user.region"));
region = System.getProperty("user.region");
if (region != null) {
// region can be of form country, country_variant, or _variant
int i = region.indexOf('_');
Expand All @@ -1177,10 +1166,8 @@ public static Locale getStartupLocale() {
variant = "";
}
} else {
country = AccessController.doPrivileged(
new GetPropertyAction("user.country", ""));
variant = AccessController.doPrivileged(
new GetPropertyAction("user.variant", ""));
country = System.getProperty("user.country", "");
variant = System.getProperty("user.variant", "");
}
startupLocale = Locale.of(language, country, variant);
}
Expand All @@ -1201,9 +1188,7 @@ public Locale getDefaultKeyboardLocale() {
* @return {@code true}, if XEmbed is needed, {@code false} otherwise
*/
public static boolean needsXEmbed() {
@SuppressWarnings("removal")
String noxembed = AccessController.
doPrivileged(new GetPropertyAction("sun.awt.noxembed", "false"));
String noxembed = System.getProperty("sun.awt.noxembed", "false");
if ("true".equals(noxembed)) {
return false;
}
Expand Down Expand Up @@ -1235,9 +1220,8 @@ protected boolean needsXEmbedImpl() {
* developer. If true, Toolkit should return an
* XEmbed-server-enabled CanvasPeer instead of the ordinary CanvasPeer.
*/
@SuppressWarnings("removal")
protected final boolean isXEmbedServerRequested() {
return AccessController.doPrivileged(new GetBooleanAction("sun.awt.xembedserver"));
return Boolean.getBoolean("sun.awt.xembedserver");
}

/**
Expand Down Expand Up @@ -1756,16 +1740,13 @@ private static RenderingHints getDesktopAAHintsByName(String hintname) {
* to be inapplicable in that case. In that headless case although
* this method will return "true" the toolkit will return a null map.
*/
@SuppressWarnings("removal")
private static boolean useSystemAAFontSettings() {
if (!checkedSystemAAFontSettings) {
useSystemAAFontSettings = true; /* initially set this true */
String systemAAFonts = null;
Toolkit tk = Toolkit.getDefaultToolkit();
if (tk instanceof SunToolkit) {
systemAAFonts =
AccessController.doPrivileged(
new GetPropertyAction("awt.useSystemAAFontSettings"));
systemAAFonts = System.getProperty("awt.useSystemAAFontSettings");
}
if (systemAAFonts != null) {
useSystemAAFontSettings = Boolean.parseBoolean(systemAAFonts);
Expand Down Expand Up @@ -1859,11 +1840,9 @@ public static Window getContainingWindow(Component comp) {
* Returns the value of "sun.awt.disableMixing" property. Default
* value is {@code false}.
*/
@SuppressWarnings("removal")
public static synchronized boolean getSunAwtDisableMixing() {
if (sunAwtDisableMixing == null) {
sunAwtDisableMixing = AccessController.doPrivileged(
new GetBooleanAction("sun.awt.disableMixing"));
sunAwtDisableMixing = Boolean.getBoolean("sun.awt.disableMixing");
}
return sunAwtDisableMixing.booleanValue();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -159,18 +159,11 @@ protected int imageComplete(int status, boolean done) {
public abstract void produceImage() throws IOException,
ImageFormatException;

@SuppressWarnings("removal")
public void abort() {
aborted = true;
source.doneDecoding(this);
close();
java.security.AccessController.doPrivileged(
new java.security.PrivilegedAction<Object>() {
public Object run() {
feeder.interrupt();
return null;
}
});
feeder.interrupt();
}

public synchronized void close() {
Expand Down
30 changes: 11 additions & 19 deletions src/java.desktop/share/classes/sun/awt/image/ImageFetcher.java
Original file line number Diff line number Diff line change
Expand Up @@ -276,7 +276,6 @@ private static void stoppingAnimation(Thread me) {
/**
* Create and start ImageFetcher threads in the appropriate ThreadGroup.
*/
@SuppressWarnings("removal")
private static void createFetchers(final FetcherInfo info) {
// We need to instantiate a new ImageFetcher thread.
// First, figure out which ThreadGroup we'll put the
Expand Down Expand Up @@ -310,25 +309,18 @@ private static void createFetchers(final FetcherInfo info) {
}
final ThreadGroup fetcherGroup = fetcherThreadGroup;

java.security.AccessController.doPrivileged(
new java.security.PrivilegedAction<Object>() {
public Object run() {
for (int i = 0; i < info.fetchers.length; i++) {
if (info.fetchers[i] == null) {
ImageFetcher f = new ImageFetcher(fetcherGroup, i);
try {
f.start();
info.fetchers[i] = f;
info.numFetchers++;
break;
} catch (Error e) {
}
}
}
return null;
for (int i = 0; i < info.fetchers.length; i++) {
if (info.fetchers[i] == null) {
ImageFetcher f = new ImageFetcher(fetcherGroup, i);
try {
f.start();
info.fetchers[i] = f;
info.numFetchers++;
break;
} catch (Error e) {
}
});
return;
}
}
}

}
Expand Down
36 changes: 3 additions & 33 deletions src/java.desktop/share/classes/sun/awt/image/ImageWatched.java
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,6 @@
import java.awt.Image;
import java.awt.image.ImageObserver;

import java.security.AccessControlContext;
import java.security.AccessController;
import java.security.PrivilegedAction;

public abstract class ImageWatched {
public static Link endlink = new Link();

Expand Down Expand Up @@ -89,28 +85,16 @@ public boolean newInfo(Image img, int info,
}
}

static class AccWeakReference<T> extends WeakReference<T> {

@SuppressWarnings("removal")
private final AccessControlContext acc;

@SuppressWarnings("removal")
AccWeakReference(T ref) {
super(ref);
acc = AccessController.getContext();
}
}

/*
* Standard Link implementation to manage a Weak Reference
* to an ImageObserver.
*/
public static class WeakLink extends Link {
private final AccWeakReference<ImageObserver> myref;
private final WeakReference<ImageObserver> myref;
private Link next;

public WeakLink(ImageObserver obs, Link next) {
myref = new AccWeakReference<ImageObserver>(obs);
myref = new WeakReference<ImageObserver>(obs);
this.next = next;
}

Expand All @@ -136,20 +120,6 @@ public Link removeWatcher(ImageObserver iw) {
return this;
}

@SuppressWarnings("removal")
private static boolean update(ImageObserver iw, AccessControlContext acc,
Image img, int info,
int x, int y, int w, int h) {

if (acc != null || System.getSecurityManager() != null) {
return AccessController.doPrivileged(
(PrivilegedAction<Boolean>) () -> {
return iw.imageUpdate(img, info, x, y, w, h);
}, acc);
}
return false;
}

public boolean newInfo(Image img, int info,
int x, int y, int w, int h)
{
Expand All @@ -159,7 +129,7 @@ public boolean newInfo(Image img, int info,
if (myiw == null) {
// My referent is null so we must prune in a second pass.
ret = true;
} else if (update(myiw, myref.acc, img, info, x, y, w, h) == false) {
} else if (myiw.imageUpdate(img, info, x, y, w, h) == false) {
// My referent has lost interest so clear it and ask
// for a pruning pass to remove it later.
myref.clear();
Expand Down
24 changes: 8 additions & 16 deletions src/java.desktop/share/classes/sun/awt/image/ImagingLib.java
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,6 @@
import java.awt.image.RasterOp;
import java.awt.image.Raster;
import java.awt.image.WritableRaster;
import java.security.AccessController;
import java.security.PrivilegedAction;

/**
* This class provides a hook to access platform-specific
Expand All @@ -51,7 +49,7 @@
* (in which case our java code will be executed) or may throw
* an exception.
*/
@SuppressWarnings({"removal", "restricted"})
@SuppressWarnings("restricted")
public class ImagingLib {

static boolean useLib = true;
Expand Down Expand Up @@ -90,20 +88,14 @@ public static native int lookupByteRaster(Raster src, Raster dst,

static {

PrivilegedAction<Boolean> doMlibInitialization =
new PrivilegedAction<Boolean>() {
public Boolean run() {
try {
System.loadLibrary("mlib_image");
} catch (UnsatisfiedLinkError e) {
return Boolean.FALSE;
}
boolean success = init();
return Boolean.valueOf(success);
}
};
boolean success = false;
try {
System.loadLibrary("mlib_image");
success = init();
} catch (UnsatisfiedLinkError e) {
}

useLib = AccessController.doPrivileged(doMlibInitialization);
useLib = success;

//
// Cache the class references of the operations we know about
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@
*
* @author Jim Graham
*/
@SuppressWarnings({"removal", "restricted"})
@SuppressWarnings("restricted")
public class JPEGImageDecoder extends ImageDecoder {
private static ColorModel RGBcolormodel;
private static ColorModel ARGBcolormodel;
Expand All @@ -54,13 +54,7 @@ public class JPEGImageDecoder extends ImageDecoder {
private ColorModel colormodel;

static {
java.security.AccessController.doPrivileged(
new java.security.PrivilegedAction<Void>() {
public Void run() {
System.loadLibrary("javajpeg");
return null;
}
});
System.loadLibrary("javajpeg");
initIDs(InputStreamClass);
RGBcolormodel = new DirectColorModel(24, 0xff0000, 0xff00, 0xff);
ARGBcolormodel = ColorModel.getRGBdefault();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,14 +52,8 @@ class NativeLibLoader {
* For now, we know it's done by the implementation, and we assume
* that the name of the library is "awt". -br.
*/
@SuppressWarnings({"removal", "restricted"})
@SuppressWarnings("restricted")
static void loadLibraries() {
java.security.AccessController.doPrivileged(
new java.security.PrivilegedAction<Void>() {
public Void run() {
System.loadLibrary("awt");
return null;
}
});
System.loadLibrary("awt");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -35,11 +35,8 @@ public abstract class VSyncedBSManager {

private static VSyncedBSManager theInstance;

@SuppressWarnings("removal")
private static final boolean vSyncLimit =
Boolean.parseBoolean(java.security.AccessController.doPrivileged(
new sun.security.action.GetPropertyAction(
"sun.java2d.vsynclimit", "true")));
Boolean.parseBoolean(System.getProperty("sun.java2d.vsynclimit", "true"));

private static VSyncedBSManager getInstance(boolean create) {
if (theInstance == null && create) {
Expand Down
Loading