Skip to content

Commit 9e92a9e

Browse files
committed
8344059: Remove doPrivileged calls from windows platform sources in the java.desktop module
Reviewed-by: kcr, prr
1 parent 3729884 commit 9e92a9e

17 files changed

+188
-355
lines changed

src/java.desktop/windows/classes/com/sun/java/swing/plaf/windows/AnimationController.java

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

2626
package com.sun.java.swing.plaf.windows;
2727

28-
import java.security.AccessController;
29-
import sun.security.action.GetBooleanAction;
30-
3128
import java.util.*;
3229
import java.beans.PropertyChangeListener;
3330
import java.beans.PropertyChangeEvent;
@@ -67,9 +64,8 @@
6764
*/
6865
class AnimationController implements ActionListener, PropertyChangeListener {
6966

70-
@SuppressWarnings("removal")
7167
private static final boolean VISTA_ANIMATION_DISABLED =
72-
AccessController.doPrivileged(new GetBooleanAction("swing.disablevistaanimation"));
68+
Boolean.getBoolean("swing.disablevistaanimation");
7369

7470

7571
private static final Object ANIMATION_CONTROLLER_KEY =

src/java.desktop/windows/classes/com/sun/java/swing/plaf/windows/WindowsLookAndFeel.java

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,6 @@
5858
import java.awt.image.ImageFilter;
5959
import java.awt.image.ImageProducer;
6060
import java.awt.image.RGBImageFilter;
61-
import java.security.AccessController;
6261

6362
import javax.swing.AbstractAction;
6463
import javax.swing.Action;
@@ -90,7 +89,6 @@
9089
import sun.awt.SunToolkit;
9190
import sun.awt.shell.ShellFolder;
9291
import sun.font.FontUtilities;
93-
import sun.security.action.GetPropertyAction;
9492
import sun.swing.DefaultLayoutStyle;
9593
import sun.swing.ImageIconUIResource;
9694
import sun.swing.MnemonicHandler;
@@ -184,9 +182,7 @@ public void initialize() {
184182
// performance and compatibility issues, so allow this feature
185183
// to be switched off either at runtime or programmatically
186184
//
187-
@SuppressWarnings("removal")
188-
String systemFonts = java.security.AccessController.doPrivileged(
189-
new GetPropertyAction("swing.useSystemFontSettings"));
185+
String systemFonts = System.getProperty("swing.useSystemFontSettings");
190186
useSystemFontSettings = systemFonts == null || Boolean.parseBoolean(systemFonts);
191187

192188
if (useSystemFontSettings) {
@@ -596,8 +592,7 @@ protected void initComponentDefaults(UIDefaults table)
596592
if (!(this instanceof WindowsClassicLookAndFeel) &&
597593
(OSInfo.getOSType() == OSInfo.OSType.WINDOWS &&
598594
OSInfo.getWindowsVersion().compareTo(OSInfo.WINDOWS_XP) >= 0)) {
599-
@SuppressWarnings("removal")
600-
String prop = AccessController.doPrivileged(new GetPropertyAction("swing.noxp"));
595+
String prop = System.getProperty("swing.noxp");
601596
if (prop == null) {
602597

603598
// These desktop properties are not used directly, but are needed to

src/java.desktop/windows/classes/com/sun/java/swing/plaf/windows/XPStyle.java

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,6 @@
5555
import java.awt.image.BufferedImage;
5656
import java.awt.image.DataBufferInt;
5757
import java.awt.image.WritableRaster;
58-
import java.security.AccessController;
5958
import java.util.HashMap;
6059

6160
import javax.swing.AbstractButton;
@@ -79,7 +78,6 @@
7978

8079
import sun.awt.image.SunWritableRaster;
8180
import sun.awt.windows.ThemeReader;
82-
import sun.security.action.GetPropertyAction;
8381
import sun.swing.CachedPainter;
8482

8583
import static com.sun.java.swing.plaf.windows.TMSchema.Part;
@@ -124,7 +122,6 @@ static synchronized void invalidateStyle() {
124122
* @return the singleton instance of this class or null if XP styles
125123
* are not active or if this is not Windows XP
126124
*/
127-
@SuppressWarnings("removal")
128125
static synchronized XPStyle getXP() {
129126
if (themeActive == null) {
130127
Toolkit toolkit = Toolkit.getDefaultToolkit();
@@ -134,9 +131,8 @@ static synchronized XPStyle getXP() {
134131
themeActive = Boolean.FALSE;
135132
}
136133
if (themeActive.booleanValue()) {
137-
GetPropertyAction propertyAction =
138-
new GetPropertyAction("swing.noxp");
139-
if (AccessController.doPrivileged(propertyAction) == null &&
134+
String propertyAction = System.getProperty("swing.noxp");
135+
if (propertyAction == null &&
140136
ThemeReader.isThemed() &&
141137
!(UIManager.getLookAndFeel()
142138
instanceof WindowsClassicLookAndFeel)) {

src/java.desktop/windows/classes/sun/awt/PlatformGraphicsInfo.java

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -39,15 +39,9 @@ public class PlatformGraphicsInfo {
3939
hasDisplays = hasDisplays0();
4040
}
4141

42-
@SuppressWarnings({"removal", "restricted"})
42+
@SuppressWarnings("restricted")
4343
private static void loadAWTLibrary() {
44-
java.security.AccessController.doPrivileged(
45-
new java.security.PrivilegedAction<Void>() {
46-
public Void run() {
47-
System.loadLibrary("awt");
48-
return null;
49-
}
50-
});
44+
System.loadLibrary("awt");
5145
}
5246

5347
private static native boolean hasDisplays0();

src/java.desktop/windows/classes/sun/awt/Win32FontManager.java

Lines changed: 37 additions & 61 deletions
Original file line numberDiff line numberDiff line change
@@ -29,13 +29,12 @@
2929
import java.awt.FontFormatException;
3030
import java.awt.GraphicsEnvironment;
3131
import java.io.File;
32-
import java.security.AccessController;
33-
import java.security.PrivilegedAction;
3432
import java.util.ArrayList;
3533
import java.util.HashMap;
3634
import java.util.Locale;
3735
import java.util.NoSuchElementException;
3836
import java.util.StringTokenizer;
37+
import java.util.function.Supplier;
3938

4039
import sun.awt.windows.WFontConfiguration;
4140
import sun.font.FontManager;
@@ -47,24 +46,21 @@
4746
*/
4847
public final class Win32FontManager extends SunFontManager {
4948

50-
@SuppressWarnings("removal")
5149
private static final TrueTypeFont eudcFont =
52-
AccessController.doPrivileged(new PrivilegedAction<TrueTypeFont>() {
53-
public TrueTypeFont run() {
54-
String eudcFile = getEUDCFontFile();
55-
if (eudcFile != null) {
56-
try {
57-
/* Must use Java rasteriser since GDI doesn't
58-
* enumerate (allow direct use) of EUDC fonts.
59-
*/
60-
return new TrueTypeFont(eudcFile, null, 0,
61-
true, false);
62-
} catch (FontFormatException e) {
63-
}
50+
((Supplier<TrueTypeFont>) () -> {
51+
String eudcFile = getEUDCFontFile();
52+
if (eudcFile != null) {
53+
try {
54+
/* Must use Java rasteriser since GDI doesn't
55+
* enumerate (allow direct use) of EUDC fonts.
56+
*/
57+
return new TrueTypeFont(eudcFile, null, 0,
58+
true, false);
59+
} catch (FontFormatException e) {
6460
}
65-
return null;
6661
}
67-
});
62+
return null;
63+
}).get();
6864

6965
/* Used on Windows to obtain from the windows registry the name
7066
* of a file containing the system EUFC font. If running in one of
@@ -78,20 +74,14 @@ public TrueTypeFont getEUDCFont() {
7874
return eudcFont;
7975
}
8076

81-
@SuppressWarnings("removal")
8277
public Win32FontManager() {
8378
super();
84-
AccessController.doPrivileged(new PrivilegedAction<Object>() {
85-
public Object run() {
86-
87-
/* Register the JRE fonts so that the native platform can
88-
* access them. This is used only on Windows so that when
89-
* printing the printer driver can access the fonts.
90-
*/
91-
registerJREFontsWithPlatform(jreFontDirName);
92-
return null;
93-
}
94-
});
79+
80+
/* Register the JRE fonts so that the native platform can
81+
* access them. This is used only on Windows so that when
82+
* printing the printer driver can access the fonts.
83+
*/
84+
registerJREFontsWithPlatform(jreFontDirName);
9585
}
9686

9787
/**
@@ -213,21 +203,15 @@ protected String[] getDefaultPlatformFont() {
213203
info[1] = "c:\\windows\\fonts";
214204
final String[] dirs = getPlatformFontDirs(true);
215205
if (dirs.length > 1) {
216-
@SuppressWarnings("removal")
217-
String dir = (String)
218-
AccessController.doPrivileged(new PrivilegedAction<Object>() {
219-
public Object run() {
220-
for (int i=0; i<dirs.length; i++) {
221-
String path =
222-
dirs[i] + File.separator + "arial.ttf";
223-
File file = new File(path);
224-
if (file.exists()) {
225-
return dirs[i];
226-
}
227-
}
228-
return null;
229-
}
230-
});
206+
String dir = null;
207+
for (int i=0; i<dirs.length; i++) {
208+
String path = dirs[i] + File.separator + "arial.ttf";
209+
File file = new File(path);
210+
if (file.exists()) {
211+
dir = dirs[i];
212+
break;
213+
}
214+
}
231215
if (dir != null) {
232216
info[1] = dir;
233217
}
@@ -248,7 +232,6 @@ protected void registerJREFontsWithPlatform(String pathName) {
248232
fontsForPrinting = pathName;
249233
}
250234

251-
@SuppressWarnings("removal")
252235
public static void registerJREFontsForPrinting() {
253236
final String pathName;
254237
synchronized (Win32GraphicsEnvironment.class) {
@@ -259,22 +242,15 @@ public static void registerJREFontsForPrinting() {
259242
pathName = fontsForPrinting;
260243
fontsForPrinting = null;
261244
}
262-
java.security.AccessController.doPrivileged(
263-
new java.security.PrivilegedAction<Object>() {
264-
public Object run() {
265-
File f1 = new File(pathName);
266-
String[] ls = f1.list(SunFontManager.getInstance().
267-
getTrueTypeFilter());
268-
if (ls == null) {
269-
return null;
270-
}
271-
for (int i=0; i <ls.length; i++ ) {
272-
File fontFile = new File(f1, ls[i]);
273-
registerFontWithPlatform(fontFile.getAbsolutePath());
274-
}
275-
return null;
276-
}
277-
});
245+
File f1 = new File(pathName);
246+
String[] ls = f1.list(SunFontManager.getInstance().
247+
getTrueTypeFilter());
248+
if (ls != null) {
249+
for (int i=0; i <ls.length; i++ ) {
250+
File fontFile = new File(f1, ls[i]);
251+
registerFontWithPlatform(fontFile.getAbsolutePath());
252+
}
253+
}
278254
}
279255

280256
private static native void registerFontWithPlatform(String fontName);

src/java.desktop/windows/classes/sun/awt/Win32GraphicsDevice.java

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -100,9 +100,7 @@ public class Win32GraphicsDevice extends GraphicsDevice implements
100100
// is run as an NT service. To prevent the loading of ddraw.dll
101101
// completely, sun.awt.nopixfmt should be set as well. Apps which use
102102
// OpenGL w/ Java probably don't want to set this.
103-
@SuppressWarnings("removal")
104-
String nopixfmt = java.security.AccessController.doPrivileged(
105-
new sun.security.action.GetPropertyAction("sun.awt.nopixfmt"));
103+
String nopixfmt = System.getProperty("sun.awt.nopixfmt");
106104
pfDisabled = (nopixfmt != null);
107105
initIDs();
108106
}

src/java.desktop/windows/classes/sun/awt/shell/Win32ShellFolderManager2.java

Lines changed: 20 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,6 @@
3131
import java.io.File;
3232
import java.io.FileNotFoundException;
3333
import java.io.IOException;
34-
import java.security.AccessController;
35-
import java.security.PrivilegedAction;
3634
import java.util.ArrayList;
3735
import java.util.Arrays;
3836
import java.util.List;
@@ -478,12 +476,7 @@ public boolean isComputerNode(final File dir) {
478476
if (dir != null && dir == getDrives()) {
479477
return true;
480478
} else {
481-
@SuppressWarnings("removal")
482-
String path = AccessController.doPrivileged(new PrivilegedAction<String>() {
483-
public String run() {
484-
return dir.getAbsolutePath();
485-
}
486-
});
479+
String path = dir.getAbsolutePath();
487480

488481
return (path.startsWith("\\\\") && path.indexOf("\\", 2) < 0); //Network path
489482
}
@@ -572,25 +565,17 @@ protected Invoker createInvoker() {
572565
private static class ComInvoker extends ThreadPoolExecutor implements ThreadFactory, ShellFolder.Invoker {
573566
private static Thread comThread;
574567

575-
@SuppressWarnings("removal")
576568
private ComInvoker() {
577569
super(1, 1, 0, TimeUnit.DAYS, new LinkedBlockingQueue<>());
578570
allowCoreThreadTimeOut(false);
579571
setThreadFactory(this);
580-
final Runnable shutdownHook = () -> AccessController.doPrivileged((PrivilegedAction<Void>) () -> {
581-
shutdownNow();
582-
return null;
583-
});
584-
AccessController.doPrivileged((PrivilegedAction<Void>) () -> {
585-
Thread t = new Thread(
586-
ThreadGroupUtils.getRootThreadGroup(), shutdownHook,
587-
"ShellFolder", 0, false);
588-
Runtime.getRuntime().addShutdownHook(t);
589-
return null;
590-
});
572+
final Runnable shutdownHook = () -> shutdownNow();
573+
Thread t = new Thread(
574+
ThreadGroupUtils.getRootThreadGroup(), shutdownHook,
575+
"ShellFolder", 0, false);
576+
Runtime.getRuntime().addShutdownHook(t);
591577
}
592578

593-
@SuppressWarnings("removal")
594579
public synchronized Thread newThread(final Runnable task) {
595580
final Runnable comRun = new Runnable() {
596581
public void run() {
@@ -602,27 +587,22 @@ public void run() {
602587
}
603588
}
604589
};
605-
comThread = AccessController.doPrivileged((PrivilegedAction<Thread>) () -> {
606-
String name = "Swing-Shell";
607-
/* The thread must be a member of a thread group
608-
* which will not get GCed before VM exit.
609-
* Make its parent the top-level thread group.
610-
*/
611-
Thread thread = new Thread(
612-
ThreadGroupUtils.getRootThreadGroup(), comRun, name,
613-
0, false);
614-
thread.setDaemon(true);
615-
/* This is important, since this thread running at lower priority
616-
leads to memory consumption when listDrives() function is called
617-
repeatedly.
618-
*/
619-
thread.setPriority(Thread.MAX_PRIORITY);
620-
return thread;
621-
});
590+
/* The thread must be a member of a thread group
591+
* which will not get GCed before VM exit.
592+
* Make its parent the top-level thread group.
593+
*/
594+
comThread = new Thread(
595+
ThreadGroupUtils.getRootThreadGroup(), comRun, "Swing-Shell",
596+
0, false);
597+
comThread.setDaemon(true);
598+
/* This is important, since this thread running at lower priority
599+
leads to memory consumption when listDrives() function is called
600+
repeatedly.
601+
*/
602+
comThread.setPriority(Thread.MAX_PRIORITY);
622603
return comThread;
623604
}
624605

625-
@SuppressWarnings("removal")
626606
public <T> T invoke(Callable<T> task) throws Exception {
627607
if (Thread.currentThread() == comThread) {
628608
// if it's already called from the COM
@@ -640,13 +620,8 @@ public <T> T invoke(Callable<T> task) throws Exception {
640620
try {
641621
return future.get();
642622
} catch (InterruptedException e) {
643-
AccessController.doPrivileged(new PrivilegedAction<Void>() {
644-
public Void run() {
645-
future.cancel(true);
623+
future.cancel(true);
646624

647-
return null;
648-
}
649-
});
650625

651626
throw e;
652627
} catch (ExecutionException e) {

0 commit comments

Comments
 (0)