Skip to content

Commit 92271af

Browse files
author
Harshitha Onkar
committed
8344058: Remove doPrivileged calls from macos platform sources in the java.desktop module
Reviewed-by: prr, aivanov
1 parent 70eb95f commit 92271af

24 files changed

+142
-321
lines changed

src/java.desktop/macosx/classes/apple/laf/JRSUIUtils.java

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -25,12 +25,9 @@
2525

2626
package apple.laf;
2727

28-
import java.security.AccessController;
29-
3028
import apple.laf.JRSUIConstants.Hit;
3129
import apple.laf.JRSUIConstants.ScrollBarPart;
3230
import com.apple.laf.AquaImageFactory.NineSliceMetrics;
33-
import sun.security.action.GetPropertyAction;
3431

3532
public final class JRSUIUtils {
3633

@@ -69,8 +66,7 @@ static boolean currentMacOSXVersionMatchesGivenVersionRange(
6966
final int majorVersion, final int minorVersion, final boolean inclusive,
7067
final boolean matchBelow, final boolean matchAbove) {
7168
// split the "x.y.z" version number
72-
@SuppressWarnings("removal")
73-
String osVersion = AccessController.doPrivileged(new GetPropertyAction("os.version"));
69+
String osVersion = System.getProperty("os.version");
7470
String[] fragments = osVersion.split("\\.");
7571

7672
if (fragments.length < 2) return false;

src/java.desktop/macosx/classes/com/apple/eio/FileManager.java

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -58,15 +58,9 @@ public class FileManager {
5858
loadOSXLibrary();
5959
}
6060

61-
@SuppressWarnings({"removal", "restricted"})
61+
@SuppressWarnings("restricted")
6262
private static void loadOSXLibrary() {
63-
java.security.AccessController.doPrivileged(
64-
new java.security.PrivilegedAction<Void>() {
65-
public Void run() {
66-
System.loadLibrary("osx");
67-
return null;
68-
}
69-
});
63+
System.loadLibrary("osx");
7064
}
7165

7266
/**

src/java.desktop/macosx/classes/com/apple/laf/AquaFileView.java

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -65,15 +65,9 @@ class AquaFileView extends FileView {
6565
loadOSXUILibrary();
6666
}
6767

68-
@SuppressWarnings({"removal", "restricted"})
68+
@SuppressWarnings("restricted")
6969
private static void loadOSXUILibrary() {
70-
java.security.AccessController.doPrivileged(
71-
new java.security.PrivilegedAction<Void>() {
72-
public Void run() {
73-
System.loadLibrary("osxui");
74-
return null;
75-
}
76-
});
70+
System.loadLibrary("osxui");
7771
}
7872

7973
// TODO: Un-comment this out when the native version exists

src/java.desktop/macosx/classes/com/apple/laf/AquaImageFactory.java

Lines changed: 3 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -27,11 +27,11 @@
2727

2828
import java.awt.*;
2929
import java.awt.image.BufferedImage;
30-
import java.security.PrivilegedAction;
3130

3231
import javax.swing.*;
3332
import javax.swing.plaf.*;
3433

34+
import com.apple.eawt.Application;
3535
import sun.lwawt.macosx.LWCToolkit;
3636
import apple.laf.JRSUIConstants.AlignmentHorizontal;
3737
import apple.laf.JRSUIConstants.AlignmentVertical;
@@ -82,22 +82,12 @@ public static IconUIResource getLockImageIcon() {
8282
return getAppIconCompositedOn(lockIcon);
8383
}
8484

85-
@SuppressWarnings("removal")
8685
static Image getGenericJavaIcon() {
87-
return java.security.AccessController.doPrivileged(new PrivilegedAction<Image>() {
88-
public Image run() {
89-
return com.apple.eawt.Application.getApplication().getDockIconImage();
90-
}
91-
});
86+
return Application.getApplication().getDockIconImage();
9287
}
9388

94-
@SuppressWarnings("removal")
9589
static String getPathToThisApplication() {
96-
return java.security.AccessController.doPrivileged(new PrivilegedAction<String>() {
97-
public String run() {
98-
return FileManager.getPathToApplicationBundle();
99-
}
100-
});
90+
return FileManager.getPathToApplicationBundle();
10191
}
10292

10393
static IconUIResource getAppIconCompositedOn(final SystemIcon systemIcon) {

src/java.desktop/macosx/classes/com/apple/laf/AquaLookAndFeel.java

Lines changed: 3 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -154,22 +154,10 @@ public boolean isSupportedLookAndFeel() {
154154
* @see #uninitialize
155155
* @see UIManager#setLookAndFeel
156156
*/
157-
@SuppressWarnings({"removal", "restricted"})
157+
@SuppressWarnings("restricted")
158158
public void initialize() {
159-
java.security.AccessController.doPrivileged(new PrivilegedAction<Void>() {
160-
public Void run() {
161-
System.loadLibrary("osxui");
162-
return null;
163-
}
164-
});
165-
166-
java.security.AccessController.doPrivileged(new PrivilegedAction<Void>(){
167-
@Override
168-
public Void run() {
169-
JRSUIControl.initJRSUI();
170-
return null;
171-
}
172-
});
159+
System.loadLibrary("osxui");
160+
JRSUIControl.initJRSUI();
173161

174162
super.initialize();
175163
final ScreenPopupFactory spf = new ScreenPopupFactory();

src/java.desktop/macosx/classes/com/apple/laf/AquaMenuBarUI.java

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,6 @@
2929
import java.awt.Dimension;
3030
import java.awt.Graphics;
3131
import java.awt.MenuBar;
32-
import java.security.AccessController;
3332

3433
import javax.swing.JComponent;
3534
import javax.swing.JFrame;
@@ -38,18 +37,13 @@
3837
import javax.swing.plaf.basic.BasicMenuBarUI;
3938

4039
import sun.lwawt.macosx.LWCToolkit;
41-
import sun.security.action.GetBooleanAction;
4240

4341
// MenuBar implementation for Mac L&F
44-
@SuppressWarnings({"removal", "restricted"})
42+
@SuppressWarnings("restricted")
4543
public class AquaMenuBarUI extends BasicMenuBarUI implements ScreenMenuBarProvider {
4644

4745
static {
48-
java.security.AccessController.doPrivileged(
49-
(java.security.PrivilegedAction<Void>) () -> {
50-
System.loadLibrary("osxui");
51-
return null;
52-
});
46+
System.loadLibrary("osxui");
5347
}
5448

5549
// Utilities
@@ -151,7 +145,6 @@ public static final boolean isScreenMenuBar(final JMenuBar c) {
151145
public static boolean getScreenMenuBarProperty() {
152146
// Do not allow AWT to set the screen menu bar if it's embedded in another UI toolkit
153147
if (LWCToolkit.isEmbedded()) return false;
154-
return AccessController.doPrivileged(new GetBooleanAction(
155-
AquaLookAndFeel.sPropertyPrefix + "useScreenMenuBar"));
148+
return Boolean.getBoolean(AquaLookAndFeel.sPropertyPrefix + "useScreenMenuBar");
156149
}
157150
}

src/java.desktop/macosx/classes/com/apple/laf/AquaNativeResources.java

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -32,16 +32,10 @@
3232

3333
import com.apple.laf.AquaUtils.RecyclableSingleton;
3434

35-
@SuppressWarnings({"removal", "restricted"})
35+
@SuppressWarnings("restricted")
3636
public class AquaNativeResources {
3737
static {
38-
java.security.AccessController.doPrivileged(
39-
new java.security.PrivilegedAction<Void>() {
40-
public Void run() {
41-
System.loadLibrary("osxui");
42-
return null;
43-
}
44-
});
38+
System.loadLibrary("osxui");
4539
}
4640

4741
// TODO: removing CColorPaint for now

src/java.desktop/macosx/classes/com/apple/laf/AquaUtilControlSize.java

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

2828
import java.awt.*;
2929
import java.beans.*;
30-
import java.security.AccessController;
3130

3231
import javax.swing.*;
3332
import javax.swing.border.Border;
@@ -38,7 +37,6 @@
3837

3938
import com.apple.laf.AquaUtils.RecyclableSingleton;
4039
import com.apple.laf.AquaUtils.RecyclableSingletonFromDefaultConstructor;
41-
import sun.security.action.GetPropertyAction;
4240

4341
public class AquaUtilControlSize {
4442
protected static final String CLIENT_PROPERTY_KEY = "JComponent.sizeVariant";
@@ -72,9 +70,7 @@ private static JRSUIConstants.Size getSizeFromString(final String name) {
7270
}
7371

7472
private static Size getDefaultSize() {
75-
@SuppressWarnings("removal")
76-
final String sizeProperty = AccessController.doPrivileged(
77-
new GetPropertyAction(SYSTEM_PROPERTY_KEY));
73+
final String sizeProperty = System.getProperty(SYSTEM_PROPERTY_KEY);
7874
final JRSUIConstants.Size size = getSizeFromString(sizeProperty);
7975
if (size != null) return size;
8076
return JRSUIConstants.Size.REGULAR;

src/java.desktop/macosx/classes/com/apple/laf/AquaUtils.java

Lines changed: 9 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,6 @@
2929
import java.awt.image.*;
3030
import java.lang.ref.SoftReference;
3131
import java.lang.reflect.Method;
32-
import java.security.AccessController;
33-
import java.security.PrivilegedAction;
3432
import java.util.*;
3533

3634
import javax.swing.*;
@@ -41,7 +39,6 @@
4139

4240
import sun.lwawt.macosx.CPlatformWindow;
4341
import sun.reflect.misc.ReflectUtil;
44-
import sun.security.action.GetPropertyAction;
4542
import sun.swing.SwingUtilities2;
4643

4744
import com.apple.laf.AquaImageFactory.SlicedImageControl;
@@ -205,9 +202,7 @@ V get(final K key) {
205202
private static final RecyclableSingleton<Boolean> enableAnimations = new RecyclableSingleton<Boolean>() {
206203
@Override
207204
protected Boolean getInstance() {
208-
@SuppressWarnings("removal")
209-
final String sizeProperty = (String) AccessController.doPrivileged((PrivilegedAction<?>)new GetPropertyAction(
210-
ANIMATIONS_PROPERTY));
205+
final String sizeProperty = System.getProperty(ANIMATIONS_PROPERTY);
211206
return !"false".equals(sizeProperty); // should be true by default
212207
}
213208
};
@@ -332,25 +327,17 @@ public void paintBorder(final Component c, final Graphics g, final int x, final
332327
}
333328
}
334329

335-
@SuppressWarnings("removal")
336330
private static final RecyclableSingleton<Method> getJComponentGetFlagMethod = new RecyclableSingleton<Method>() {
337331
@Override
338332
protected Method getInstance() {
339-
return AccessController.doPrivileged(
340-
new PrivilegedAction<Method>() {
341-
@Override
342-
public Method run() {
343-
try {
344-
final Method method = JComponent.class.getDeclaredMethod(
345-
"getFlag", new Class<?>[] { int.class });
346-
method.setAccessible(true);
347-
return method;
348-
} catch (final Throwable ignored) {
349-
return null;
350-
}
351-
}
352-
}
353-
);
333+
try {
334+
final Method method = JComponent.class.getDeclaredMethod(
335+
"getFlag", new Class<?>[]{int.class});
336+
method.setAccessible(true);
337+
return method;
338+
} catch (final Throwable ignored) {
339+
return null;
340+
}
354341
}
355342
};
356343

src/java.desktop/macosx/classes/com/apple/laf/ScreenMenu.java

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -45,15 +45,9 @@ final class ScreenMenu extends Menu
4545
loadAWTLibrary();
4646
}
4747

48-
@SuppressWarnings({"removal", "restricted"})
48+
@SuppressWarnings("restricted")
4949
private static void loadAWTLibrary() {
50-
java.security.AccessController.doPrivileged(
51-
new java.security.PrivilegedAction<Void>() {
52-
public Void run() {
53-
System.loadLibrary("awt");
54-
return null;
55-
}
56-
});
50+
System.loadLibrary("awt");
5751
}
5852

5953
// screen menu stuff

0 commit comments

Comments
 (0)