8344063: Remove doPrivileged calls from swing classes in the java.desktop module

Reviewed-by: honkar, kcr
This commit is contained in:
Phil Race 2024-11-14 18:42:31 +00:00
parent 2cbce1f0f1
commit ec148c1365
28 changed files with 207 additions and 518 deletions

View File

@ -32,12 +32,9 @@ import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.io.Serial;
import java.io.Serializable;
import java.security.AccessController;
import javax.swing.event.SwingPropertyChangeSupport;
import sun.security.action.GetPropertyAction;
/**
* This class provides default implementations for the JFC <code>Action</code>
* interface. Standard behaviors like the get and set methods for
@ -81,14 +78,11 @@ public abstract class AbstractAction implements Action, Cloneable, Serializable
* Whether or not to reconfigure all action properties from the
* specified event.
*/
@SuppressWarnings("removal")
static boolean shouldReconfigure(PropertyChangeEvent e) {
if (e.getPropertyName() == null) {
synchronized(AbstractAction.class) {
if (RECONFIGURE_ON_NULL == null) {
RECONFIGURE_ON_NULL = Boolean.valueOf(
AccessController.doPrivileged(new GetPropertyAction(
"swing.actions.reconfigureOnNull", "false")));
RECONFIGURE_ON_NULL = Boolean.getBoolean("swing.actions.reconfigureOnNull");
}
return RECONFIGURE_ON_NULL;
}

View File

@ -27,8 +27,6 @@ package javax.swing;
import java.awt.*;
import java.awt.image.*;
import java.security.AccessController;
import java.security.PrivilegedAction;
import java.text.AttributedCharacterIterator;
/**
@ -79,7 +77,6 @@ public class DebugGraphics extends Graphics {
* applications, it is for internal use only. When called directly
* it will create an un-usable instance.
*/
@SuppressWarnings("removal")
public DebugGraphics() {
super();
buffer = null;
@ -87,14 +84,7 @@ public class DebugGraphics extends Graphics {
// Creates a Graphics context when the constructor is called.
if (this.graphics == null) {
StackWalker walker = AccessController.doPrivileged(new PrivilegedAction<StackWalker>() {
@Override
public StackWalker run() {
StackWalker stackwalker = StackWalker.getInstance(StackWalker.Option.RETAIN_CLASS_REFERENCE);
return stackwalker;
}
});
StackWalker walker = StackWalker.getInstance(StackWalker.Option.RETAIN_CLASS_REFERENCE);
if (walker.getCallerClass() != this.getClass()) {
BufferedImage bi = new BufferedImage(1, 1, BufferedImage.TYPE_INT_RGB);
this.graphics = bi.createGraphics();

View File

@ -44,10 +44,6 @@ import java.io.ObjectOutputStream;
import java.io.Serial;
import java.io.Serializable;
import java.net.URL;
import java.security.AccessControlContext;
import java.security.AccessController;
import java.security.PrivilegedAction;
import java.security.ProtectionDomain;
import java.util.Locale;
import javax.accessibility.Accessible;
@ -105,27 +101,19 @@ public class ImageIcon implements Icon, Serializable, Accessible {
* It is left for backward compatibility only.
* @deprecated since 1.8
*/
@SuppressWarnings("removal")
@Deprecated
protected static final Component component
= AccessController.doPrivileged(new PrivilegedAction<Component>() {
public Component run() {
protected static final Component component = createComponent();
private static final Component createComponent() {
try {
final Component component = createNoPermsComponent();
Component component = new Component() {};
// 6482575 - clear the appContext field so as not to leak it
AWTAccessor.getComponentAccessor().
setAppContext(component, null);
AWTAccessor.getComponentAccessor().setAppContext(component, null);
return component;
} catch (Throwable e) {
// We don't care about component.
// So don't prevent class initialisation.
e.printStackTrace();
} catch (Throwable t) {
return null;
}
}
});
/**
* Do not use this shared media tracker, which is used to load images.
@ -135,23 +123,6 @@ public class ImageIcon implements Icon, Serializable, Accessible {
@Deprecated
protected static final MediaTracker tracker = new MediaTracker(component);
@SuppressWarnings("removal")
private static Component createNoPermsComponent() {
// 7020198 - set acc field to no permissions and no subject
// Note, will have appContext set.
return AccessController.doPrivileged(
new PrivilegedAction<Component>() {
public Component run() {
return new Component() {
};
}
},
new AccessControlContext(new ProtectionDomain[]{
new ProtectionDomain(null, null)
})
);
}
/**
* Id used in loading images from MediaTracker.
*/

View File

@ -38,8 +38,6 @@ import java.io.IOException;
import java.io.ObjectInputStream;
import java.io.Serial;
import java.util.ArrayList;
import java.security.AccessController;
import java.security.PrivilegedAction;
/**
* {@code JLayer} is a universal decorator for Swing components
@ -816,27 +814,14 @@ public final class JLayer<V extends Component>
return currentEventMask;
}
@SuppressWarnings("removal")
private void addAWTEventListener(final long eventMask) {
AccessController.doPrivileged(new PrivilegedAction<Void>() {
public Void run() {
Toolkit.getDefaultToolkit().
addAWTEventListener(LayerEventController.this, eventMask);
return null;
}
});
}
@SuppressWarnings("removal")
private void removeAWTEventListener() {
AccessController.doPrivileged(new PrivilegedAction<Void>() {
public Void run() {
Toolkit.getDefaultToolkit().
removeAWTEventListener(LayerEventController.this);
return null;
}
});
}
private boolean isEventEnabled(long eventMask, int id) {

View File

@ -119,11 +119,8 @@ public class JPopupMenu extends JComponent implements Accessible,MenuElement {
new StringBuffer("JPopupMenu.defaultLWPopupEnabledKey");
/** Bug#4425878-Property javax.swing.adjustPopupLocationToFit introduced */
@SuppressWarnings("removal")
static boolean popupPositionFixDisabled =
java.security.AccessController.doPrivileged(
new sun.security.action.GetPropertyAction(
"javax.swing.adjustPopupLocationToFit","")).equals("false");
System.getProperty("javax.swing.adjustPopupLocationToFit","").equals("false");
transient Component invoker;
transient Popup popup;

View File

@ -26,13 +26,10 @@ package javax.swing;
import java.awt.*;
import java.beans.*;
import java.security.AccessController;
import javax.accessibility.*;
import javax.swing.plaf.RootPaneUI;
import java.io.Serializable;
import sun.security.action.GetBooleanAction;
/**
* A lightweight container used behind the scenes by
@ -202,19 +199,15 @@ public class JRootPane extends JComponent implements Accessible {
* Whether or not we should dump the stack when true double buffering
* is disabled. Default is false.
*/
@SuppressWarnings("removal")
private static final boolean LOG_DISABLE_TRUE_DOUBLE_BUFFERING
= AccessController.doPrivileged(new GetBooleanAction(
"swing.logDoubleBufferingDisable"));
= Boolean.getBoolean("swing.logDoubleBufferingDisable");
/**
* Whether or not we should ignore requests to disable true double
* buffering. Default is false.
*/
@SuppressWarnings("removal")
private static final boolean IGNORE_DISABLE_TRUE_DOUBLE_BUFFERING
= AccessController.doPrivileged(new GetBooleanAction(
"swing.ignoreDoubleBufferingDisable"));
= Boolean.getBoolean("swing.ignoreDoubleBufferingDisable");
/**
* Constant used for the windowDecorationStyle property. Indicates that

View File

@ -28,9 +28,6 @@ package javax.swing;
import java.awt.*;
import java.awt.event.*;
import java.awt.image.VolatileImage;
import java.security.AccessControlContext;
import java.security.AccessController;
import java.security.PrivilegedAction;
import java.util.*;
import java.util.concurrent.atomic.AtomicInteger;
import java.applet.*;
@ -211,22 +208,13 @@ public class RepaintManager
}
});
@SuppressWarnings("removal")
var t1 = "true".equals(AccessController.
doPrivileged(new GetPropertyAction(
"swing.volatileImageBufferEnabled", "true")));
volatileImageBufferEnabled = t1;
volatileImageBufferEnabled = "true".equals(System.getProperty("swing.volatileImageBufferEnabled", "true"));
boolean headless = GraphicsEnvironment.isHeadless();
if (volatileImageBufferEnabled && headless) {
volatileImageBufferEnabled = false;
}
@SuppressWarnings("removal")
var t2 = "true".equals(AccessController.doPrivileged(
new GetPropertyAction("awt.nativeDoubleBuffering")));
nativeDoubleBuffering = t2;
@SuppressWarnings("removal")
String bs = AccessController.doPrivileged(
new GetPropertyAction("swing.bufferPerWindow"));
nativeDoubleBuffering = "true".equals(System.getProperty("awt.nativeDoubleBuffering"));
String bs = System.getProperty("swing.bufferPerWindow");
if (headless) {
BUFFER_STRATEGY_TYPE = BUFFER_STRATEGY_SPECIFIED_OFF;
}
@ -239,10 +227,7 @@ public class RepaintManager
else {
BUFFER_STRATEGY_TYPE = BUFFER_STRATEGY_SPECIFIED_OFF;
}
@SuppressWarnings("removal")
var t3 = "true".equals(AccessController.doPrivileged(
new GetPropertyAction("swing.handleTopLevelPaint", "true")));
HANDLE_TOP_LEVEL_PAINT = t3;
HANDLE_TOP_LEVEL_PAINT = "true".equals(System.getProperty("swing.handleTopLevelPaint", "true"));
GraphicsEnvironment ge = GraphicsEnvironment.
getLocalGraphicsEnvironment();
if (ge instanceof SunGraphicsEnvironment) {
@ -611,21 +596,7 @@ public class RepaintManager
if (runnableList == null) {
runnableList = new LinkedList<Runnable>();
}
runnableList.add(new Runnable() {
public void run() {
@SuppressWarnings("removal")
AccessControlContext stack = AccessController.getContext();
@SuppressWarnings("removal")
AccessControlContext acc =
AWTAccessor.getComponentAccessor().getAccessControlContext(c);
javaSecurityAccess.doIntersectionPrivilege(new PrivilegedAction<Void>() {
public Void run() {
r.run();
return null;
}
}, stack, acc);
}
});
runnableList.add(r);
}
scheduleProcessingRunnable(appContext);
}
@ -746,18 +717,7 @@ public class RepaintManager
int n = ic.size();
for(int i = 0; i < n; i++) {
final Component c = ic.get(i);
@SuppressWarnings("removal")
AccessControlContext stack = AccessController.getContext();
@SuppressWarnings("removal")
AccessControlContext acc =
AWTAccessor.getComponentAccessor().getAccessControlContext(c);
javaSecurityAccess.doIntersectionPrivilege(
new PrivilegedAction<Void>() {
public Void run() {
c.validate();
return null;
}
}, stack, acc);
}
}
@ -853,18 +813,11 @@ public class RepaintManager
for (int j=0 ; j < count.get(); j++) {
final int i = j;
final Component dirtyComponent = roots.get(j);
@SuppressWarnings("removal")
AccessControlContext stack = AccessController.getContext();
@SuppressWarnings("removal")
AccessControlContext acc =
AWTAccessor.getComponentAccessor().getAccessControlContext(dirtyComponent);
javaSecurityAccess.doIntersectionPrivilege(new PrivilegedAction<Void>() {
public Void run() {
Rectangle rect = tmpDirtyComponents.get(dirtyComponent);
// Sometimes when RepaintManager is changed during the painting
// we may get null here, see #6995769 for details
if (rect == null) {
return null;
continue;
}
int localBoundsH = dirtyComponent.getHeight();
@ -904,10 +857,6 @@ public class RepaintManager
// Only service repaintRoot once.
repaintRoot = null;
}
return null;
}
}, stack, acc);
}
} finally {
painting = false;

View File

@ -29,8 +29,6 @@ import java.awt.Container;
import java.util.*;
import java.awt.FocusTraversalPolicy;
import sun.util.logging.PlatformLogger;
import sun.security.action.GetPropertyAction;
import java.security.AccessController;
/**
* A FocusTraversalPolicy that determines traversal order by sorting the
@ -95,10 +93,8 @@ public class SortingFocusTraversalPolicy
* When false, the default (tim-sort) algo is used, which may lead to an exception.
* See: JDK-8048887
*/
@SuppressWarnings("removal")
private static final boolean legacySortingFTPEnabled = "true".equals(
AccessController.doPrivileged(
new GetPropertyAction("swing.legacySortingFTPEnabled", "true")));
System.getProperty("swing.legacySortingFTPEnabled", "true"));
/**
* Constructs a SortingFocusTraversalPolicy without a Comparator.

View File

@ -32,8 +32,6 @@ import java.security.AccessController;
import sun.awt.AppContext;
import sun.awt.SunToolkit;
import sun.awt.event.IgnorePaintEvent;
import sun.security.action.GetBooleanAction;
import sun.security.action.GetPropertyAction;
/**
* Swing's PaintEventDispatcher. If the component specified by the PaintEvent
@ -41,16 +39,15 @@ import sun.security.action.GetPropertyAction;
* will forward the request to the RepaintManager for eventual painting.
*
*/
@SuppressWarnings("removal")
class SwingPaintEventDispatcher extends sun.awt.PaintEventDispatcher {
private static final boolean SHOW_FROM_DOUBLE_BUFFER;
private static final boolean ERASE_BACKGROUND;
static {
SHOW_FROM_DOUBLE_BUFFER = "true".equals(AccessController.doPrivileged(
new GetPropertyAction("swing.showFromDoubleBuffer", "true")));
ERASE_BACKGROUND = AccessController.doPrivileged(
new GetBooleanAction("swing.nativeErase"));
SHOW_FROM_DOUBLE_BUFFER =
"true".equals(System.getProperty("swing.showFromDoubleBuffer", "true"));
ERASE_BACKGROUND =
"true".equals(System.getProperty("swing.swing.nativeErase", "false"));
}
public PaintEvent createPaintEvent(Component component, int x, int y,

View File

@ -40,8 +40,6 @@ import javax.accessibility.*;
import javax.swing.event.MenuDragMouseEvent;
import javax.swing.plaf.UIResource;
import javax.swing.text.View;
import java.security.AccessController;
import sun.security.action.GetPropertyAction;
import sun.awt.AppContext;
import sun.awt.AWTAccessor;
@ -75,12 +73,9 @@ public class SwingUtilities implements SwingConstants
* Returns true if <code>setTransferHandler</code> should change the
* <code>DropTarget</code>.
*/
@SuppressWarnings("removal")
private static boolean getSuppressDropTarget() {
if (!checkedSuppressDropSupport) {
suppressDropSupport = Boolean.parseBoolean(
AccessController.doPrivileged(
new GetPropertyAction("suppressSwingDropSupport")));
suppressDropSupport = Boolean.getBoolean("suppressSwingDropSupport");
checkedSuppressDropSupport = true;
}
return suppressDropSupport;

View File

@ -31,8 +31,6 @@ import java.beans.PropertyChangeEvent;
import java.beans.PropertyChangeListener;
import java.beans.PropertyChangeSupport;
import java.lang.ref.WeakReference;
import java.security.AccessController;
import java.security.PrivilegedAction;
import java.util.List;
import java.util.concurrent.Callable;
import java.util.concurrent.CancellationException;
@ -797,7 +795,6 @@ public abstract class SwingWorker<T, V> implements RunnableFuture<T> {
final ExecutorService es = executorService;
appContext.addPropertyChangeListener(AppContext.DISPOSED_PROPERTY_NAME,
new PropertyChangeListener() {
@SuppressWarnings("removal")
@Override
public void propertyChange(PropertyChangeEvent pce) {
boolean disposed = (Boolean)pce.getNewValue();
@ -807,14 +804,7 @@ public abstract class SwingWorker<T, V> implements RunnableFuture<T> {
final ExecutorService executorService =
executorServiceRef.get();
if (executorService != null) {
AccessController.doPrivileged(
new PrivilegedAction<Void>() {
public Void run() {
executorService.shutdown();
return null;
}
}
);
}
}
}

View File

@ -32,9 +32,6 @@ import java.io.InvalidObjectException;
import java.io.ObjectInputStream;
import java.io.Serial;
import java.io.Serializable;
import java.security.AccessControlContext;
import java.security.AccessController;
import java.security.PrivilegedAction;
import java.util.EventListener;
import java.util.concurrent.atomic.AtomicBoolean;
import java.util.concurrent.locks.Lock;
@ -209,25 +206,6 @@ public class Timer implements Serializable
}
}
/*
* The timer's AccessControlContext.
*/
@SuppressWarnings("removal")
private transient volatile AccessControlContext acc =
AccessController.getContext();
/**
* Returns the acc this timer was constructed with.
*/
@SuppressWarnings("removal")
final AccessControlContext getAccessControlContext() {
if (acc == null) {
throw new SecurityException(
"Timer is missing AccessControlContext");
}
return acc;
}
/**
* DoPostEvent is a runnable class that fires actionEvents to
* the listeners on the EventDispatchThread, via invokeLater.
@ -609,15 +587,9 @@ public class Timer implements Serializable
}
@SuppressWarnings("removal")
void post() {
if (notify.compareAndSet(false, true) || !coalesce) {
AccessController.doPrivileged(new PrivilegedAction<Void>() {
public Void run() {
SwingUtilities.invokeLater(doPostEvent);
return null;
}
}, getAccessControlContext());
}
}
@ -630,7 +602,6 @@ public class Timer implements Serializable
private void readObject(ObjectInputStream in)
throws ClassNotFoundException, IOException
{
this.acc = AccessController.getContext();
ObjectInputStream.GetField f = in.readFields();
EventListenerList newListenerList = (EventListenerList)

View File

@ -25,8 +25,6 @@
package javax.swing;
import java.security.AccessController;
import java.security.PrivilegedAction;
import java.util.concurrent.*;
import java.util.concurrent.locks.*;
import java.util.concurrent.atomic.AtomicLong;
@ -83,7 +81,6 @@ class TimerQueue implements Runnable
}
@SuppressWarnings("removal")
void startIfNeeded() {
if (! running) {
runningLock.lock();
@ -92,15 +89,11 @@ class TimerQueue implements Runnable
}
try {
final ThreadGroup threadGroup = AppContext.getAppContext().getThreadGroup();
AccessController.doPrivileged((PrivilegedAction<Object>) () -> {
String name = "TimerQueue";
Thread timerThread =
new Thread(threadGroup, this, name, 0, false);
Thread timerThread = new Thread(threadGroup, this, name, 0, false);
timerThread.setDaemon(true);
timerThread.setPriority(Thread.NORM_PRIORITY);
timerThread.start();
return null;
});
running = true;
} finally {
runningLock.unlock();

View File

@ -51,7 +51,6 @@ import java.awt.Dimension;
import java.beans.PropertyChangeListener;
import java.security.AccessController;
import java.security.AccessControlContext;
import java.security.PrivilegedAction;
import sun.reflect.misc.MethodUtil;
import sun.reflect.misc.ReflectUtil;
@ -341,12 +340,8 @@ public class UIDefaults extends Hashtable<Object,Object>
* Test if the specified baseName of the ROOT locale is in java.desktop module.
* JDK always defines the resource bundle of the ROOT locale.
*/
@SuppressWarnings("removal")
private static boolean isDesktopResourceBundle(String baseName) {
Module thisModule = UIDefaults.class.getModule();
return AccessController.doPrivileged(new PrivilegedAction<Boolean>() {
@Override
public Boolean run() {
Class<?> c = Class.forName(thisModule, baseName);
if (c != null) {
return true;
@ -359,8 +354,6 @@ public class UIDefaults extends Hashtable<Object,Object>
}
}
}
});
}
/**
* Sets the value of <code>key</code> to <code>value</code> for all locales.
@ -1141,16 +1134,7 @@ public class UIDefaults extends Hashtable<Object,Object>
* @param table a <code>UIDefaults</code> table
* @return the created <code>Object</code>
*/
@SuppressWarnings("removal")
public Object createValue(final UIDefaults table) {
// In order to pick up the security policy in effect at the
// time of creation we use a doPrivileged with the
// AccessControlContext that was in place when this was created.
if (acc == null && System.getSecurityManager() != null) {
throw new SecurityException("null AccessControlContext");
}
return AccessController.doPrivileged(new PrivilegedAction<Object>() {
public Object run() {
try {
Class<?> c;
Object cl;
@ -1186,8 +1170,6 @@ public class UIDefaults extends Hashtable<Object,Object>
}
return null;
}
}, acc);
}
/*
* Coerce the array of class types provided into one which

View File

@ -35,8 +35,6 @@ import java.awt.Toolkit;
import java.awt.event.KeyEvent;
import java.security.AccessController;
import javax.swing.plaf.ComponentUI;
import javax.swing.border.Border;
@ -55,7 +53,6 @@ import java.util.Locale;
import sun.awt.SunToolkit;
import sun.awt.OSInfo;
import sun.security.action.GetPropertyAction;
import sun.swing.SwingUtilities2;
import java.util.HashMap;
import java.util.Objects;
@ -292,8 +289,6 @@ public class UIManager implements Serializable
*/
private static String makeSwingPropertiesFilename() {
String sep = File.separator;
// No need to wrap this in a doPrivileged as it's called from
// a doPrivileged.
String javaHome = System.getProperty("java.home");
if (javaHome == null) {
javaHome = "<java.home undefined>";
@ -650,9 +645,7 @@ public class UIManager implements Serializable
* @see #getCrossPlatformLookAndFeelClassName
*/
public static String getSystemLookAndFeelClassName() {
@SuppressWarnings("removal")
String systemLAF = AccessController.doPrivileged(
new GetPropertyAction("swing.systemlaf"));
String systemLAF = System.getProperty("swing.systemlaf");
if (systemLAF != null) {
return systemLAF;
}
@ -691,9 +684,7 @@ public class UIManager implements Serializable
* @see #getSystemLookAndFeelClassName
*/
public static String getCrossPlatformLookAndFeelClassName() {
@SuppressWarnings("removal")
String laf = AccessController.doPrivileged(
new GetPropertyAction("swing.crossplatformlaf"));
String laf = System.getProperty("swing.crossplatformlaf");
if (laf != null) {
return laf;
}
@ -1282,9 +1273,6 @@ public class UIManager implements Serializable
else {
final Properties props = new Properties();
java.security.AccessController.doPrivileged(
new java.security.PrivilegedAction<Object>() {
public Object run() {
if (OSInfo.getOSType() == OSInfo.OSType.MACOSX) {
props.put(defaultLAFKey, getSystemLookAndFeelClassName());
}
@ -1311,17 +1299,12 @@ public class UIManager implements Serializable
checkProperty(props, multiplexingLAFKey);
checkProperty(props, installedLAFsKey);
checkProperty(props, disableMnemonicKey);
// Don't care about return value.
return null;
}
});
return props;
}
}
private static void checkProperty(Properties props, String key) {
// No need to do catch the SecurityException here, this runs
// in a doPrivileged.
String value = System.getProperty(key);
if (value != null) {
props.put(key, value);

View File

@ -32,8 +32,6 @@ import java.io.File;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.lang.ref.WeakReference;
import java.security.AccessController;
import java.security.PrivilegedAction;
import java.text.MessageFormat;
import java.util.ArrayList;
import java.util.List;
@ -917,13 +915,7 @@ class WindowsFileSystemView extends FileSystemView {
}
public boolean isFloppyDrive(final File dir) {
@SuppressWarnings("removal")
String path = AccessController.doPrivileged(new PrivilegedAction<String>() {
public String run() {
return dir.getAbsolutePath();
}
});
String path = dir.getAbsolutePath();
return path != null && (path.equals("A:\\") || path.equals("B:\\"));
}

View File

@ -393,12 +393,9 @@ public class BasicHTML {
private static Boolean useOV = null;
@SuppressWarnings("removal")
private static void setAllowHTMLObject() {
if (useOV == null) {
useOV = java.security.AccessController.doPrivileged(
new sun.security.action.GetBooleanAction(
"swing.html.object"));
useOV = Boolean.getBoolean("swing.html.object");
};
SwingAccessor.setAllowHTMLObject(useOV);
}

View File

@ -45,8 +45,6 @@ import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.Serializable;
import java.security.AccessController;
import java.security.PrivilegedAction;
import java.util.HashSet;
import java.util.Locale;
@ -194,7 +192,6 @@ public abstract class BasicLookAndFeel extends LookAndFeel implements Serializab
/**
* {@inheritDoc}
*/
@SuppressWarnings("removal")
public void uninitialize() {
AppContext context = AppContext.getAppContext();
synchronized (BasicPopupMenuUI.MOUSE_GRABBER_KEY) {
@ -212,7 +209,7 @@ public abstract class BasicLookAndFeel extends LookAndFeel implements Serializab
}
if(invocator != null) {
AccessController.doPrivileged(invocator);
invocator.run();
invocator = null;
}
@ -2082,25 +2079,18 @@ public abstract class BasicLookAndFeel extends LookAndFeel implements Serializab
* Class.getResourceAsStream just returns raw
* bytes, which we can convert to a sound.
*/
@SuppressWarnings("removal")
byte[] buffer = AccessController.doPrivileged(
new PrivilegedAction<byte[]>() {
public byte[] run() {
byte[] buffer = null;
try {
InputStream resource = BasicLookAndFeel.this.
getClass().getResourceAsStream(soundFile);
if (resource == null) {
return null;
}
if (resource != null) {
try (BufferedInputStream in = new BufferedInputStream(resource)) {
return in.readAllBytes();
buffer = in.readAllBytes();
}
}
} catch (IOException ioe) {
System.err.println(ioe.toString());
return null;
}
}
});
if (buffer == null) {
System.err.println(getClass().getName() + "/" +
soundFile + " not found.");
@ -2190,11 +2180,10 @@ public abstract class BasicLookAndFeel extends LookAndFeel implements Serializab
* This class contains listener that watches for all the mouse
* events that can possibly invoke popup on the component
*/
class AWTEventHelper implements AWTEventListener,PrivilegedAction<Object> {
@SuppressWarnings("removal")
class AWTEventHelper implements AWTEventListener {
AWTEventHelper() {
super();
AccessController.doPrivileged(this);
run();
}
public Object run() {

View File

@ -776,22 +776,14 @@ public class BasicPopupMenuUI extends PopupMenuUI {
}
}
@SuppressWarnings("removal")
void grabWindow(MenuElement[] newPath) {
// A grab needs to be added
final Toolkit tk = Toolkit.getDefaultToolkit();
java.security.AccessController.doPrivileged(
new java.security.PrivilegedAction<Object>() {
public Object run() {
tk.addAWTEventListener(MouseGrabber.this,
AWTEvent.MOUSE_EVENT_MASK |
AWTEvent.MOUSE_MOTION_EVENT_MASK |
AWTEvent.MOUSE_WHEEL_EVENT_MASK |
AWTEvent.WINDOW_EVENT_MASK | sun.awt.SunToolkit.GRAB_EVENT_MASK);
return null;
}
}
);
Component invoker = newPath[0].getComponent();
if (invoker instanceof JPopupMenu) {
@ -812,18 +804,10 @@ public class BasicPopupMenuUI extends PopupMenuUI {
}
}
@SuppressWarnings("removal")
void ungrabWindow() {
final Toolkit tk = Toolkit.getDefaultToolkit();
// The grab should be removed
java.security.AccessController.doPrivileged(
new java.security.PrivilegedAction<Object>() {
public Object run() {
tk.removeAWTEventListener(MouseGrabber.this);
return null;
}
}
);
realUngrabWindow();
}

View File

@ -30,7 +30,6 @@ import javax.swing.*;
import java.awt.*;
import sun.awt.AppContext;
import sun.security.action.GetPropertyAction;
import sun.swing.SwingUtilities2;
/**
@ -182,9 +181,7 @@ public class DefaultMetalTheme extends MetalTheme {
}
static {
@SuppressWarnings("removal")
Object boldProperty = java.security.AccessController.doPrivileged(
new GetPropertyAction("swing.boldMetal"));
Object boldProperty = System.getProperty("swing.boldMetal");
if (boldProperty == null || !"false".equals(boldProperty)) {
PLAIN_FONTS = false;
}
@ -371,7 +368,7 @@ public class DefaultMetalTheme extends MetalTheme {
public FontUIResource getFont(int type) {
int mappedType = defaultMapping[type];
if (fonts[type] == null) {
Font f = getPrivilegedFont(mappedType);
Font f = getFontForType(mappedType);
if (f == null) {
f = new Font(getDefaultFontName(type),
@ -385,41 +382,33 @@ public class DefaultMetalTheme extends MetalTheme {
/**
* This is the same as invoking
* <code>Font.getFont(key)</code>, with the exception
* that it is wrapped inside a <code>doPrivileged</code> call.
* <code>Font.getFont(key)</code>
*/
@SuppressWarnings("removal")
protected Font getPrivilegedFont(final int key) {
return java.security.AccessController.doPrivileged(
new java.security.PrivilegedAction<Font>() {
public Font run() {
protected Font getFontForType(final int key) {
return Font.getFont(getDefaultPropertyName(key));
}
}
);
}
}
/**
* The WindowsFontDelegate uses DesktopProperties to obtain fonts.
*/
private static class WindowsFontDelegate extends FontDelegate {
private MetalFontDesktopProperty[] props;
private boolean[] checkedPrivileged;
private boolean[] checked;
public WindowsFontDelegate() {
props = new MetalFontDesktopProperty[6];
checkedPrivileged = new boolean[6];
checked = new boolean[6];
}
public FontUIResource getFont(int type) {
if (fonts[type] != null) {
return fonts[type];
}
if (!checkedPrivileged[type]) {
Font f = getPrivilegedFont(type);
if (!checked[type]) {
Font f = getFontForType(type);
checkedPrivileged[type] = true;
checked[type] = true;
if (f != null) {
fonts[type] = new FontUIResource(f);
return fonts[type];

View File

@ -36,7 +36,6 @@ import java.beans.PropertyChangeEvent;
import java.beans.PropertyChangeListener;
import java.lang.ref.ReferenceQueue;
import java.lang.ref.WeakReference;
import java.security.AccessController;
import javax.swing.ButtonModel;
import javax.swing.DefaultButtonModel;
@ -145,9 +144,7 @@ public class MetalLookAndFeel extends BasicLookAndFeel
if (!checkedWindows) {
if (OSInfo.getOSType() == OSInfo.OSType.WINDOWS) {
isWindows = true;
@SuppressWarnings("removal")
String systemFonts = AccessController.doPrivileged(
new GetPropertyAction("swing.useSystemFontSettings"));
String systemFonts = System.getProperty("swing.useSystemFontSettings");
useSystemFonts = Boolean.parseBoolean(systemFonts);
}
checkedWindows = true;
@ -1662,9 +1659,7 @@ public class MetalLookAndFeel extends BasicLookAndFeel
else {
// Create the default theme. We prefer Ocean, but will
// use DefaultMetalTheme if told to.
@SuppressWarnings("removal")
String theme = AccessController.doPrivileged(
new GetPropertyAction("swing.metalTheme"));
String theme = System.getProperty("swing.metalTheme");
if ("steel".equals(theme)) {
currentTheme = new DefaultMetalTheme();
}

View File

@ -147,14 +147,7 @@ public abstract class AbstractDocument implements Document, Serializable {
if (defaultI18NProperty == null) {
// determine default setting for i18n support
@SuppressWarnings("removal")
String o = java.security.AccessController.doPrivileged(
new java.security.PrivilegedAction<String>() {
public String run() {
return System.getProperty(I18NProperty);
}
}
);
String o = System.getProperty(I18NProperty);
if (o != null) {
defaultI18NProperty = Boolean.valueOf(o);
} else {

View File

@ -26,9 +26,6 @@ package javax.swing.text;
import com.sun.beans.util.Cache;
import java.security.AccessController;
import java.security.PrivilegedAction;
import java.beans.JavaBean;
import java.beans.BeanProperty;
import java.beans.Transient;
@ -3969,9 +3966,6 @@ public abstract class JTextComponent extends JComponent implements Scrollable, A
if (get(type.getSuperclass())) {
return Boolean.TRUE;
}
return AccessController.doPrivileged(
new PrivilegedAction<Boolean>() {
public Boolean run() {
try {
type.getDeclaredMethod("processInputMethodEvent", InputMethodEvent.class);
return Boolean.TRUE;
@ -3979,8 +3973,6 @@ public abstract class JTextComponent extends JComponent implements Scrollable, A
return Boolean.FALSE;
}
}
});
}
};
/**

View File

@ -27,8 +27,6 @@ package javax.swing.text;
import java.awt.*;
import java.awt.font.FontRenderContext;
import java.awt.geom.Rectangle2D;
import java.security.AccessController;
import java.security.PrivilegedAction;
import java.util.Objects;
import javax.swing.event.*;
import java.lang.ref.SoftReference;
@ -839,21 +837,14 @@ public class PlainView extends View implements TabExpander {
return isFPMethodOverridden;
}
@SuppressWarnings("removal")
private static boolean checkFPMethodOverridden(final Class<?> className,
final String methodName,
final FPMethodArgs methodArgs) {
return AccessController
.doPrivileged(new PrivilegedAction<Boolean>() {
@Override
public Boolean run() {
return isFPMethodOverridden(methodName, className,
methodArgs.getMethodArguments(false),
methodArgs.getMethodArguments(true));
}
});
}
private static boolean isFPMethodOverridden(String method,
Class<?> cls,

View File

@ -53,8 +53,6 @@ import java.lang.ref.Reference;
import java.lang.ref.WeakReference;
import java.net.MalformedURLException;
import java.net.URL;
import java.security.AccessController;
import java.security.PrivilegedAction;
import java.util.Enumeration;
import javax.accessibility.Accessible;
@ -471,23 +469,14 @@ public class HTMLEditorKit extends StyledEditorKit implements Accessible {
/**
* Fetch a resource relative to the HTMLEditorKit classfile.
* If this is called on 1.2 the loading will occur under the
* protection of a doPrivileged call to allow the HTMLEditorKit
* to function when used in an applet.
*
* @param name the name of the resource, relative to the
* HTMLEditorKit class
* @return a stream representing the resource
*/
@SuppressWarnings("removal")
static InputStream getResourceAsStream(final String name) {
return AccessController.doPrivileged(
new PrivilegedAction<InputStream>() {
public InputStream run() {
return HTMLEditorKit.class.getResourceAsStream(name);
}
});
}
/**
* Fetches the command list for the editor. This is

View File

@ -35,8 +35,6 @@ import java.io.ObjectInputStream;
import java.io.Reader;
import java.io.Serial;
import java.io.Serializable;
import java.security.AccessController;
import java.security.PrivilegedAction;
/**
* Responsible for starting up a new DocumentParser
@ -131,15 +129,9 @@ public class ParserDelegator extends HTMLEditorKit.Parser implements Serializabl
* ParserDelegator class.
* @return a stream representing the resource
*/
@SuppressWarnings("removal")
static InputStream getResourceAsStream(final String name) {
return AccessController.doPrivileged(
new PrivilegedAction<InputStream>() {
public InputStream run() {
return ParserDelegator.class.getResourceAsStream(name);
}
});
}
@Serial
private void readObject(ObjectInputStream s)

View File

@ -37,8 +37,6 @@ import java.nio.CharBuffer;
import java.nio.charset.Charset;
import java.nio.charset.CharsetDecoder;
import java.nio.charset.CodingErrorAction;
import java.security.AccessController;
import java.security.PrivilegedAction;
import java.util.Dictionary;
import java.util.Enumeration;
import java.util.HashMap;
@ -644,13 +642,7 @@ getCharacterSet(final String name)
{
char[] set = characterSets.get(name);
if (set == null) {
@SuppressWarnings("removal")
InputStream charsetStream = AccessController.doPrivileged(
new PrivilegedAction<InputStream>() {
public InputStream run() {
return RTFReader.class.getResourceAsStream("charsets/" + name + ".txt");
}
});
InputStream charsetStream = RTFReader.class.getResourceAsStream("charsets/" + name + ".txt");
set = readCharset(charsetStream);
defineCharacterSet(name, set);
}

View File

@ -61,10 +61,12 @@ public class InputContextMemoryLeakTest {
button = new JButton("Test");
p1.add(button);
frame.add(p1);
text = new WeakReference<JTextField>(new JTextField("Text"));
p = new WeakReference<JPanel>(new JPanel(new FlowLayout()));
p.get().add(text.get());
frame.add(p.get());
JTextField tf = new JTextField("Text");
text = new WeakReference<JTextField>(tf);
JPanel jp = new JPanel(new FlowLayout());
p = new WeakReference<JPanel>(jp);
jp.add(tf);
frame.add(jp);
frame.setBounds(500, 400, 200, 200);
frame.setVisible(true);
}
@ -79,13 +81,19 @@ public class InputContextMemoryLeakTest {
SwingUtilities.invokeAndWait(new Runnable() {
@Override
public void run() {
// after this the JTextField as well as the JPanel
// are eligible to be GC'd
frame.remove(p.get());
}
});
Util.waitForIdle(null);
//After the next caret blink it automatically TextField references
Thread.sleep(text.get().getCaret().getBlinkRate() * 2);
JTextField tf = text.get();
if (tf != null) {
Thread.sleep(tf.getCaret().getBlinkRate() * 2);
tf = null; // allow to be GCed
}
Util.waitForIdle(null);
try {