8344062: Remove doPrivileged calls from awt and beans classes in the java.desktop module

Reviewed-by: serb
This commit is contained in:
Phil Race 2024-11-15 19:02:29 +00:00
parent fc8fb34f3d
commit 1bb0d3baaa
25 changed files with 97 additions and 462 deletions

View File

@ -627,14 +627,10 @@ public abstract class Component implements ImageObserver, MenuContainer,
initIDs();
}
@SuppressWarnings("removal")
String s = java.security.AccessController.doPrivileged(
new GetPropertyAction("awt.image.incrementaldraw"));
String s = System.getProperty("awt.image.incrementaldraw");
isInc = (s == null || s.equals("true"));
@SuppressWarnings("removal")
String s2 = java.security.AccessController.doPrivileged(
new GetPropertyAction("awt.image.redrawrate"));
String s2 = System.getProperty("awt.image.redrawrate");
incRate = (s2 != null) ? Integer.parseInt(s2) : 100;
}
@ -1431,15 +1427,7 @@ public abstract class Component implements ImageObserver, MenuContainer,
throw new HeadlessException();
}
@SuppressWarnings("removal")
PointerInfo pi = java.security.AccessController.doPrivileged(
new java.security.PrivilegedAction<PointerInfo>() {
public PointerInfo run() {
return MouseInfo.getPointerInfo();
}
}
);
PointerInfo pi = MouseInfo.getPointerInfo();
synchronized (getTreeLock()) {
Component inTheSameWindow = findUnderMouseInWindow(pi);
if (!isSameOrAncestorOf(inTheSameWindow, true)) {
@ -6253,14 +6241,7 @@ public abstract class Component implements ImageObserver, MenuContainer,
}
// Need to check non-bootstraps.
@SuppressWarnings("removal")
Boolean enabled = java.security.AccessController.doPrivileged(
new java.security.PrivilegedAction<Boolean>() {
public Boolean run() {
return isCoalesceEventsOverriden(clazz);
}
}
);
Boolean enabled = isCoalesceEventsOverriden(clazz);
coalesceMap.put(clazz, enabled);
return enabled;
}

View File

@ -1576,10 +1576,8 @@ public class Container extends Component {
}
// Don't lazy-read because every app uses invalidate()
@SuppressWarnings("removal")
private static final boolean isJavaAwtSmartInvalidate
= AccessController.doPrivileged(
new GetBooleanAction("java.awt.smartInvalidate"));
private static final boolean isJavaAwtSmartInvalidate =
Boolean.getBoolean("java.awt.smartInvalidate");
/**
* Invalidates the parent of the container unless the container
@ -2632,14 +2630,7 @@ public class Container extends Component {
if (GraphicsEnvironment.isHeadless()) {
throw new HeadlessException();
}
@SuppressWarnings("removal")
PointerInfo pi = java.security.AccessController.doPrivileged(
new java.security.PrivilegedAction<PointerInfo>() {
public PointerInfo run() {
return MouseInfo.getPointerInfo();
}
}
);
PointerInfo pi = MouseInfo.getPointerInfo();
synchronized (getTreeLock()) {
Component inTheSameWindow = findUnderMouseInWindow(pi);
if (isSameOrAncestorOf(inTheSameWindow, allowChildren)) {
@ -4738,33 +4729,17 @@ class LightweightDispatcher implements java.io.Serializable, AWTEventListener {
* from other heavyweight containers will generate enter/exit
* events in this container
*/
@SuppressWarnings("removal")
private void startListeningForOtherDrags() {
//System.out.println("Adding AWTEventListener");
java.security.AccessController.doPrivileged(
new java.security.PrivilegedAction<Object>() {
public Object run() {
nativeContainer.getToolkit().addAWTEventListener(
LightweightDispatcher.this,
AWTEvent.MOUSE_EVENT_MASK |
AWTEvent.MOUSE_MOTION_EVENT_MASK);
return null;
}
}
);
nativeContainer.getToolkit().addAWTEventListener(
LightweightDispatcher.this,
AWTEvent.MOUSE_EVENT_MASK |
AWTEvent.MOUSE_MOTION_EVENT_MASK);
}
@SuppressWarnings("removal")
private void stopListeningForOtherDrags() {
//System.out.println("Removing AWTEventListener");
java.security.AccessController.doPrivileged(
new java.security.PrivilegedAction<Object>() {
public Object run() {
nativeContainer.getToolkit().removeAWTEventListener(LightweightDispatcher.this);
return null;
}
}
);
nativeContainer.getToolkit().removeAWTEventListener(LightweightDispatcher.this);
}
/*

View File

@ -29,8 +29,6 @@ import java.beans.ConstructorProperties;
import java.io.InputStream;
import java.io.Serial;
import java.security.AccessController;
import java.security.PrivilegedAction;
import java.security.PrivilegedExceptionAction;
import java.util.Hashtable;
import java.util.Properties;
import java.util.StringTokenizer;
@ -332,11 +330,7 @@ public class Cursor implements java.io.Serializable {
}
final Toolkit toolkit = Toolkit.getDefaultToolkit();
final String file = RESOURCE_PREFIX + fileName;
@SuppressWarnings("removal")
final InputStream in = AccessController.doPrivileged(
(PrivilegedAction<InputStream>) () -> {
return Cursor.class.getResourceAsStream(file);
});
final InputStream in = Cursor.class.getResourceAsStream(file);
try (in) {
Image image = toolkit.createImage(in.readAllBytes());
cursor = toolkit.createCustomCursor(image, hotPoint, localized);
@ -428,7 +422,6 @@ public class Cursor implements java.io.Serializable {
/*
* load the cursor.properties file
*/
@SuppressWarnings("removal")
private static void loadSystemCustomCursorProperties() throws AWTException {
synchronized (systemCustomCursors) {
if (systemCustomCursorProperties != null) {
@ -437,14 +430,8 @@ public class Cursor implements java.io.Serializable {
systemCustomCursorProperties = new Properties();
try {
AccessController.doPrivileged(
(PrivilegedExceptionAction<Object>) () -> {
try (InputStream is = Cursor.class
.getResourceAsStream(PROPERTIES_FILE)) {
systemCustomCursorProperties.load(is);
}
return null;
});
InputStream is = Cursor.class.getResourceAsStream(PROPERTIES_FILE);
systemCustomCursorProperties.load(is);
} catch (Exception e) {
systemCustomCursorProperties = null;
throw new AWTException("Exception: " + e.getClass() + " " +

View File

@ -32,8 +32,6 @@ import java.awt.peer.ComponentPeer;
import java.awt.peer.LightweightPeer;
import java.io.Serial;
import java.lang.ref.WeakReference;
import java.security.AccessController;
import java.security.PrivilegedAction;
import java.util.Iterator;
import java.util.LinkedList;
import java.util.ListIterator;
@ -86,21 +84,14 @@ public class DefaultKeyboardFocusManager extends KeyboardFocusManager {
initStatic();
}
@SuppressWarnings("removal")
private static void initStatic() {
AWTAccessor.setDefaultKeyboardFocusManagerAccessor(
new AWTAccessor.DefaultKeyboardFocusManagerAccessor() {
public void consumeNextKeyTyped(DefaultKeyboardFocusManager dkfm, KeyEvent e) {
dkfm.consumeNextKeyTyped(e);
}
}
});
AccessController.doPrivileged(new PrivilegedAction<Object>() {
public Object run() {
fxAppThreadIsDispatchThread =
"true".equals(System.getProperty("javafx.embed.singleThread"));
return null;
}
});
fxAppThreadIsDispatchThread = "true".equals(System.getProperty("javafx.embed.singleThread"));
}
/**

View File

@ -42,8 +42,6 @@ import java.io.FilePermission;
import java.io.IOException;
import java.net.URI;
import java.net.URISyntaxException;
import java.security.AccessController;
import java.security.PrivilegedAction;
import java.util.Objects;
import javax.swing.JMenuBar;
@ -936,11 +934,7 @@ public class Desktop {
sm.checkDelete(file.getPath());
}
checkActionSupport(Action.MOVE_TO_TRASH);
final File finalFile = file;
AccessController.doPrivileged((PrivilegedAction<?>) () -> {
checkFileValidation(finalFile);
return null;
});
checkFileValidation(file);
return peer.moveToTrash(file);
}
}

View File

@ -34,8 +34,6 @@ import java.io.IOException;
import java.io.ObjectInputStream;
import java.io.Serial;
import java.security.AccessControlException;
import java.security.AccessController;
import java.security.PrivilegedAction;
import java.util.Iterator;
import java.util.concurrent.atomic.AtomicLong;
@ -1052,9 +1050,7 @@ public class Dialog extends Window {
modalityPushed();
try {
@SuppressWarnings("removal")
final EventQueue eventQueue = AccessController.doPrivileged(
(PrivilegedAction<EventQueue>) Toolkit.getDefaultToolkit()::getSystemEventQueue);
EventQueue eventQueue = Toolkit.getDefaultToolkit().getSystemEventQueue();
secondaryLoop = eventQueue.createSecondaryLoop(() -> true, modalFilter, 0);
if (!secondaryLoop.enter()) {
secondaryLoop = null;

View File

@ -32,9 +32,6 @@ import java.awt.peer.ComponentPeer;
import java.lang.ref.WeakReference;
import java.lang.reflect.InvocationTargetException;
import java.security.AccessController;
import java.security.PrivilegedAction;
import java.util.EmptyStackException;
import sun.awt.*;
@ -45,11 +42,6 @@ import java.util.concurrent.locks.Condition;
import java.util.concurrent.locks.Lock;
import java.util.concurrent.atomic.AtomicInteger;
import java.security.AccessControlContext;
import jdk.internal.access.SharedSecrets;
import jdk.internal.access.JavaSecurityAccess;
/**
* {@code EventQueue} is a platform-independent class
* that queues events, both from the underlying peer classes
@ -229,13 +221,8 @@ public class EventQueue {
});
}
@SuppressWarnings("removal")
private static boolean fxAppThreadIsDispatchThread =
AccessController.doPrivileged(new PrivilegedAction<Boolean>() {
public Boolean run() {
return "true".equals(System.getProperty("javafx.embed.singleThread"));
}
});
"true".equals(System.getProperty("javafx.embed.singleThread"));
/**
* Initializes a new instance of {@code EventQueue}.
@ -668,9 +655,6 @@ public class EventQueue {
return null;
}
private static final JavaSecurityAccess javaSecurityAccess =
SharedSecrets.getJavaSecurityAccess();
/**
* Dispatches an event. The manner in which the event is
* dispatched depends upon the type of the event and the
@ -711,59 +695,25 @@ public class EventQueue {
*/
protected void dispatchEvent(final AWTEvent event) {
final Object src = event.getSource();
final PrivilegedAction<Void> action = new PrivilegedAction<Void>() {
public Void run() {
// In case fwDispatcher is installed and we're already on the
// dispatch thread (e.g. performing DefaultKeyboardFocusManager.sendMessage),
// dispatch the event straight away.
if (fwDispatcher == null || isDispatchThreadImpl()) {
dispatchEventImpl(event, src);
} else {
fwDispatcher.scheduleDispatch(new Runnable() {
@Override
public void run() {
if (dispatchThread.filterAndCheckEvent(event)) {
dispatchEventImpl(event, src);
}
}
});
}
return null;
}
};
@SuppressWarnings("removal")
final AccessControlContext stack = AccessController.getContext();
@SuppressWarnings("removal")
final AccessControlContext srcAcc = getAccessControlContextFrom(src);
@SuppressWarnings("removal")
final AccessControlContext eventAcc = event.getAccessControlContext();
if (srcAcc == null) {
javaSecurityAccess.doIntersectionPrivilege(action, stack, eventAcc);
// In case fwDispatcher is installed and we're already on the
// dispatch thread (e.g. performing DefaultKeyboardFocusManager.sendMessage),
// dispatch the event straight away.
if (fwDispatcher == null || isDispatchThreadImpl()) {
dispatchEventImpl(event, src);
} else {
javaSecurityAccess.doIntersectionPrivilege(
new PrivilegedAction<Void>() {
public Void run() {
javaSecurityAccess.doIntersectionPrivilege(action, eventAcc);
return null;
fwDispatcher.scheduleDispatch(new Runnable() {
@Override
public void run() {
if (dispatchThread.filterAndCheckEvent(event)) {
dispatchEventImpl(event, src);
}
}, stack, srcAcc);
}
});
}
}
@SuppressWarnings("removal")
private static AccessControlContext getAccessControlContextFrom(Object src) {
return src instanceof Component ?
((Component)src).getAccessControlContext() :
src instanceof MenuComponent ?
((MenuComponent)src).getAccessControlContext() :
src instanceof TrayIcon ?
((TrayIcon)src).getAccessControlContext() :
null;
}
/**
* Called from dispatchEvent() under a correct AccessControlContext
* Called from dispatchEvent()
*/
private void dispatchEventImpl(final AWTEvent event, final Object src) {
event.isPosted = true;
@ -1113,21 +1063,12 @@ public class EventQueue {
pushPopLock.lock();
try {
if (dispatchThread == null && !threadGroup.isDestroyed() && !appContext.isDisposed()) {
dispatchThread = AccessController.doPrivileged(
new PrivilegedAction<EventDispatchThread>() {
public EventDispatchThread run() {
EventDispatchThread t =
new EventDispatchThread(threadGroup,
name,
EventQueue.this);
t.setContextClassLoader(classLoader);
t.setPriority(Thread.NORM_PRIORITY + 1);
t.setDaemon(false);
AWTAutoShutdown.getInstance().notifyThreadBusy(t);
return t;
}
}
);
EventDispatchThread t = new EventDispatchThread(threadGroup, name, EventQueue.this);
t.setContextClassLoader(classLoader);
t.setPriority(Thread.NORM_PRIORITY + 1);
t.setDaemon(false);
AWTAutoShutdown.getInstance().notifyThreadBusy(t);
dispatchThread = t;
dispatchThread.start();
}
} finally {

View File

@ -44,8 +44,6 @@ import java.io.OutputStream;
import java.io.Serial;
import java.lang.ref.SoftReference;
import java.nio.file.Files;
import java.security.AccessController;
import java.security.PrivilegedExceptionAction;
import java.text.AttributedCharacterIterator.Attribute;
import java.text.CharacterIterator;
import java.util.EventListener;
@ -1095,7 +1093,6 @@ public class Font implements java.io.Serializable
}
}
@SuppressWarnings("removal")
private static Font[] createFont0(int fontFormat, InputStream fontStream,
boolean allFonts,
CreatedFontTracker tracker)
@ -1107,27 +1104,14 @@ public class Font implements java.io.Serializable
}
boolean copiedFontData = false;
try {
final File tFile = AccessController.doPrivileged(
new PrivilegedExceptionAction<File>() {
public File run() throws IOException {
return Files.createTempFile("+~JF", ".tmp").toFile();
}
}
);
final File tFile = Files.createTempFile("+~JF", ".tmp").toFile();
if (tracker != null) {
tracker.add(tFile);
}
int totalSize = 0;
try {
final OutputStream outStream =
AccessController.doPrivileged(
new PrivilegedExceptionAction<OutputStream>() {
public OutputStream run() throws IOException {
return new FileOutputStream(tFile);
}
}
);
final OutputStream outStream = new FileOutputStream(tFile);
if (tracker != null) {
tracker.set(tFile, outStream);
}
@ -1181,14 +1165,7 @@ public class Font implements java.io.Serializable
if (tracker != null) {
tracker.subBytes(totalSize);
}
AccessController.doPrivileged(
new PrivilegedExceptionAction<Void>() {
public Void run() {
tFile.delete();
return null;
}
}
);
tFile.delete();
}
}
} catch (Throwable t) {

View File

@ -26,8 +26,6 @@
package java.awt;
import java.awt.image.BufferedImage;
import java.security.AccessController;
import java.security.PrivilegedAction;
import java.util.Locale;
import sun.awt.PlatformGraphicsInfo;
@ -137,20 +135,16 @@ public abstract class GraphicsEnvironment {
* @return the value of the property "java.awt.headless"
* @since 1.4
*/
@SuppressWarnings("removal")
private static boolean getHeadlessProperty() {
if (headless == null) {
AccessController.doPrivileged((PrivilegedAction<Void>) () -> {
String nm = System.getProperty("java.awt.headless");
String nm = System.getProperty("java.awt.headless");
if (nm == null) {
headless = defaultHeadless =
PlatformGraphicsInfo.getDefaultHeadlessProperty();
} else {
headless = Boolean.valueOf(nm);
}
return null;
});
if (nm == null) {
headless = defaultHeadless =
PlatformGraphicsInfo.getDefaultHeadlessProperty();
} else {
headless = Boolean.valueOf(nm);
}
}
return headless;
}

View File

@ -40,9 +40,6 @@ import java.beans.VetoableChangeSupport;
import java.lang.ref.WeakReference;
import java.security.AccessController;
import java.security.PrivilegedAction;
import java.util.Collections;
import java.util.HashSet;
import java.util.Iterator;
@ -601,14 +598,8 @@ public abstract class KeyboardFocusManager
peer.clearGlobalFocusOwner(activeWindow);
}
@SuppressWarnings("removal")
void clearGlobalFocusOwnerPriv() {
AccessController.doPrivileged(new PrivilegedAction<Void>() {
public Void run() {
clearGlobalFocusOwner();
return null;
}
});
clearGlobalFocusOwner();
}
Component getNativeFocusOwner() {
@ -1194,14 +1185,8 @@ public abstract class KeyboardFocusManager
newFocusCycleRoot);
}
@SuppressWarnings("removal")
void setGlobalCurrentFocusCycleRootPriv(final Container newFocusCycleRoot) {
AccessController.doPrivileged(new PrivilegedAction<Void>() {
public Void run() {
setGlobalCurrentFocusCycleRoot(newFocusCycleRoot);
return null;
}
});
setGlobalCurrentFocusCycleRoot(newFocusCycleRoot);
}
/**

View File

@ -26,8 +26,6 @@
package java.awt;
import java.io.Serial;
import java.security.AccessController;
import java.security.PrivilegedAction;
import java.util.LinkedList;
import sun.awt.AWTAccessor;
@ -80,13 +78,7 @@ class SequencedEvent extends AWTEvent implements ActiveEvent {
return new SequencedEvent(event);
}
});
AccessController.doPrivileged(new PrivilegedAction<Object>() {
public Object run() {
fxAppThreadIsDispatchThread =
"true".equals(System.getProperty("javafx.embed.singleThread"));
return null;
}
});
fxAppThreadIsDispatchThread = "true".equals(System.getProperty("javafx.embed.singleThread"));
}
private static final class SequencedEventsFilter implements EventFilter {

View File

@ -129,13 +129,7 @@ public final class SplashScreen {
}
// SplashScreen class is now a singleton
if (!wasClosed && theInstance == null) {
java.security.AccessController.doPrivileged(
new java.security.PrivilegedAction<Void>() {
public Void run() {
System.loadLibrary("splashscreen");
return null;
}
});
System.loadLibrary("splashscreen");
long ptr = _getInstance();
if (ptr != 0 && _isVisible(ptr)) {
theInstance = new SplashScreen(ptr);

View File

@ -56,8 +56,6 @@ import java.beans.PropertyChangeSupport;
import java.io.File;
import java.io.FileInputStream;
import java.net.URL;
import java.security.AccessController;
import java.security.PrivilegedAction;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.EventListener;
@ -396,18 +394,12 @@ public abstract class Toolkit {
* properties are set up properly before any classes dependent upon them
* are initialized.
*/
@SuppressWarnings("removal")
private static void initAssistiveTechnologies() {
// Get accessibility properties
final String sep = File.separator;
final Properties properties = new Properties();
atNames = java.security.AccessController.doPrivileged(
new java.security.PrivilegedAction<String>() {
public String run() {
// Try loading the per-user accessibility properties file.
try {
File propsFile = new File(
@ -459,9 +451,7 @@ public abstract class Toolkit {
System.setProperty("javax.accessibility.assistive_technologies", classNames);
}
}
return classNames;
}
});
atNames = classNames;
}
/**
@ -512,7 +502,6 @@ public abstract class Toolkit {
* {@code null} it is ignored. All other errors are handled via an AWTError
* exception.
*/
@SuppressWarnings("removal")
private static void loadAssistiveTechnologies() {
// Load any assistive technologies
if (atNames != null && !atNames.isBlank()) {
@ -521,20 +510,17 @@ public abstract class Toolkit {
.map(String::trim)
.collect(Collectors.toSet());
final Map<String, AccessibilityProvider> providers = new HashMap<>();
AccessController.doPrivileged((PrivilegedAction<Void>) () -> {
try {
for (AccessibilityProvider p : ServiceLoader.load(AccessibilityProvider.class, cl)) {
String name = p.getName();
if (names.contains(name) && !providers.containsKey(name)) {
p.activate();
providers.put(name, p);
}
try {
for (AccessibilityProvider p : ServiceLoader.load(AccessibilityProvider.class, cl)) {
String name = p.getName();
if (names.contains(name) && !providers.containsKey(name)) {
p.activate();
providers.put(name, p);
}
} catch (java.util.ServiceConfigurationError | Exception e) {
newAWTError(e, "Could not load or activate service provider");
}
return null;
});
} catch (java.util.ServiceConfigurationError | Exception e) {
newAWTError(e, "Could not load or activate service provider");
}
names.stream()
.filter(n -> !providers.containsKey(n))
.forEach(Toolkit::fallbackToLoadClassForAT);
@ -1302,16 +1288,10 @@ public abstract class Toolkit {
* directly. -hung
*/
private static boolean loaded = false;
@SuppressWarnings({"removal", "restricted"})
@SuppressWarnings("restricted")
static void loadLibraries() {
if (!loaded) {
java.security.AccessController.doPrivileged(
new java.security.PrivilegedAction<Void>() {
public Void run() {
System.loadLibrary("awt");
return null;
}
});
System.loadLibrary("awt");
loaded = true;
}
}
@ -1320,7 +1300,6 @@ public abstract class Toolkit {
initStatic();
}
@SuppressWarnings("removal")
private static void initStatic() {
AWTAccessor.setToolkitAccessor(
new AWTAccessor.ToolkitAccessor() {
@ -1330,17 +1309,11 @@ public abstract class Toolkit {
}
});
java.security.AccessController.doPrivileged(
new java.security.PrivilegedAction<Void>() {
public Void run() {
try {
resources = ResourceBundle.getBundle("sun.awt.resources.awt");
} catch (MissingResourceException e) {
// No resource file; defaults will be used.
}
return null;
}
});
try {
resources = ResourceBundle.getBundle("sun.awt.resources.awt");
} catch (MissingResourceException e) {
// No resource file; defaults will be used.
}
// ensure that the proper libraries are loaded
loadLibraries();

View File

@ -29,9 +29,6 @@ import java.util.Timer;
import java.util.TimerTask;
import java.util.concurrent.atomic.AtomicBoolean;
import java.security.PrivilegedAction;
import java.security.AccessController;
import sun.awt.PeerEvent;
import sun.util.logging.PlatformLogger;
@ -230,13 +227,7 @@ class WaitDispatchSupport implements SecondaryLoop {
// The event will be handled after the new event pump
// starts. Thus, the enter() method will not hang.
//
// Event pump should be privileged. See 6300270.
AccessController.doPrivileged(new PrivilegedAction<Void>() {
public Void run() {
run.run();
return null;
}
});
run.run();
} else {
if (log.isLoggable(PlatformLogger.Level.FINEST)) {
log.finest("On non-dispatch thread: " + currentThread);

View File

@ -48,7 +48,6 @@ import java.io.Serial;
import java.io.Serializable;
import java.lang.ref.WeakReference;
import java.lang.reflect.InvocationTargetException;
import java.security.AccessController;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.EventListener;
@ -414,13 +413,9 @@ public class Window extends Container implements Accessible {
initIDs();
}
@SuppressWarnings("removal")
String s = java.security.AccessController.doPrivileged(
new GetPropertyAction("java.awt.syncLWRequests"));
String s = System.getProperty("java.awt.syncLWRequests");
systemSyncLWRequests = "true".equals(s);
@SuppressWarnings("removal")
String s2 = java.security.AccessController.doPrivileged(
new GetPropertyAction("java.awt.Window.locationByPlatform"));
String s2 = System.getProperty("java.awt.Window.locationByPlatform");
locationByPlatformProp = "true".equals(s2);
}
@ -505,7 +500,6 @@ public class Window extends Container implements Accessible {
weakThis = new WeakReference<Window>(this);
addToWindowList();
setWarningString();
this.cursor = Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR);
this.visible = false;
@ -1376,24 +1370,6 @@ public class Window extends Container implements Accessible {
return warningString;
}
@SuppressWarnings("removal")
private void setWarningString() {
warningString = null;
SecurityManager sm = System.getSecurityManager();
if (sm != null) {
try {
sm.checkPermission(AWTPermissions.TOPLEVEL_WINDOW_PERMISSION);
} catch (SecurityException se) {
// make sure the privileged action is only
// for getting the property! We don't want the
// above checkPermission call to always succeed!
warningString = AccessController.doPrivileged(
new GetPropertyAction("awt.appletWarning",
"Java Applet Window"));
}
}
}
/**
* Gets the {@code Locale} object that is associated
* with this window, if the locale has been set.
@ -2978,7 +2954,6 @@ public class Window extends Container implements Accessible {
// user's code.
//
private void initDeserializedWindow() {
setWarningString();
inputContextLock = new Object();
// Deserialized Windows are not yet visible.

View File

@ -48,8 +48,6 @@ import java.io.ObjectStreamException;
import java.io.OutputStream;
import java.io.Serial;
import java.io.Serializable;
import java.security.AccessController;
import java.security.PrivilegedAction;
import java.util.Objects;
import java.util.StringTokenizer;
@ -1341,13 +1339,8 @@ public sealed class ICC_Profile implements Serializable
* fileName. If there is no built-in profile with such name, then the method
* returns {@code null}.
*/
@SuppressWarnings("removal")
private static InputStream getStandardProfileInputStream(String fileName) {
return AccessController.doPrivileged(
(PrivilegedAction<InputStream>) () -> {
return PCMM.class.getResourceAsStream("profiles/" + fileName);
}, null, new FilePermission("<<ALL FILES>>", "read"),
new RuntimePermission("accessSystemModules"));
return PCMM.class.getResourceAsStream("profiles/" + fileName);
}
/**

View File

@ -40,13 +40,11 @@ import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.io.Serial;
import java.io.Serializable;
import java.security.AccessController;
import java.util.EventListener;
import sun.awt.AWTAccessor;
import sun.awt.AWTAccessor.DragSourceContextAccessor;
import sun.awt.dnd.SunDragSourceContextPeer;
import sun.security.action.GetIntegerAction;
/**
* The {@code DragSource} is the entity responsible
@ -908,8 +906,7 @@ public class DragSource implements Serializable {
*/
public static int getDragThreshold() {
@SuppressWarnings("removal")
int ts = AccessController.doPrivileged(
new GetIntegerAction("awt.dnd.drag.threshold", 0)).intValue();
int ts = Integer.getInteger("awt.dnd.drag.threshold", 0);
if (ts > 0) {
return ts;
} else {

View File

@ -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");
}
}

View File

@ -31,8 +31,6 @@ import java.awt.Point;
import java.awt.Rectangle;
import java.awt.Transparency;
import java.awt.color.ColorSpace;
import java.security.AccessController;
import java.security.PrivilegedAction;
import java.util.Hashtable;
import java.util.Set;
import java.util.Vector;
@ -800,26 +798,16 @@ public class BufferedImage extends java.awt.Image
} // else if ((raster instanceof ByteComponentRaster) &&
}
@SuppressWarnings("removal")
private static boolean isStandard(ColorModel cm, WritableRaster wr) {
final Class<? extends ColorModel> cmClass = cm.getClass();
final Class<? extends WritableRaster> wrClass = wr.getClass();
final Class<? extends SampleModel> smClass = wr.getSampleModel().getClass();
final PrivilegedAction<Boolean> checkClassLoadersAction =
new PrivilegedAction<Boolean>()
{
final ClassLoader std = System.class.getClassLoader();
@Override
public Boolean run() {
final ClassLoader std = System.class.getClassLoader();
return (cmClass.getClassLoader() == std) &&
(smClass.getClassLoader() == std) &&
(wrClass.getClassLoader() == std);
}
};
return AccessController.doPrivileged(checkClassLoadersAction);
return (cmClass.getClassLoader() == std) &&
(smClass.getClassLoader() == std) &&
(wrClass.getClassLoader() == std);
}
/**

View File

@ -202,16 +202,10 @@ public abstract class ColorModel implements Transparency{
* that the name of the library is "awt". -br.
*/
private static boolean loaded = false;
@SuppressWarnings({"removal", "restricted"})
@SuppressWarnings("restricted")
static void loadLibraries() {
if (!loaded) {
java.security.AccessController.doPrivileged(
new java.security.PrivilegedAction<Void>() {
public Void run() {
System.loadLibrary("awt");
return null;
}
});
System.loadLibrary("awt");
loaded = true;
}
}

View File

@ -28,9 +28,6 @@ import java.lang.reflect.InvocationHandler;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Proxy;
import java.lang.reflect.Method;
import java.security.AccessControlContext;
import java.security.AccessController;
import java.security.PrivilegedAction;
import sun.reflect.misc.MethodUtil;
import sun.reflect.misc.ReflectUtil;
@ -281,8 +278,6 @@ public class EventHandler implements InvocationHandler {
private String action;
private final String eventPropertyName;
private final String listenerMethodName;
@SuppressWarnings("removal")
private final AccessControlContext acc = AccessController.getContext();
/**
* Creates a new {@code EventHandler} object;
@ -421,20 +416,7 @@ public class EventHandler implements InvocationHandler {
*
* @see EventHandler
*/
@SuppressWarnings("removal")
public Object invoke(final Object proxy, final Method method, final Object[] arguments) {
AccessControlContext acc = this.acc;
if ((acc == null) && (System.getSecurityManager() != null)) {
throw new SecurityException("AccessControlContext is not set");
}
return AccessController.doPrivileged(new PrivilegedAction<Object>() {
public Object run() {
return invokeInternal(proxy, method, arguments);
}
}, acc);
}
private Object invokeInternal(Object proxy, Method method, Object[] arguments) {
String methodName = method.getName();
if (method.getDeclaringClass() == Object.class) {
// Handle the Object public methods.
@ -689,7 +671,7 @@ public class EventHandler implements InvocationHandler {
* @see EventHandler
* @see Proxy#newProxyInstance
*/
@SuppressWarnings("removal")
@SuppressWarnings("unchecked")
public static <T> T create(Class<T> listenerInterface,
Object target, String action,
String eventPropertyName,
@ -705,12 +687,7 @@ public class EventHandler implements InvocationHandler {
}
final ClassLoader loader = getClassLoader(listenerInterface);
final Class<?>[] interfaces = {listenerInterface};
return AccessController.doPrivileged(new PrivilegedAction<T>() {
@SuppressWarnings("unchecked")
public T run() {
return (T) Proxy.newProxyInstance(loader, interfaces, handler);
}
});
return (T) Proxy.newProxyInstance(loader, interfaces, handler);
}
private static ClassLoader getClassLoader(Class<?> type) {

View File

@ -41,9 +41,6 @@ import java.lang.reflect.Method;
import java.lang.reflect.Modifier;
import java.lang.reflect.InvocationTargetException;
import java.security.AccessController;
import java.security.PrivilegedAction;
import java.util.*;
import javax.swing.Box;
@ -1319,28 +1316,22 @@ static final class sun_swing_PrintColorUIResource_PersistenceDelegate extends Pe
}
}
@SuppressWarnings("removal")
static Object getPrivateFieldValue(Object instance, String name) {
Field field = fields.get(name);
if (field == null) {
int index = name.lastIndexOf('.');
final String className = name.substring(0, index);
final String fieldName = name.substring(1 + index);
field = AccessController.doPrivileged(new PrivilegedAction<Field>() {
public Field run() {
try {
Field field = Class.forName(className).getDeclaredField(fieldName);
field.setAccessible(true);
return field;
}
catch (ClassNotFoundException exception) {
throw new IllegalStateException("Could not find class", exception);
}
catch (NoSuchFieldException exception) {
throw new IllegalStateException("Could not find field", exception);
}
}
});
try {
field = Class.forName(className).getDeclaredField(fieldName);
field.setAccessible(true);
}
catch (ClassNotFoundException exception) {
throw new IllegalStateException("Could not find class", exception);
}
catch (NoSuchFieldException exception) {
throw new IllegalStateException("Could not find field", exception);
}
fields.put(name, field);
}
try {

View File

@ -29,8 +29,6 @@ import java.awt.Image;
import java.awt.Toolkit;
import java.awt.image.ImageProducer;
import java.net.URL;
import java.security.AccessController;
import java.security.PrivilegedAction;
/**
* This is a support class to make it easier for people to provide
@ -154,10 +152,8 @@ public class SimpleBeanInfo implements BeanInfo {
* @return an image object. May be null if the load failed.
* @see java.beans.SimpleBeanInfo#loadImage(String)
*/
@SuppressWarnings("removal")
private Image loadStandardImage(final String resourceName) {
return AccessController.doPrivileged(
(PrivilegedAction<Image>) () -> loadImage(resourceName));
return loadImage(resourceName);
}
/**

View File

@ -29,10 +29,6 @@ import java.lang.reflect.Array;
import java.lang.reflect.Constructor;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.security.AccessControlContext;
import java.security.AccessController;
import java.security.PrivilegedActionException;
import java.security.PrivilegedExceptionAction;
import com.sun.beans.finder.ClassFinder;
import com.sun.beans.finder.ConstructorFinder;
@ -69,8 +65,6 @@ public class Statement {
}
};
@SuppressWarnings("removal")
private final AccessControlContext acc = AccessController.getContext();
private final Object target;
private final String methodName;
private final Object[] arguments;
@ -174,28 +168,7 @@ public class Statement {
invoke();
}
@SuppressWarnings("removal")
Object invoke() throws Exception {
AccessControlContext acc = this.acc;
if ((acc == null) && (System.getSecurityManager() != null)) {
throw new SecurityException("AccessControlContext is not set");
}
try {
return AccessController.doPrivileged(
new PrivilegedExceptionAction<Object>() {
public Object run() throws Exception {
return invokeInternal();
}
},
acc
);
}
catch (PrivilegedActionException exception) {
throw exception.getException();
}
}
private Object invokeInternal() throws Exception {
Object target = getTarget();
String methodName = getMethodName();

View File

@ -29,9 +29,6 @@ import com.sun.beans.decoder.DocumentHandler;
import java.io.Closeable;
import java.io.InputStream;
import java.io.IOException;
import java.security.AccessControlContext;
import java.security.AccessController;
import java.security.PrivilegedAction;
import org.xml.sax.InputSource;
import org.xml.sax.helpers.DefaultHandler;
@ -64,8 +61,6 @@ import org.xml.sax.helpers.DefaultHandler;
* @author Philip Milne
*/
public class XMLDecoder implements AutoCloseable {
@SuppressWarnings("removal")
private final AccessControlContext acc = AccessController.getContext();
private final DocumentHandler handler = new DocumentHandler();
private final InputSource input;
private Object owner;
@ -189,21 +184,12 @@ public class XMLDecoder implements AutoCloseable {
}
}
@SuppressWarnings("removal")
private boolean parsingComplete() {
if (this.input == null) {
return false;
}
if (this.array == null) {
if ((this.acc == null) && (null != System.getSecurityManager())) {
throw new SecurityException("AccessControlContext is not set");
}
AccessController.doPrivileged(new PrivilegedAction<Void>() {
public Void run() {
XMLDecoder.this.handler.parse(XMLDecoder.this.input);
return null;
}
}, this.acc);
XMLDecoder.this.handler.parse(XMLDecoder.this.input);
this.array = this.handler.getObjects();
}
return true;