Skip to content

Commit ec148c1

Browse files
committed
8344063: Remove doPrivileged calls from swing classes in the java.desktop module
Reviewed-by: honkar, kcr
1 parent 2cbce1f commit ec148c1

28 files changed

+208
-519
lines changed

src/java.desktop/share/classes/javax/swing/AbstractAction.java

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -32,12 +32,9 @@
3232
import java.io.ObjectOutputStream;
3333
import java.io.Serial;
3434
import java.io.Serializable;
35-
import java.security.AccessController;
3635

3736
import javax.swing.event.SwingPropertyChangeSupport;
3837

39-
import sun.security.action.GetPropertyAction;
40-
4138
/**
4239
* This class provides default implementations for the JFC <code>Action</code>
4340
* interface. Standard behaviors like the get and set methods for
@@ -81,14 +78,11 @@ public abstract class AbstractAction implements Action, Cloneable, Serializable
8178
* Whether or not to reconfigure all action properties from the
8279
* specified event.
8380
*/
84-
@SuppressWarnings("removal")
8581
static boolean shouldReconfigure(PropertyChangeEvent e) {
8682
if (e.getPropertyName() == null) {
8783
synchronized(AbstractAction.class) {
8884
if (RECONFIGURE_ON_NULL == null) {
89-
RECONFIGURE_ON_NULL = Boolean.valueOf(
90-
AccessController.doPrivileged(new GetPropertyAction(
91-
"swing.actions.reconfigureOnNull", "false")));
85+
RECONFIGURE_ON_NULL = Boolean.getBoolean("swing.actions.reconfigureOnNull");
9286
}
9387
return RECONFIGURE_ON_NULL;
9488
}

src/java.desktop/share/classes/javax/swing/DebugGraphics.java

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,6 @@
2727

2828
import java.awt.*;
2929
import java.awt.image.*;
30-
import java.security.AccessController;
31-
import java.security.PrivilegedAction;
3230
import java.text.AttributedCharacterIterator;
3331

3432
/**
@@ -79,22 +77,14 @@ public class DebugGraphics extends Graphics {
7977
* applications, it is for internal use only. When called directly
8078
* it will create an un-usable instance.
8179
*/
82-
@SuppressWarnings("removal")
8380
public DebugGraphics() {
8481
super();
8582
buffer = null;
8683
xOffset = yOffset = 0;
8784

8885
// Creates a Graphics context when the constructor is called.
8986
if (this.graphics == null) {
90-
StackWalker walker = AccessController.doPrivileged(new PrivilegedAction<StackWalker>() {
91-
@Override
92-
public StackWalker run() {
93-
StackWalker stackwalker = StackWalker.getInstance(StackWalker.Option.RETAIN_CLASS_REFERENCE);
94-
return stackwalker;
95-
}
96-
});
97-
87+
StackWalker walker = StackWalker.getInstance(StackWalker.Option.RETAIN_CLASS_REFERENCE);
9888
if (walker.getCallerClass() != this.getClass()) {
9989
BufferedImage bi = new BufferedImage(1, 1, BufferedImage.TYPE_INT_RGB);
10090
this.graphics = bi.createGraphics();

src/java.desktop/share/classes/javax/swing/ImageIcon.java

Lines changed: 11 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -44,10 +44,6 @@
4444
import java.io.Serial;
4545
import java.io.Serializable;
4646
import java.net.URL;
47-
import java.security.AccessControlContext;
48-
import java.security.AccessController;
49-
import java.security.PrivilegedAction;
50-
import java.security.ProtectionDomain;
5147
import java.util.Locale;
5248

5349
import javax.accessibility.Accessible;
@@ -105,27 +101,19 @@ public class ImageIcon implements Icon, Serializable, Accessible {
105101
* It is left for backward compatibility only.
106102
* @deprecated since 1.8
107103
*/
108-
@SuppressWarnings("removal")
109104
@Deprecated
110-
protected static final Component component
111-
= AccessController.doPrivileged(new PrivilegedAction<Component>() {
112-
public Component run() {
113-
try {
114-
final Component component = createNoPermsComponent();
115-
116-
// 6482575 - clear the appContext field so as not to leak it
117-
AWTAccessor.getComponentAccessor().
118-
setAppContext(component, null);
119-
120-
return component;
121-
} catch (Throwable e) {
122-
// We don't care about component.
123-
// So don't prevent class initialisation.
124-
e.printStackTrace();
125-
return null;
126-
}
105+
protected static final Component component = createComponent();
106+
107+
private static final Component createComponent() {
108+
try {
109+
Component component = new Component() {};
110+
// 6482575 - clear the appContext field so as not to leak it
111+
AWTAccessor.getComponentAccessor().setAppContext(component, null);
112+
return component;
113+
} catch (Throwable t) {
114+
return null;
127115
}
128-
});
116+
}
129117

130118
/**
131119
* Do not use this shared media tracker, which is used to load images.
@@ -135,23 +123,6 @@ public Component run() {
135123
@Deprecated
136124
protected static final MediaTracker tracker = new MediaTracker(component);
137125

138-
@SuppressWarnings("removal")
139-
private static Component createNoPermsComponent() {
140-
// 7020198 - set acc field to no permissions and no subject
141-
// Note, will have appContext set.
142-
return AccessController.doPrivileged(
143-
new PrivilegedAction<Component>() {
144-
public Component run() {
145-
return new Component() {
146-
};
147-
}
148-
},
149-
new AccessControlContext(new ProtectionDomain[]{
150-
new ProtectionDomain(null, null)
151-
})
152-
);
153-
}
154-
155126
/**
156127
* Id used in loading images from MediaTracker.
157128
*/

src/java.desktop/share/classes/javax/swing/JLayer.java

Lines changed: 4 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,6 @@
3838
import java.io.ObjectInputStream;
3939
import java.io.Serial;
4040
import java.util.ArrayList;
41-
import java.security.AccessController;
42-
import java.security.PrivilegedAction;
4341

4442
/**
4543
* {@code JLayer} is a universal decorator for Swing components
@@ -816,27 +814,14 @@ private long getCurrentEventMask() {
816814
return currentEventMask;
817815
}
818816

819-
@SuppressWarnings("removal")
820817
private void addAWTEventListener(final long eventMask) {
821-
AccessController.doPrivileged(new PrivilegedAction<Void>() {
822-
public Void run() {
823-
Toolkit.getDefaultToolkit().
824-
addAWTEventListener(LayerEventController.this, eventMask);
825-
return null;
826-
}
827-
});
828-
818+
Toolkit.getDefaultToolkit().
819+
addAWTEventListener(LayerEventController.this, eventMask);
829820
}
830821

831-
@SuppressWarnings("removal")
832822
private void removeAWTEventListener() {
833-
AccessController.doPrivileged(new PrivilegedAction<Void>() {
834-
public Void run() {
835-
Toolkit.getDefaultToolkit().
836-
removeAWTEventListener(LayerEventController.this);
837-
return null;
838-
}
839-
});
823+
Toolkit.getDefaultToolkit().
824+
removeAWTEventListener(LayerEventController.this);
840825
}
841826

842827
private boolean isEventEnabled(long eventMask, int id) {

src/java.desktop/share/classes/javax/swing/JPopupMenu.java

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -119,11 +119,8 @@ public class JPopupMenu extends JComponent implements Accessible,MenuElement {
119119
new StringBuffer("JPopupMenu.defaultLWPopupEnabledKey");
120120

121121
/** Bug#4425878-Property javax.swing.adjustPopupLocationToFit introduced */
122-
@SuppressWarnings("removal")
123122
static boolean popupPositionFixDisabled =
124-
java.security.AccessController.doPrivileged(
125-
new sun.security.action.GetPropertyAction(
126-
"javax.swing.adjustPopupLocationToFit","")).equals("false");
123+
System.getProperty("javax.swing.adjustPopupLocationToFit","").equals("false");
127124

128125
transient Component invoker;
129126
transient Popup popup;

src/java.desktop/share/classes/javax/swing/JRootPane.java

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -26,13 +26,10 @@
2626

2727
import java.awt.*;
2828
import java.beans.*;
29-
import java.security.AccessController;
3029
import javax.accessibility.*;
3130
import javax.swing.plaf.RootPaneUI;
3231
import java.io.Serializable;
3332

34-
import sun.security.action.GetBooleanAction;
35-
3633

3734
/**
3835
* A lightweight container used behind the scenes by
@@ -202,19 +199,15 @@ public class JRootPane extends JComponent implements Accessible {
202199
* Whether or not we should dump the stack when true double buffering
203200
* is disabled. Default is false.
204201
*/
205-
@SuppressWarnings("removal")
206202
private static final boolean LOG_DISABLE_TRUE_DOUBLE_BUFFERING
207-
= AccessController.doPrivileged(new GetBooleanAction(
208-
"swing.logDoubleBufferingDisable"));
203+
= Boolean.getBoolean("swing.logDoubleBufferingDisable");
209204

210205
/**
211206
* Whether or not we should ignore requests to disable true double
212207
* buffering. Default is false.
213208
*/
214-
@SuppressWarnings("removal")
215209
private static final boolean IGNORE_DISABLE_TRUE_DOUBLE_BUFFERING
216-
= AccessController.doPrivileged(new GetBooleanAction(
217-
"swing.ignoreDoubleBufferingDisable"));
210+
= Boolean.getBoolean("swing.ignoreDoubleBufferingDisable");
218211

219212
/**
220213
* Constant used for the windowDecorationStyle property. Indicates that

0 commit comments

Comments
 (0)