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

View File

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

View File

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

View File

@ -38,8 +38,6 @@ import java.io.IOException;
import java.io.ObjectInputStream; import java.io.ObjectInputStream;
import java.io.Serial; import java.io.Serial;
import java.util.ArrayList; import java.util.ArrayList;
import java.security.AccessController;
import java.security.PrivilegedAction;
/** /**
* {@code JLayer} is a universal decorator for Swing components * {@code JLayer} is a universal decorator for Swing components
@ -816,27 +814,14 @@ public final class JLayer<V extends Component>
return currentEventMask; return currentEventMask;
} }
@SuppressWarnings("removal")
private void addAWTEventListener(final long eventMask) { private void addAWTEventListener(final long eventMask) {
AccessController.doPrivileged(new PrivilegedAction<Void>() {
public Void run() {
Toolkit.getDefaultToolkit(). Toolkit.getDefaultToolkit().
addAWTEventListener(LayerEventController.this, eventMask); addAWTEventListener(LayerEventController.this, eventMask);
return null;
}
});
} }
@SuppressWarnings("removal")
private void removeAWTEventListener() { private void removeAWTEventListener() {
AccessController.doPrivileged(new PrivilegedAction<Void>() {
public Void run() {
Toolkit.getDefaultToolkit(). Toolkit.getDefaultToolkit().
removeAWTEventListener(LayerEventController.this); removeAWTEventListener(LayerEventController.this);
return null;
}
});
} }
private boolean isEventEnabled(long eventMask, int id) { 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"); new StringBuffer("JPopupMenu.defaultLWPopupEnabledKey");
/** Bug#4425878-Property javax.swing.adjustPopupLocationToFit introduced */ /** Bug#4425878-Property javax.swing.adjustPopupLocationToFit introduced */
@SuppressWarnings("removal")
static boolean popupPositionFixDisabled = static boolean popupPositionFixDisabled =
java.security.AccessController.doPrivileged( System.getProperty("javax.swing.adjustPopupLocationToFit","").equals("false");
new sun.security.action.GetPropertyAction(
"javax.swing.adjustPopupLocationToFit","")).equals("false");
transient Component invoker; transient Component invoker;
transient Popup popup; transient Popup popup;

View File

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

View File

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

View File

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

View File

@ -32,8 +32,6 @@ import java.security.AccessController;
import sun.awt.AppContext; import sun.awt.AppContext;
import sun.awt.SunToolkit; import sun.awt.SunToolkit;
import sun.awt.event.IgnorePaintEvent; 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 * 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. * will forward the request to the RepaintManager for eventual painting.
* *
*/ */
@SuppressWarnings("removal")
class SwingPaintEventDispatcher extends sun.awt.PaintEventDispatcher { class SwingPaintEventDispatcher extends sun.awt.PaintEventDispatcher {
private static final boolean SHOW_FROM_DOUBLE_BUFFER; private static final boolean SHOW_FROM_DOUBLE_BUFFER;
private static final boolean ERASE_BACKGROUND; private static final boolean ERASE_BACKGROUND;
static { static {
SHOW_FROM_DOUBLE_BUFFER = "true".equals(AccessController.doPrivileged( SHOW_FROM_DOUBLE_BUFFER =
new GetPropertyAction("swing.showFromDoubleBuffer", "true"))); "true".equals(System.getProperty("swing.showFromDoubleBuffer", "true"));
ERASE_BACKGROUND = AccessController.doPrivileged( ERASE_BACKGROUND =
new GetBooleanAction("swing.nativeErase")); "true".equals(System.getProperty("swing.swing.nativeErase", "false"));
} }
public PaintEvent createPaintEvent(Component component, int x, int y, 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.event.MenuDragMouseEvent;
import javax.swing.plaf.UIResource; import javax.swing.plaf.UIResource;
import javax.swing.text.View; import javax.swing.text.View;
import java.security.AccessController;
import sun.security.action.GetPropertyAction;
import sun.awt.AppContext; import sun.awt.AppContext;
import sun.awt.AWTAccessor; import sun.awt.AWTAccessor;
@ -75,12 +73,9 @@ public class SwingUtilities implements SwingConstants
* Returns true if <code>setTransferHandler</code> should change the * Returns true if <code>setTransferHandler</code> should change the
* <code>DropTarget</code>. * <code>DropTarget</code>.
*/ */
@SuppressWarnings("removal")
private static boolean getSuppressDropTarget() { private static boolean getSuppressDropTarget() {
if (!checkedSuppressDropSupport) { if (!checkedSuppressDropSupport) {
suppressDropSupport = Boolean.parseBoolean( suppressDropSupport = Boolean.getBoolean("suppressSwingDropSupport");
AccessController.doPrivileged(
new GetPropertyAction("suppressSwingDropSupport")));
checkedSuppressDropSupport = true; checkedSuppressDropSupport = true;
} }
return suppressDropSupport; return suppressDropSupport;

View File

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

View File

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

View File

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

View File

@ -51,7 +51,6 @@ import java.awt.Dimension;
import java.beans.PropertyChangeListener; import java.beans.PropertyChangeListener;
import java.security.AccessController; import java.security.AccessController;
import java.security.AccessControlContext; import java.security.AccessControlContext;
import java.security.PrivilegedAction;
import sun.reflect.misc.MethodUtil; import sun.reflect.misc.MethodUtil;
import sun.reflect.misc.ReflectUtil; 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. * Test if the specified baseName of the ROOT locale is in java.desktop module.
* JDK always defines the resource bundle of the ROOT locale. * JDK always defines the resource bundle of the ROOT locale.
*/ */
@SuppressWarnings("removal")
private static boolean isDesktopResourceBundle(String baseName) { private static boolean isDesktopResourceBundle(String baseName) {
Module thisModule = UIDefaults.class.getModule(); Module thisModule = UIDefaults.class.getModule();
return AccessController.doPrivileged(new PrivilegedAction<Boolean>() {
@Override
public Boolean run() {
Class<?> c = Class.forName(thisModule, baseName); Class<?> c = Class.forName(thisModule, baseName);
if (c != null) { if (c != null) {
return true; 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. * 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 * @param table a <code>UIDefaults</code> table
* @return the created <code>Object</code> * @return the created <code>Object</code>
*/ */
@SuppressWarnings("removal")
public Object createValue(final UIDefaults table) { 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 { try {
Class<?> c; Class<?> c;
Object cl; Object cl;
@ -1186,8 +1170,6 @@ public class UIDefaults extends Hashtable<Object,Object>
} }
return null; return null;
} }
}, acc);
}
/* /*
* Coerce the array of class types provided into one which * 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.awt.event.KeyEvent;
import java.security.AccessController;
import javax.swing.plaf.ComponentUI; import javax.swing.plaf.ComponentUI;
import javax.swing.border.Border; import javax.swing.border.Border;
@ -55,7 +53,6 @@ import java.util.Locale;
import sun.awt.SunToolkit; import sun.awt.SunToolkit;
import sun.awt.OSInfo; import sun.awt.OSInfo;
import sun.security.action.GetPropertyAction;
import sun.swing.SwingUtilities2; import sun.swing.SwingUtilities2;
import java.util.HashMap; import java.util.HashMap;
import java.util.Objects; import java.util.Objects;
@ -292,8 +289,6 @@ public class UIManager implements Serializable
*/ */
private static String makeSwingPropertiesFilename() { private static String makeSwingPropertiesFilename() {
String sep = File.separator; 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"); String javaHome = System.getProperty("java.home");
if (javaHome == null) { if (javaHome == null) {
javaHome = "<java.home undefined>"; javaHome = "<java.home undefined>";
@ -650,9 +645,7 @@ public class UIManager implements Serializable
* @see #getCrossPlatformLookAndFeelClassName * @see #getCrossPlatformLookAndFeelClassName
*/ */
public static String getSystemLookAndFeelClassName() { public static String getSystemLookAndFeelClassName() {
@SuppressWarnings("removal") String systemLAF = System.getProperty("swing.systemlaf");
String systemLAF = AccessController.doPrivileged(
new GetPropertyAction("swing.systemlaf"));
if (systemLAF != null) { if (systemLAF != null) {
return systemLAF; return systemLAF;
} }
@ -691,9 +684,7 @@ public class UIManager implements Serializable
* @see #getSystemLookAndFeelClassName * @see #getSystemLookAndFeelClassName
*/ */
public static String getCrossPlatformLookAndFeelClassName() { public static String getCrossPlatformLookAndFeelClassName() {
@SuppressWarnings("removal") String laf = System.getProperty("swing.crossplatformlaf");
String laf = AccessController.doPrivileged(
new GetPropertyAction("swing.crossplatformlaf"));
if (laf != null) { if (laf != null) {
return laf; return laf;
} }
@ -1282,9 +1273,6 @@ public class UIManager implements Serializable
else { else {
final Properties props = new Properties(); final Properties props = new Properties();
java.security.AccessController.doPrivileged(
new java.security.PrivilegedAction<Object>() {
public Object run() {
if (OSInfo.getOSType() == OSInfo.OSType.MACOSX) { if (OSInfo.getOSType() == OSInfo.OSType.MACOSX) {
props.put(defaultLAFKey, getSystemLookAndFeelClassName()); props.put(defaultLAFKey, getSystemLookAndFeelClassName());
} }
@ -1311,17 +1299,12 @@ public class UIManager implements Serializable
checkProperty(props, multiplexingLAFKey); checkProperty(props, multiplexingLAFKey);
checkProperty(props, installedLAFsKey); checkProperty(props, installedLAFsKey);
checkProperty(props, disableMnemonicKey); checkProperty(props, disableMnemonicKey);
// Don't care about return value.
return null;
}
});
return props; return props;
} }
} }
private static void checkProperty(Properties props, String key) { 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); String value = System.getProperty(key);
if (value != null) { if (value != null) {
props.put(key, value); props.put(key, value);

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -53,8 +53,6 @@ import java.lang.ref.Reference;
import java.lang.ref.WeakReference; import java.lang.ref.WeakReference;
import java.net.MalformedURLException; import java.net.MalformedURLException;
import java.net.URL; import java.net.URL;
import java.security.AccessController;
import java.security.PrivilegedAction;
import java.util.Enumeration; import java.util.Enumeration;
import javax.accessibility.Accessible; import javax.accessibility.Accessible;
@ -471,23 +469,14 @@ public class HTMLEditorKit extends StyledEditorKit implements Accessible {
/** /**
* Fetch a resource relative to the HTMLEditorKit classfile. * 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 * @param name the name of the resource, relative to the
* HTMLEditorKit class * HTMLEditorKit class
* @return a stream representing the resource * @return a stream representing the resource
*/ */
@SuppressWarnings("removal")
static InputStream getResourceAsStream(final String name) { static InputStream getResourceAsStream(final String name) {
return AccessController.doPrivileged(
new PrivilegedAction<InputStream>() {
public InputStream run() {
return HTMLEditorKit.class.getResourceAsStream(name); return HTMLEditorKit.class.getResourceAsStream(name);
} }
});
}
/** /**
* Fetches the command list for the editor. This is * 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.Reader;
import java.io.Serial; import java.io.Serial;
import java.io.Serializable; import java.io.Serializable;
import java.security.AccessController;
import java.security.PrivilegedAction;
/** /**
* Responsible for starting up a new DocumentParser * Responsible for starting up a new DocumentParser
@ -131,15 +129,9 @@ public class ParserDelegator extends HTMLEditorKit.Parser implements Serializabl
* ParserDelegator class. * ParserDelegator class.
* @return a stream representing the resource * @return a stream representing the resource
*/ */
@SuppressWarnings("removal")
static InputStream getResourceAsStream(final String name) { static InputStream getResourceAsStream(final String name) {
return AccessController.doPrivileged(
new PrivilegedAction<InputStream>() {
public InputStream run() {
return ParserDelegator.class.getResourceAsStream(name); return ParserDelegator.class.getResourceAsStream(name);
} }
});
}
@Serial @Serial
private void readObject(ObjectInputStream s) private void readObject(ObjectInputStream s)

View File

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

View File

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