8344061: Remove doPrivileged calls from shared implementation code in the java.desktop module : part 2

Reviewed-by: aivanov
This commit is contained in:
Phil Race 2024-11-19 19:35:28 +00:00
parent 3328b4ecf2
commit 69c9f2566e
21 changed files with 523 additions and 918 deletions

View File

@ -26,8 +26,6 @@
package sun.awt;
import java.awt.AWTEvent;
import java.security.AccessController;
import java.security.PrivilegedAction;
import java.util.HashSet;
import java.util.IdentityHashMap;
import java.util.Map;
@ -333,17 +331,13 @@ public final class AWTAutoShutdown implements Runnable {
* Creates and starts a new blocker thread. Doesn't return until
* the new blocker thread starts.
*/
@SuppressWarnings("removal")
private void activateBlockerThread() {
AccessController.doPrivileged((PrivilegedAction<Thread>) () -> {
String name = "AWT-Shutdown";
Thread thread = new Thread(
ThreadGroupUtils.getRootThreadGroup(), this, name, 0, false);
thread.setContextClassLoader(null);
thread.setDaemon(false);
blockerThread = thread;
return thread;
}).start();
String name = "AWT-Shutdown";
Thread thread = new Thread(ThreadGroupUtils.getRootThreadGroup(), this, name, 0, false);
thread.setContextClassLoader(null);
thread.setDaemon(false);
blockerThread = thread;
thread.start();
try {
/* Wait for the blocker thread to start. */
mainLock.wait();

View File

@ -32,8 +32,6 @@ import java.awt.TrayIcon;
import java.awt.Toolkit;
import java.awt.GraphicsEnvironment;
import java.awt.event.InvocationEvent;
import java.security.AccessController;
import java.security.PrivilegedAction;
import java.util.Collections;
import java.util.HashMap;
import java.util.IdentityHashMap;
@ -229,20 +227,13 @@ public final class AppContext {
* @see sun.awt.SunToolkit
* @since 1.2
*/
@SuppressWarnings("removal")
AppContext(ThreadGroup threadGroup) {
numAppContexts.incrementAndGet();
this.threadGroup = threadGroup;
threadGroup2appContext.put(threadGroup, this);
this.contextClassLoader =
AccessController.doPrivileged(new PrivilegedAction<ClassLoader>() {
public ClassLoader run() {
return Thread.currentThread().getContextClassLoader();
}
});
this.contextClassLoader = Thread.currentThread().getContextClassLoader();
// Initialize push/pop lock and its condition to be used by all the
// EventQueues within this AppContext
Lock eventQueuePushPopLock = new ReentrantLock();
@ -254,26 +245,19 @@ public final class AppContext {
private static final ThreadLocal<AppContext> threadAppContext =
new ThreadLocal<AppContext>();
@SuppressWarnings("removal")
private static void initMainAppContext() {
// On the main Thread, we get the ThreadGroup, make a corresponding
// AppContext, and instantiate the Java EventQueue. This way, legacy
// code is unaffected by the move to multiple AppContext ability.
AccessController.doPrivileged(new PrivilegedAction<Void>() {
public Void run() {
ThreadGroup currentThreadGroup =
Thread.currentThread().getThreadGroup();
ThreadGroup parentThreadGroup = currentThreadGroup.getParent();
while (parentThreadGroup != null) {
// Find the root ThreadGroup to construct our main AppContext
currentThreadGroup = parentThreadGroup;
parentThreadGroup = currentThreadGroup.getParent();
}
ThreadGroup currentThreadGroup = Thread.currentThread().getThreadGroup();
ThreadGroup parentThreadGroup = currentThreadGroup.getParent();
while (parentThreadGroup != null) {
// Find the root ThreadGroup to construct our main AppContext
currentThreadGroup = parentThreadGroup;
parentThreadGroup = currentThreadGroup.getParent();
}
mainAppContext = SunToolkit.createNewAppContext(currentThreadGroup);
return null;
}
});
mainAppContext = SunToolkit.createNewAppContext(currentThreadGroup);
}
/**
@ -284,7 +268,6 @@ public final class AppContext {
* @see java.lang.ThreadGroup
* @since 1.2
*/
@SuppressWarnings("removal")
public static AppContext getAppContext() {
// we are standalone app, return the main app context
if (numAppContexts.get() == 1 && mainAppContext != null) {
@ -294,69 +277,53 @@ public final class AppContext {
AppContext appContext = threadAppContext.get();
if (null == appContext) {
appContext = AccessController.doPrivileged(new PrivilegedAction<AppContext>()
{
public AppContext run() {
// Get the current ThreadGroup, and look for it and its
// parents in the hash from ThreadGroup to AppContext --
// it should be found, because we use createNewContext()
// when new AppContext objects are created.
ThreadGroup currentThreadGroup = Thread.currentThread().getThreadGroup();
ThreadGroup threadGroup = currentThreadGroup;
// Get the current ThreadGroup, and look for it and its
// parents in the hash from ThreadGroup to AppContext --
// it should be found, because we use createNewContext()
// when new AppContext objects are created.
ThreadGroup currentThreadGroup = Thread.currentThread().getThreadGroup();
ThreadGroup threadGroup = currentThreadGroup;
// Special case: we implicitly create the main app context
// if no contexts have been created yet. This covers standalone apps
// and excludes applets because by the time applet starts
// a number of contexts have already been created by the plugin.
synchronized (getAppContextLock) {
if (numAppContexts.get() == 0) {
if (System.getProperty("javaplugin.version") == null &&
System.getProperty("javawebstart.version") == null) {
initMainAppContext();
} else if (System.getProperty("javafx.version") != null &&
threadGroup.getParent() != null) {
// Swing inside JavaFX case
SunToolkit.createNewAppContext();
}
}
// Special case: we implicitly create the main app context
// if no contexts have been created yet. This covers standalone apps
// and excludes applets because by the time applet starts
// a number of contexts have already been created by the plugin.
synchronized (getAppContextLock) {
if (numAppContexts.get() == 0) {
if (System.getProperty("javaplugin.version") == null &&
System.getProperty("javawebstart.version") == null) {
initMainAppContext();
} else if (System.getProperty("javafx.version") != null &&
threadGroup.getParent() != null) {
// Swing inside JavaFX case
SunToolkit.createNewAppContext();
}
AppContext context = threadGroup2appContext.get(threadGroup);
while (context == null) {
threadGroup = threadGroup.getParent();
if (threadGroup == null) {
// We've got up to the root thread group and did not find an AppContext
// Try to get it from the security manager
SecurityManager securityManager = System.getSecurityManager();
if (securityManager != null) {
ThreadGroup smThreadGroup = securityManager.getThreadGroup();
if (smThreadGroup != null) {
/*
* If we get this far then it's likely that
* the ThreadGroup does not actually belong
* to the applet, so do not cache it.
*/
return threadGroup2appContext.get(smThreadGroup);
}
}
return null;
}
context = threadGroup2appContext.get(threadGroup);
}
// In case we did anything in the above while loop, we add
// all the intermediate ThreadGroups to threadGroup2appContext
// so we won't spin again.
for (ThreadGroup tg = currentThreadGroup; tg != threadGroup; tg = tg.getParent()) {
threadGroup2appContext.put(tg, context);
}
// Now we're done, so we cache the latest key/value pair.
threadAppContext.set(context);
return context;
}
});
}
AppContext context = threadGroup2appContext.get(threadGroup);
while (context == null) {
threadGroup = threadGroup.getParent();
if (threadGroup == null) {
// We've got up to the root thread group and did not find an AppContext
// We have nowhere else to look, and this is not supposed to happen.
// return null from this whole method.
return null;
}
context = threadGroup2appContext.get(threadGroup);
}
// In case we did anything in the above while loop, we add
// all the intermediate ThreadGroups to threadGroup2appContext
// so we won't spin again.
for (ThreadGroup tg = currentThreadGroup; tg != threadGroup; tg = tg.getParent()) {
threadGroup2appContext.put(tg, context);
}
// Now we're done, so we cache the latest key/value pair.
threadAppContext.set(context);
appContext = context;
}
return appContext;
@ -395,7 +362,7 @@ public final class AppContext {
* contained within this AppContext
* @since 1.2
*/
@SuppressWarnings({"deprecation", "removal"})
@SuppressWarnings("deprecation")
public void dispose() throws IllegalThreadStateException {
System.err.println(
"""
@ -439,19 +406,13 @@ public final class AppContext {
log.finer("exception occurred while disposing app context", t);
}
}
AccessController.doPrivileged(new PrivilegedAction<Void>() {
public Void run() {
if (!GraphicsEnvironment.isHeadless() && SystemTray.isSupported())
{
SystemTray systemTray = SystemTray.getSystemTray();
TrayIcon[] trayIconsToDispose = systemTray.getTrayIcons();
for (TrayIcon ti : trayIconsToDispose) {
systemTray.remove(ti);
}
}
return null;
}
});
if (!GraphicsEnvironment.isHeadless() && SystemTray.isSupported()) {
SystemTray systemTray = SystemTray.getSystemTray();
TrayIcon[] trayIconsToDispose = systemTray.getTrayIcons();
for (TrayIcon ti : trayIconsToDispose) {
systemTray.remove(ti);
}
}
// Alert PropertyChangeListeners that the GUI has been disposed.
if (changeSupport != null) {
changeSupport.firePropertyChange(GUI_DISPOSED, false, true);
@ -546,25 +507,6 @@ public final class AppContext {
}
}
static final class CreateThreadAction implements PrivilegedAction<Thread> {
private final AppContext appContext;
private final Runnable runnable;
CreateThreadAction(AppContext ac, Runnable r) {
appContext = ac;
runnable = r;
}
public Thread run() {
Thread t = new Thread(appContext.getThreadGroup(),
runnable, "AppContext Disposer", 0, false);
t.setContextClassLoader(appContext.getContextClassLoader());
t.setPriority(Thread.NORM_PRIORITY + 1);
t.setDaemon(true);
return t;
}
}
static void stopEventDispatchThreads() {
for (AppContext appContext: getAppContexts()) {
if (appContext.isDisposed()) {
@ -576,9 +518,11 @@ public final class AppContext {
if (appContext != AppContext.getAppContext()) {
// Create a thread that belongs to the thread group associated
// with the AppContext and invokes EventQueue.postEvent.
PrivilegedAction<Thread> action = new CreateThreadAction(appContext, r);
@SuppressWarnings("removal")
Thread thread = AccessController.doPrivileged(action);
Thread thread = new Thread(appContext.getThreadGroup(),
r, "AppContext Disposer", 0, false);
thread.setContextClassLoader(appContext.getContextClassLoader());
thread.setPriority(Thread.NORM_PRIORITY + 1);
thread.setDaemon(true);
thread.start();
} else {
r.run();
@ -806,14 +750,8 @@ public final class AppContext {
// Set up JavaAWTAccess in SharedSecrets
static {
SharedSecrets.setJavaAWTAccess(new JavaAWTAccess() {
@SuppressWarnings("removal")
private boolean hasRootThreadGroup(final AppContext ecx) {
return AccessController.doPrivileged(new PrivilegedAction<Boolean>() {
@Override
public Boolean run() {
return ecx.threadGroup.getParent() == null;
}
});
return ecx.threadGroup.getParent() == null;
}
/**

View File

@ -30,8 +30,6 @@ import java.awt.event.FocusEvent;
import java.io.ObjectStreamException;
import java.io.Serial;
import java.lang.reflect.Field;
import java.security.AccessController;
import java.security.PrivilegedAction;
/**
* This class exists for deserialization compatibility only.
@ -72,7 +70,6 @@ class CausedFocusEvent extends FocusEvent {
throw new IllegalStateException();
}
@SuppressWarnings("removal")
@Serial
Object readResolve() throws ObjectStreamException {
FocusEvent.Cause newCause;
@ -119,17 +116,11 @@ class CausedFocusEvent extends FocusEvent {
focusEvent.setSource(null);
try {
final Field consumedField = FocusEvent.class.getField("consumed");
AccessController.doPrivileged(new PrivilegedAction<Object>() {
@Override
public Object run() {
consumedField.setAccessible(true);
try {
consumedField.set(focusEvent, consumed);
} catch (IllegalAccessException e) {
}
return null;
}
});
consumedField.setAccessible(true);
try {
consumedField.set(focusEvent, consumed);
} catch (IllegalAccessException e) {
}
} catch (NoSuchFieldException e) {
}

View File

@ -108,18 +108,11 @@ public final class DebugSettings {
* Load debug properties from file, then override
* with any command line specified properties
*/
@SuppressWarnings("removal")
private synchronized void loadProperties() {
// setup initial properties
java.security.AccessController.doPrivileged(
new java.security.PrivilegedAction<Void>() {
public Void run() {
loadDefaultProperties();
loadFileProperties();
loadSystemProperties();
return null;
}
});
loadDefaultProperties();
loadFileProperties();
loadSystemProperties();
// echo the initial property settings to stdout
if (log.isLoggable(PlatformLogger.Level.FINE)) {

View File

@ -35,8 +35,6 @@ import java.io.IOException;
import java.io.OutputStream;
import java.nio.charset.Charset;
import java.nio.charset.CharsetEncoder;
import java.security.AccessController;
import java.security.PrivilegedAction;
import java.util.Arrays;
import java.util.HashMap;
import java.util.HashSet;
@ -120,7 +118,7 @@ public abstract class FontConfiguration {
this.preferPropFonts = preferPropFonts;
/* fontConfig should be initialised by default constructor, and
* its data tables can be shared, since readFontConfigFile doesn't
* update any other state. Also avoid a doPrivileged block.
* update any other state.
*/
initFontConfig();
}
@ -156,20 +154,8 @@ public abstract class FontConfiguration {
short fontNameID = compFontNameIDs[0][0][0];
short fileNameID = getComponentFileID(fontNameID);
final String fileName = mapFileName(getComponentFileName(fileNameID));
@SuppressWarnings("removal")
Boolean exists = java.security.AccessController.doPrivileged(
new java.security.PrivilegedAction<Boolean>() {
public Boolean run() {
try {
File f = new File(fileName);
return Boolean.valueOf(f.exists());
}
catch (Exception e) {
return Boolean.FALSE;
}
}
});
return exists.booleanValue();
File f = new File(fileName);
return f.exists();
}
private void findFontConfigFile() {
@ -960,18 +946,11 @@ public abstract class FontConfiguration {
!charsetName.startsWith("sun.font.")) {
fc = Charset.forName(charsetName);
} else {
@SuppressWarnings("removal")
Class<?> fcc = AccessController.doPrivileged(new PrivilegedAction<Class<?>>() {
public Class<?> run() {
try {
return Class.forName(charsetName, true,
ClassLoader.getSystemClassLoader());
} catch (ClassNotFoundException e) {
}
return null;
}
});
Class<?> fcc = null;
try {
fcc = Class.forName(charsetName, true, ClassLoader.getSystemClassLoader());
} catch (ClassNotFoundException e) {
}
if (fcc != null) {
try {
fc = (Charset) fcc.getDeclaredConstructor().newInstance();

View File

@ -120,10 +120,7 @@ public class FontDescriptor implements Cloneable {
}
static boolean isLE;
static {
@SuppressWarnings("removal")
String enc = java.security.AccessController.doPrivileged(
new sun.security.action.GetPropertyAction("sun.io.unicode.encoding",
"UnicodeBig"));
String enc = System.getProperty("sun.io.unicode.encoding", "UnicodeBig");
isLE = !"UnicodeBig".equals(enc);
}
}

View File

@ -52,14 +52,8 @@ class NativeLibLoader {
* For now, we know it's done by the implementation, and we assume
* that the name of the library is "awt". -br.
*/
@SuppressWarnings({"removal", "restricted"})
@SuppressWarnings("restricted")
static void loadLibraries() {
java.security.AccessController.doPrivileged(
new java.security.PrivilegedAction<Void>() {
public Void run() {
System.loadLibrary("awt");
return null;
}
});
System.loadLibrary("awt");
}
}

View File

@ -62,10 +62,6 @@ import java.nio.charset.Charset;
import java.nio.charset.CharsetEncoder;
import java.nio.charset.IllegalCharsetNameException;
import java.nio.charset.UnsupportedCharsetException;
import java.security.AccessController;
import java.security.PrivilegedAction;
import java.security.PrivilegedActionException;
import java.security.PrivilegedExceptionAction;
import java.security.ProtectionDomain;
import java.util.AbstractMap;
import java.util.ArrayList;
@ -985,7 +981,6 @@ search:
@SuppressWarnings("removal")
private String removeSuspectedData(DataFlavor flavor, final Transferable contents, final String str)
throws IOException
{
if (null == System.getSecurityManager()
|| !flavor.isMimeTypeEqual("text/uri-list"))
@ -994,34 +989,25 @@ search:
}
final ProtectionDomain userProtectionDomain = getUserProtectionDomain(contents);
StringBuilder allowedFiles = new StringBuilder(str.length());
String [] uriArray = str.split("(\\s)+");
try {
return AccessController.doPrivileged((PrivilegedExceptionAction<String>) () -> {
StringBuilder allowedFiles = new StringBuilder(str.length());
String [] uriArray = str.split("(\\s)+");
for (String fileName : uriArray)
for (String fileName : uriArray)
{
File file = new File(fileName);
if (file.exists() &&
!(isFileInWebstartedCache(file) ||
isForbiddenToRead(file, userProtectionDomain)))
{
if (0 != allowedFiles.length())
{
File file = new File(fileName);
if (file.exists() &&
!(isFileInWebstartedCache(file) ||
isForbiddenToRead(file, userProtectionDomain)))
{
if (0 != allowedFiles.length())
{
allowedFiles.append("\\r\\n");
}
allowedFiles.append(fileName);
}
allowedFiles.append("\\r\\n");
}
return allowedFiles.toString();
});
} catch (PrivilegedActionException pae) {
throw new IOException(pae.getMessage(), pae);
allowedFiles.append(fileName);
}
}
return allowedFiles.toString();
}
private static ProtectionDomain getUserProtectionDomain(Transferable contents) {
@ -1047,25 +1033,19 @@ search:
@SuppressWarnings("removal")
private ArrayList<String> castToFiles(final List<?> files,
final ProtectionDomain userProtectionDomain) throws IOException {
try {
return AccessController.doPrivileged((PrivilegedExceptionAction<ArrayList<String>>) () -> {
ArrayList<String> fileList = new ArrayList<>();
for (Object fileObject : files)
{
File file = castToFile(fileObject);
if (file != null &&
(null == System.getSecurityManager() ||
!(isFileInWebstartedCache(file) ||
isForbiddenToRead(file, userProtectionDomain))))
{
fileList.add(file.getCanonicalPath());
}
}
return fileList;
});
} catch (PrivilegedActionException pae) {
throw new IOException(pae.getMessage());
ArrayList<String> fileList = new ArrayList<>();
for (Object fileObject : files)
{
File file = castToFile(fileObject);
if (file != null &&
(null == System.getSecurityManager() ||
!(isFileInWebstartedCache(file) ||
isForbiddenToRead(file, userProtectionDomain))))
{
fileList.add(file.getCanonicalPath());
}
}
return fileList;
}
// It is important do not use user's successors
@ -1419,7 +1399,6 @@ search:
* and also arbitrary Objects which have a constructor which takes an
* instance of the Class as its sole parameter.
*/
@SuppressWarnings("removal")
private Object constructFlavoredObject(Object arg, DataFlavor flavor,
Class<?> clazz)
throws IOException
@ -1429,15 +1408,7 @@ search:
if (clazz.equals(dfrc)) {
return arg; // simple case
} else {
Constructor<?>[] constructors;
try {
constructors = AccessController.doPrivileged(
(PrivilegedAction<Constructor<?>[]>) dfrc::getConstructors);
} catch (SecurityException se) {
throw new IOException(se.getMessage());
}
Constructor<?>[] constructors = dfrc.getConstructors();
Constructor<?> constructor = Stream.of(constructors)
.filter(c -> Modifier.isPublic(c.getModifiers()))
.filter(c -> {

View File

@ -38,8 +38,6 @@ import java.io.ObjectStreamClass;
import java.io.OutputStream;
import java.lang.reflect.Modifier;
import java.lang.reflect.Proxy;
import java.security.AccessController;
import java.security.PrivilegedAction;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
@ -111,28 +109,14 @@ final class ClassLoaderObjectOutputStream extends ObjectOutputStream {
}
protected void annotateClass(final Class<?> cl) throws IOException {
@SuppressWarnings("removal")
ClassLoader classLoader = AccessController.doPrivileged(
new PrivilegedAction<ClassLoader>() {
public ClassLoader run() {
return cl.getClassLoader();
}
});
ClassLoader classLoader = cl.getClassLoader();
Set<String> s = new HashSet<String>(1);
s.add(cl.getName());
map.put(s, classLoader);
}
protected void annotateProxyClass(final Class<?> cl) throws IOException {
@SuppressWarnings("removal")
ClassLoader classLoader = AccessController.doPrivileged(
new PrivilegedAction<ClassLoader>() {
public ClassLoader run() {
return cl.getClassLoader();
}
});
ClassLoader classLoader = cl.getClassLoader();
Class<?>[] interfaces = cl.getInterfaces();
Set<String> s = new HashSet<String>(interfaces.length);
for (int i = 0; i < interfaces.length; i++) {

View File

@ -41,10 +41,6 @@ import java.awt.event.ActionListener;
import java.awt.event.InvocationEvent;
import java.awt.im.spi.InputMethodDescriptor;
import java.lang.reflect.InvocationTargetException;
import java.security.AccessController;
import java.security.PrivilegedAction;
import java.security.PrivilegedActionException;
import java.security.PrivilegedExceptionAction;
import java.util.Hashtable;
import java.util.Iterator;
import java.util.Locale;
@ -252,24 +248,14 @@ class ExecutableInputMethodManager extends InputMethodManager
* initializes the input method locator list for all
* installed input method descriptors.
*/
@SuppressWarnings("removal")
private void initializeInputMethodLocatorList() {
synchronized (javaInputMethodLocatorList) {
javaInputMethodLocatorList.clear();
try {
AccessController.doPrivileged(new PrivilegedExceptionAction<Object>() {
public Object run() {
for (InputMethodDescriptor descriptor :
ServiceLoader.load(InputMethodDescriptor.class,
ClassLoader.getSystemClassLoader())) {
ClassLoader cl = descriptor.getClass().getClassLoader();
javaInputMethodLocatorList.add(new InputMethodLocator(descriptor, cl, null));
}
return null;
}
});
} catch (PrivilegedActionException e) {
e.printStackTrace();
for (InputMethodDescriptor descriptor :
ServiceLoader.load(InputMethodDescriptor.class,
ClassLoader.getSystemClassLoader())) {
ClassLoader cl = descriptor.getClass().getClassLoader();
javaInputMethodLocatorList.add(new InputMethodLocator(descriptor, cl, null));
}
javaInputMethodCount = javaInputMethodLocatorList.size();
}
@ -594,13 +580,8 @@ class ExecutableInputMethodManager extends InputMethodManager
}
}
@SuppressWarnings("removal")
private Preferences getUserRoot() {
return AccessController.doPrivileged(new PrivilegedAction<Preferences>() {
public Preferences run() {
return Preferences.userRoot();
}
});
return Preferences.userRoot();
}
private Locale getAdvertisedLocale(InputMethodLocator locator, Locale locale) {

View File

@ -44,8 +44,6 @@ import java.awt.event.WindowListener;
import java.awt.im.InputMethodRequests;
import java.awt.im.spi.InputMethod;
import java.lang.Character.Subset;
import java.security.AccessController;
import java.security.PrivilegedAction;
import java.text.MessageFormat;
import java.util.Collection;
import java.util.HashMap;
@ -1036,22 +1034,16 @@ public class InputContext extends java.awt.im.InputContext
/**
* Initializes the input method selection key definition in preference trees
*/
@SuppressWarnings("removal")
private void initializeInputMethodSelectionKey() {
AccessController.doPrivileged(new PrivilegedAction<Object>() {
public Object run() {
// Look in user's tree
Preferences root = Preferences.userRoot();
inputMethodSelectionKey = getInputMethodSelectionKeyStroke(root);
// Look in user's tree
Preferences root = Preferences.userRoot();
inputMethodSelectionKey = getInputMethodSelectionKeyStroke(root);
if (inputMethodSelectionKey == null) {
// Look in system's tree
root = Preferences.systemRoot();
inputMethodSelectionKey = getInputMethodSelectionKeyStroke(root);
}
return null;
}
});
if (inputMethodSelectionKey == null) {
// Look in system's tree
root = Preferences.systemRoot();
inputMethodSelectionKey = getInputMethodSelectionKeyStroke(root);
}
}
private AWTKeyStroke getInputMethodSelectionKeyStroke(Preferences root) {

View File

@ -37,7 +37,6 @@ import java.awt.event.InputMethodEvent;
import java.awt.font.TextHitInfo;
import java.awt.im.InputMethodRequests;
import java.awt.im.spi.InputMethod;
import java.security.AccessController;
import java.text.AttributedCharacterIterator;
import java.text.AttributedCharacterIterator.Attribute;
import java.text.AttributedString;
@ -72,9 +71,7 @@ public class InputMethodContext
static {
// check whether we should use below-the-spot input
// get property from command line
@SuppressWarnings("removal")
String inputStyle = AccessController.doPrivileged
(new GetPropertyAction("java.awt.im.style", null));
String inputStyle = System.getProperty("java.awt.im.style");
// get property from awt.properties file
if (inputStyle == null) {
inputStyle = Toolkit.getProperty("java.awt.im.style", null);

View File

@ -27,8 +27,6 @@ package sun.font;
import java.io.File;
import java.io.OutputStream;
import java.security.AccessController;
import java.security.PrivilegedAction;
import java.util.HashMap;
import java.util.Map;
import java.util.concurrent.Semaphore;
@ -112,25 +110,21 @@ public class CreatedFontTracker {
private static HashMap<File, OutputStream> files = new HashMap<>();
private static Thread t = null;
@SuppressWarnings("removal")
static void init() {
if (t == null) {
// Add a shutdown hook to remove the temp file.
AccessController.doPrivileged((PrivilegedAction<Void>) () -> {
/* The thread must be a member of a thread group
* which will not get GCed before VM exit.
* Make its parent the top-level thread group.
*/
ThreadGroup rootTG = ThreadGroupUtils.getRootThreadGroup();
t = new Thread(rootTG, TempFileDeletionHook::runHooks,
"TempFontFileDeleter", 0, false);
/* Set context class loader to null in order to avoid
* keeping a strong reference to an application classloader.
*/
t.setContextClassLoader(null);
Runtime.getRuntime().addShutdownHook(t);
return null;
});
/* The thread must be a member of a thread group
* which will not get GCed before VM exit.
* Make its parent the top-level thread group.
*/
ThreadGroup rootTG = ThreadGroupUtils.getRootThreadGroup();
t = new Thread(rootTG, TempFileDeletionHook::runHooks,
"TempFontFileDeleter", 0, false);
/* Set context class loader to null in order to avoid
* keeping a strong reference to an application classloader.
*/
t.setContextClassLoader(null);
Runtime.getRuntime().addShutdownHook(t);
}
}

View File

@ -35,11 +35,7 @@ import java.nio.ByteBuffer;
import sun.java2d.Disposer;
import sun.java2d.DisposerRecord;
import java.io.IOException;
import java.util.List;
import java.security.AccessController;
import java.security.PrivilegedActionException;
import java.security.PrivilegedExceptionAction;
public abstract class FileFont extends PhysicalFont {
@ -252,84 +248,35 @@ public abstract class FileFont extends PhysicalFont {
this.tracker = tracker;
}
@SuppressWarnings("removal")
public void dispose() {
java.security.AccessController.doPrivileged(
new java.security.PrivilegedAction<Object>() {
public Object run() {
synchronized (fontFile) {
count--;
if (count > 0) {
return null;
}
}
if (fontFile != null) {
try {
if (tracker != null) {
tracker.subBytes((int)fontFile.length());
}
/* REMIND: is it possible that the file is
* still open? It will be closed when the
* font2D is disposed but could this code
* execute first? If so the file would not
* be deleted on MS-windows.
*/
fontFile.delete();
/* remove from delete on exit hook list : */
// FIXME: still need to be refactored
SunFontManager.getInstance().tmpFontFiles.remove(fontFile);
} catch (Exception e) {
}
}
return null;
synchronized (fontFile) {
count--;
if (count > 0) {
return;
}
}
if (fontFile != null) {
try {
if (tracker != null) {
tracker.subBytes((int)fontFile.length());
}
});
/* REMIND: is it possible that the file is
* still open? It will be closed when the
* font2D is disposed but could this code
* execute first? If so the file would not
* be deleted on MS-windows.
*/
fontFile.delete();
/* remove from delete on exit hook list : */
// FIXME: still need to be refactored
SunFontManager.getInstance().tmpFontFiles.remove(fontFile);
} catch (Exception e) {
}
}
}
}
@SuppressWarnings("removal")
protected String getPublicFileName() {
SecurityManager sm = System.getSecurityManager();
if (sm == null) {
return platName;
}
boolean canReadProperty = true;
try {
sm.checkPropertyAccess("java.io.tmpdir");
} catch (SecurityException e) {
canReadProperty = false;
}
if (canReadProperty) {
return platName;
}
final File f = new File(platName);
Boolean isTmpFile = Boolean.FALSE;
try {
isTmpFile = AccessController.doPrivileged(
new PrivilegedExceptionAction<Boolean>() {
public Boolean run() {
File tmp = new File(System.getProperty("java.io.tmpdir"));
try {
String tpath = tmp.getCanonicalPath();
String fpath = f.getCanonicalPath();
return (fpath == null) || fpath.startsWith(tpath);
} catch (IOException e) {
return Boolean.TRUE;
}
}
}
);
} catch (PrivilegedActionException e) {
// unable to verify whether value of java.io.tempdir will be
// exposed, so return only a name of the font file.
isTmpFile = Boolean.TRUE;
}
return isTmpFile ? "temp file" : platName;
}
}

View File

@ -27,39 +27,32 @@ package sun.font;
import sun.awt.OSInfo;
@SuppressWarnings({"removal", "restricted"})
@SuppressWarnings("restricted")
public class FontManagerNativeLibrary {
static {
java.security.AccessController.doPrivileged(
new java.security.PrivilegedAction<Object>() {
public Object run() {
/* REMIND do we really have to load awt here? */
System.loadLibrary("awt");
if (OSInfo.getOSType() == OSInfo.OSType.WINDOWS) {
/* Ideally fontmanager library should not depend on
particular implementation of the font scaler.
However, freetype scaler is basically small wrapper on
top of freetype library (that is used in binary form).
/* REMIND do we really have to load awt here? */
System.loadLibrary("awt");
if (OSInfo.getOSType() == OSInfo.OSType.WINDOWS) {
/* Ideally fontmanager library should not depend on
particular implementation of the font scaler.
However, freetype scaler is basically small wrapper on
top of freetype library (that is used in binary form).
This wrapper is compiled into fontmanager and this make
fontmanger library depending on freetype library.
This wrapper is compiled into fontmanager and this make
fontmanger library depending on freetype library.
On Windows DLL's in the JRE's BIN directory cannot be
found by windows DLL loading as that directory is not
on the Windows PATH.
On Windows DLL's in the JRE's BIN directory cannot be
found by windows DLL loading as that directory is not
on the Windows PATH.
To avoid link error we have to load freetype explicitly
before we load fontmanager.
To avoid link error we have to load freetype explicitly
before we load fontmanager.
NB: consider moving freetype wrapper part to separate
shared library in order to avoid dependency. */
System.loadLibrary("freetype");
}
System.loadLibrary("fontmanager");
return null;
}
});
NB: consider moving freetype wrapper part to separate
shared library in order to avoid dependency. */
System.loadLibrary("freetype");
}
System.loadLibrary("fontmanager");
}
/*

View File

@ -28,9 +28,7 @@ package sun.font;
import java.awt.Font;
import java.lang.ref.SoftReference;
import java.util.concurrent.ConcurrentHashMap;
import java.security.AccessController;
import java.security.PrivilegedAction;
import javax.swing.plaf.FontUIResource;
import sun.awt.OSInfo;
@ -59,65 +57,57 @@ public final class FontUtilities {
initStatic();
}
@SuppressWarnings("removal")
@SuppressWarnings("deprecation") // PlatformLogger.setLevel is deprecated.
private static void initStatic() {
AccessController.doPrivileged(new PrivilegedAction<Object>() {
@SuppressWarnings("deprecation") // PlatformLogger.setLevel is deprecated.
@Override
public Object run() {
isLinux = OSInfo.getOSType() == OSInfo.OSType.LINUX;
isLinux = OSInfo.getOSType() == OSInfo.OSType.LINUX;
isMacOSX = OSInfo.getOSType() == OSInfo.OSType.MACOSX;
if (isMacOSX) {
// os.version has values like 10.13.6, 10.14.6
// If it is not positively recognised as 10.13 or less,
// assume it means 10.14 or some later version.
isMacOSX14 = true;
String version = System.getProperty("os.version", "");
if (version.startsWith("10.")) {
version = version.substring(3);
int periodIndex = version.indexOf('.');
if (periodIndex != -1) {
version = version.substring(0, periodIndex);
}
try {
int v = Integer.parseInt(version);
isMacOSX14 = (v >= 14);
} catch (NumberFormatException e) {
}
}
}
/* If set to "jdk", use the JDK's scaler rather than
* the platform one. This may be a no-op on platforms where
* JDK has been configured so that it always relies on the
* platform scaler. The principal case where it has an
* effect is that on Windows, 2D will never use GDI.
*/
String scalerStr = System.getProperty("sun.java2d.font.scaler");
if (scalerStr != null) {
useJDKScaler = "jdk".equals(scalerStr);
} else {
useJDKScaler = false;
isMacOSX = OSInfo.getOSType() == OSInfo.OSType.MACOSX;
if (isMacOSX) {
// os.version has values like 10.13.6, 10.14.6
// If it is not positively recognised as 10.13 or less,
// assume it means 10.14 or some later version.
isMacOSX14 = true;
String version = System.getProperty("os.version", "");
if (version.startsWith("10.")) {
version = version.substring(3);
int periodIndex = version.indexOf('.');
if (periodIndex != -1) {
version = version.substring(0, periodIndex);
}
isWindows = OSInfo.getOSType() == OSInfo.OSType.WINDOWS;
String debugLevel =
System.getProperty("sun.java2d.debugfonts");
if (debugLevel != null && !debugLevel.equals("false")) {
debugFonts = true;
logger = PlatformLogger.getLogger("sun.java2d");
if (debugLevel.equals("warning")) {
logger.setLevel(PlatformLogger.Level.WARNING);
} else if (debugLevel.equals("severe")) {
logger.setLevel(PlatformLogger.Level.SEVERE);
}
logging = logger.isEnabled();
try {
int v = Integer.parseInt(version);
isMacOSX14 = (v >= 14);
} catch (NumberFormatException e) {
}
}
}
/* If set to "jdk", use the JDK's scaler rather than
* the platform one. This may be a no-op on platforms where
* JDK has been configured so that it always relies on the
* platform scaler. The principal case where it has an
* effect is that on Windows, 2D will never use GDI.
*/
String scalerStr = System.getProperty("sun.java2d.font.scaler");
if (scalerStr != null) {
useJDKScaler = "jdk".equals(scalerStr);
} else {
useJDKScaler = false;
}
isWindows = OSInfo.getOSType() == OSInfo.OSType.WINDOWS;
String debugLevel =
System.getProperty("sun.java2d.debugfonts");
return null;
if (debugLevel != null && !debugLevel.equals("false")) {
debugFonts = true;
logger = PlatformLogger.getLogger("sun.java2d");
if (debugLevel.equals("warning")) {
logger.setLevel(PlatformLogger.Level.WARNING);
} else if (debugLevel.equals("severe")) {
logger.setLevel(PlatformLogger.Level.SEVERE);
}
});
logging = logger.isEnabled();
}
}
/**

View File

@ -263,7 +263,6 @@ public final class StrikeCache {
initStatic();
}
@SuppressWarnings("removal")
private static void initStatic() {
if (nativeAddressSize < 4) {
@ -271,37 +270,28 @@ public final class StrikeCache {
nativeAddressSize);
}
java.security.AccessController.doPrivileged(
new java.security.PrivilegedAction<Object>() {
public Object run() {
/* Allow a client to override the reference type used to
* cache strikes. The default is "soft" which hints to keep
* the strikes around. This property allows the client to
* override this to "weak" which hint to the GC to free
* memory more aggressively.
*/
String refType = System.getProperty("sun.java2d.font.reftype", "soft");
cacheRefTypeWeak = refType.equals("weak");
/* Allow a client to override the reference type used to
* cache strikes. The default is "soft" which hints to keep
* the strikes around. This property allows the client to
* override this to "weak" which hint to the GC to free
* memory more aggressively.
*/
String refType =
System.getProperty("sun.java2d.font.reftype", "soft");
cacheRefTypeWeak = refType.equals("weak");
String minStrikesStr =
System.getProperty("sun.java2d.font.minstrikes");
if (minStrikesStr != null) {
try {
MINSTRIKES = Integer.parseInt(minStrikesStr);
if (MINSTRIKES <= 0) {
MINSTRIKES = 1;
}
} catch (NumberFormatException e) {
}
String minStrikesStr =
System.getProperty("sun.java2d.font.minstrikes");
if (minStrikesStr != null) {
try {
MINSTRIKES = Integer.parseInt(minStrikesStr);
if (MINSTRIKES <= 0) {
MINSTRIKES = 1;
}
recentStrikes = new FontStrike[MINSTRIKES];
return null;
} catch (NumberFormatException e) {
}
});
}
recentStrikes = new FontStrike[MINSTRIKES];
}

View File

@ -33,8 +33,6 @@ import java.io.FileInputStream;
import java.io.FilenameFilter;
import java.io.IOException;
import java.io.InputStreamReader;
import java.security.AccessController;
import java.security.PrivilegedAction;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.HashSet;
@ -262,30 +260,24 @@ public abstract class SunFontManager implements FontSupport, FontManagerForSGE {
initStatic();
}
@SuppressWarnings("removal")
private static void initStatic() {
AccessController.doPrivileged(new PrivilegedAction<Void>() {
public Void run() {
FontManagerNativeLibrary.load();
FontManagerNativeLibrary.load();
// JNI throws an exception if a class/method/field is not found,
// so there's no need to do anything explicit here.
initIDs();
// JNI throws an exception if a class/method/field is not found,
// so there's no need to do anything explicit here.
initIDs();
switch (StrikeCache.nativeAddressSize) {
case 8: longAddresses = true; break;
case 4: longAddresses = false; break;
default: throw new RuntimeException("Unexpected address size");
}
switch (StrikeCache.nativeAddressSize) {
case 8: longAddresses = true; break;
case 4: longAddresses = false; break;
default: throw new RuntimeException("Unexpected address size");
}
noType1Font = "true".equals(System.getProperty("sun.java2d.noType1Font"));
jreLibDirName = System.getProperty("java.home","") + File.separator + "lib";
jreFontDirName = jreLibDirName + File.separator + "fonts";
noType1Font = "true".equals(System.getProperty("sun.java2d.noType1Font"));
jreLibDirName = System.getProperty("java.home","") + File.separator + "lib";
jreFontDirName = jreLibDirName + File.separator + "fonts";
maxSoftRefCnt = Integer.getInteger("sun.java2d.font.maxSoftRefs", 10);
return null;
}
});
maxSoftRefCnt = Integer.getInteger("sun.java2d.font.maxSoftRefs", 10);
}
/**
@ -304,150 +296,142 @@ public abstract class SunFontManager implements FontSupport, FontManagerForSGE {
/* Initialise ptrs used by JNI methods */
private static native void initIDs();
@SuppressWarnings("removal")
protected SunFontManager() {
AccessController.doPrivileged(new PrivilegedAction<Void>() {
public Void run() {
File badFontFile =
new File(jreFontDirName + File.separator + "badfonts.txt");
if (badFontFile.exists()) {
badFonts = new ArrayList<>();
try (FileInputStream fis = new FileInputStream(badFontFile);
BufferedReader br = new BufferedReader(new InputStreamReader(fis))) {
while (true) {
String name = br.readLine();
if (name == null) {
break;
} else {
if (FontUtilities.debugFonts()) {
FontUtilities.logWarning("read bad font: " + name);
}
badFonts.add(name);
}
}
} catch (IOException e) {
}
}
/* Here we get the fonts in jre/lib/fonts and register
* them so they are always available and preferred over
* other fonts. This needs to be registered before the
* composite fonts as otherwise some native font that
* corresponds may be found as we don't have a way to
* handle two fonts of the same name, so the JRE one
* must be the first one registered. Pass "true" to
* registerFonts method as on-screen these JRE fonts
* always go through the JDK rasteriser.
*/
if (FontUtilities.isLinux) {
/* Linux font configuration uses these fonts */
registerFontDir(jreFontDirName);
}
registerFontsInDir(jreFontDirName, true, Font2D.JRE_RANK,
true, false);
/* Create the font configuration and get any font path
* that might be specified.
*/
fontConfig = createFontConfiguration();
String[] fontInfo = getDefaultPlatformFont();
defaultFontName = fontInfo[0];
if (defaultFontName == null && FontUtilities.debugFonts()) {
FontUtilities.logWarning("defaultFontName is null");
}
defaultFontFileName = fontInfo[1];
String extraFontPath = fontConfig.getExtraFontPath();
/* In prior releases the debugging font path replaced
* all normally located font directories except for the
* JRE fonts dir. This directory is still always located
* and placed at the head of the path but as an
* augmentation to the previous behaviour the
* changes below allow you to additionally append to
* the font path by starting with append: or prepend by
* starting with a prepend: sign. Eg: to append
* -Dsun.java2d.fontpath=append:/usr/local/myfonts
* and to prepend
* -Dsun.java2d.fontpath=prepend:/usr/local/myfonts Disp
*
* If there is an appendedfontpath it in the font
* configuration it is used instead of searching the
* system for dirs.
* The behaviour of append and prepend is then similar
* to the normal case. ie it goes after what
* you prepend and * before what you append. If the
* sun.java2d.fontpath property is used, but it
* neither the append or prepend syntaxes is used then
* as except for the JRE dir the path is replaced and it
* is up to you to make sure that all the right
* directories are located. This is platform and
* locale-specific so its almost impossible to get
* right, so it should be used with caution.
*/
boolean prependToPath = false;
boolean appendToPath = false;
String dbgFontPath = System.getProperty("sun.java2d.fontpath");
if (dbgFontPath != null) {
if (dbgFontPath.startsWith("prepend:")) {
prependToPath = true;
dbgFontPath =
dbgFontPath.substring("prepend:".length());
} else if (dbgFontPath.startsWith("append:")) {
appendToPath = true;
dbgFontPath =
dbgFontPath.substring("append:".length());
}
}
if (FontUtilities.debugFonts()) {
FontUtilities.logInfo("JRE font directory: " + jreFontDirName);
FontUtilities.logInfo("Extra font path: " + extraFontPath);
FontUtilities.logInfo("Debug font path: " + dbgFontPath);
}
if (dbgFontPath != null) {
/* In debugging mode we register all the paths
* Caution: this is a very expensive call on Solaris:-
*/
fontPath = getPlatformFontPath(noType1Font);
if (extraFontPath != null) {
fontPath = extraFontPath + File.pathSeparator + fontPath;
}
if (appendToPath) {
fontPath += File.pathSeparator + dbgFontPath;
} else if (prependToPath) {
fontPath = dbgFontPath + File.pathSeparator + fontPath;
File badFontFile =
new File(jreFontDirName + File.separator + "badfonts.txt");
if (badFontFile.exists()) {
badFonts = new ArrayList<>();
try (FileInputStream fis = new FileInputStream(badFontFile);
BufferedReader br = new BufferedReader(new InputStreamReader(fis))) {
while (true) {
String name = br.readLine();
if (name == null) {
break;
} else {
fontPath = dbgFontPath;
if (FontUtilities.debugFonts()) {
FontUtilities.logWarning("read bad font: " + name);
}
badFonts.add(name);
}
registerFontDirs(fontPath);
} else if (extraFontPath != null) {
/* If the font configuration contains an
* "appendedfontpath" entry, it is interpreted as a
* set of locations that should always be registered.
* It may be additional to locations normally found
* for that place, or it may be locations that need
* to have all their paths registered to locate all
* the needed platform names.
* This is typically when the same .TTF file is
* referenced from multiple font.dir files and all
* of these must be read to find all the native
* (XLFD) names for the font, so that X11 font APIs
* can be used for as many code points as possible.
*/
registerFontDirs(extraFontPath);
}
initCompositeFonts(fontConfig, null);
return null;
} catch (IOException e) {
}
});
}
/* Here we get the fonts in jre/lib/fonts and register
* them so they are always available and preferred over
* other fonts. This needs to be registered before the
* composite fonts as otherwise some native font that
* corresponds may be found as we don't have a way to
* handle two fonts of the same name, so the JRE one
* must be the first one registered. Pass "true" to
* registerFonts method as on-screen these JRE fonts
* always go through the JDK rasteriser.
*/
if (FontUtilities.isLinux) {
/* Linux font configuration uses these fonts */
registerFontDir(jreFontDirName);
}
registerFontsInDir(jreFontDirName, true, Font2D.JRE_RANK,
true, false);
/* Create the font configuration and get any font path
* that might be specified.
*/
fontConfig = createFontConfiguration();
String[] fontInfo = getDefaultPlatformFont();
defaultFontName = fontInfo[0];
if (defaultFontName == null && FontUtilities.debugFonts()) {
FontUtilities.logWarning("defaultFontName is null");
}
defaultFontFileName = fontInfo[1];
String extraFontPath = fontConfig.getExtraFontPath();
/* In prior releases the debugging font path replaced
* all normally located font directories except for the
* JRE fonts dir. This directory is still always located
* and placed at the head of the path but as an
* augmentation to the previous behaviour the
* changes below allow you to additionally append to
* the font path by starting with append: or prepend by
* starting with a prepend: sign. Eg: to append
* -Dsun.java2d.fontpath=append:/usr/local/myfonts
* and to prepend
* -Dsun.java2d.fontpath=prepend:/usr/local/myfonts Disp
*
* If there is an appendedfontpath it in the font
* configuration it is used instead of searching the
* system for dirs.
* The behaviour of append and prepend is then similar
* to the normal case. ie it goes after what
* you prepend and * before what you append. If the
* sun.java2d.fontpath property is used, but it
* neither the append or prepend syntaxes is used then
* as except for the JRE dir the path is replaced and it
* is up to you to make sure that all the right
* directories are located. This is platform and
* locale-specific so its almost impossible to get
* right, so it should be used with caution.
*/
boolean prependToPath = false;
boolean appendToPath = false;
String dbgFontPath = System.getProperty("sun.java2d.fontpath");
if (dbgFontPath != null) {
if (dbgFontPath.startsWith("prepend:")) {
prependToPath = true;
dbgFontPath =
dbgFontPath.substring("prepend:".length());
} else if (dbgFontPath.startsWith("append:")) {
appendToPath = true;
dbgFontPath =
dbgFontPath.substring("append:".length());
}
}
if (FontUtilities.debugFonts()) {
FontUtilities.logInfo("JRE font directory: " + jreFontDirName);
FontUtilities.logInfo("Extra font path: " + extraFontPath);
FontUtilities.logInfo("Debug font path: " + dbgFontPath);
}
if (dbgFontPath != null) {
/* In debugging mode we register all the paths
* Caution: this is a very expensive call on Solaris:-
*/
fontPath = getPlatformFontPath(noType1Font);
if (extraFontPath != null) {
fontPath = extraFontPath + File.pathSeparator + fontPath;
}
if (appendToPath) {
fontPath += File.pathSeparator + dbgFontPath;
} else if (prependToPath) {
fontPath = dbgFontPath + File.pathSeparator + fontPath;
} else {
fontPath = dbgFontPath;
}
registerFontDirs(fontPath);
} else if (extraFontPath != null) {
/* If the font configuration contains an
* "appendedfontpath" entry, it is interpreted as a
* set of locations that should always be registered.
* It may be additional to locations normally found
* for that place, or it may be locations that need
* to have all their paths registered to locate all
* the needed platform names.
* This is typically when the same .TTF file is
* referenced from multiple font.dir files and all
* of these must be read to find all the native
* (XLFD) names for the font, so that X11 font APIs
* can be used for as many code points as possible.
*/
registerFontDirs(extraFontPath);
}
initCompositeFonts(fontConfig, null);
}
public Font2DHandle getNewComposite(String family, int style,
@ -1095,7 +1079,6 @@ public abstract class SunFontManager implements FontSupport, FontManagerForSGE {
private boolean haveCheckedUnreferencedFontFiles;
@SuppressWarnings("removal")
private String[] getFontFilesFromPath(boolean noType1) {
final FilenameFilter filter;
if (noType1) {
@ -1103,34 +1086,30 @@ public abstract class SunFontManager implements FontSupport, FontManagerForSGE {
} else {
filter = new TTorT1Filter();
}
return AccessController.doPrivileged(new PrivilegedAction<String[]>() {
public String[] run() {
if (pathDirs.length == 1) {
File dir = new File(pathDirs[0]);
String[] files = dir.list(filter);
if (files == null) {
return new String[0];
}
for (int f=0; f<files.length; f++) {
files[f] = files[f].toLowerCase();
}
return files;
} else {
ArrayList<String> fileList = new ArrayList<>();
for (int i = 0; i< pathDirs.length; i++) {
File dir = new File(pathDirs[i]);
String[] files = dir.list(filter);
if (files == null) {
continue;
}
for (int f = 0; f < files.length ; f++) {
fileList.add(files[f].toLowerCase());
}
}
return fileList.toArray(STR_ARRAY);
if (pathDirs.length == 1) {
File dir = new File(pathDirs[0]);
String[] files = dir.list(filter);
if (files == null) {
return new String[0];
}
for (int f=0; f<files.length; f++) {
files[f] = files[f].toLowerCase();
}
return files;
} else {
ArrayList<String> fileList = new ArrayList<>();
for (int i = 0; i< pathDirs.length; i++) {
File dir = new File(pathDirs[i]);
String[] files = dir.list(filter);
if (files == null) {
continue;
}
for (int f = 0; f < files.length ; f++) {
fileList.add(files[f].toLowerCase());
}
}
});
return fileList.toArray(STR_ARRAY);
}
}
/* This is needed since some windows registry names don't match
@ -1430,7 +1409,6 @@ public abstract class SunFontManager implements FontSupport, FontManagerForSGE {
return new HashMap<>(0);
}
@SuppressWarnings("removal")
Font2D findFontFromPlatformMap(String lcName, int style) {
HashMap<String, FamilyDescription> platformFontMap = SunFontManager.platformFontMap;
if (platformFontMap == null) {
@ -1524,20 +1502,16 @@ public abstract class SunFontManager implements FontSupport, FontManagerForSGE {
final String[] files = {
plainFile, boldFile, italicFile, boldItalicFile } ;
failure = AccessController.doPrivileged(new PrivilegedAction<Boolean>() {
public Boolean run() {
for (int i=0; i<files.length; i++) {
if (files[i] == null) {
continue;
}
File f = new File(files[i]);
if (!f.exists()) {
return Boolean.TRUE;
}
}
return Boolean.FALSE;
for (int i=0; i<files.length; i++) {
if (files[i] == null) {
continue;
}
});
File f = new File(files[i]);
if (!f.exists()) {
failure = true;
break;
}
}
if (failure) {
if (FontUtilities.isLogging()) {
@ -1724,21 +1698,11 @@ public abstract class SunFontManager implements FontSupport, FontManagerForSGE {
} else if (pathDirs.length==1) {
return pathDirs[0] + File.separator + s;
} else {
@SuppressWarnings("removal")
String path = AccessController.doPrivileged(
new PrivilegedAction<String>() {
public String run() {
for (int p = 0; p < pathDirs.length; p++) {
File f = new File(pathDirs[p] +File.separator+ s);
if (f.exists()) {
return f.getAbsolutePath();
}
}
return null;
}
});
if (path != null) {
return path;
for (int p = 0; p < pathDirs.length; p++) {
f = new File(pathDirs[p] + File.separator + s);
if (f.exists()) {
return f.getAbsolutePath();
}
}
}
return s; // shouldn't happen, but harmless
@ -2181,7 +2145,6 @@ public abstract class SunFontManager implements FontSupport, FontManagerForSGE {
private int createdFontCount = 0;
@SuppressWarnings("removal")
public Font2D[] createFont2D(File fontFile, int fontFormat, boolean all,
boolean isCopy, CreatedFontTracker tracker)
throws FontFormatException {
@ -2229,15 +2192,10 @@ public abstract class SunFontManager implements FontSupport, FontManagerForSGE {
}
} catch (FontFormatException e) {
if (isCopy) {
AccessController.doPrivileged(new PrivilegedAction<Void>() {
public Void run() {
if (_tracker != null) {
_tracker.subBytes((int)fFile.length());
}
fFile.delete();
return null;
}
});
if (_tracker != null) {
_tracker.subBytes((int)fFile.length());
}
fFile.delete();
}
throw(e);
}
@ -2253,39 +2211,31 @@ public abstract class SunFontManager implements FontSupport, FontManagerForSGE {
if (fileCloser == null) {
final Runnable fileCloserRunnable = new Runnable() {
public void run() {
AccessController.doPrivileged(new PrivilegedAction<Void>() {
public Void run() {
for (int i = 0;i < CHANNELPOOLSIZE; i++) {
if (fontFileCache[i] != null) {
try {
fontFileCache[i].close();
} catch (Exception e) {
}
}
for (int i = 0;i < CHANNELPOOLSIZE; i++) {
if (fontFileCache[i] != null) {
try {
fontFileCache[i].close();
} catch (Exception e) {
}
if (tmpFontFiles != null) {
File[] files = new File[tmpFontFiles.size()];
files = tmpFontFiles.toArray(files);
for (int f=0; f<files.length;f++) {
try {
files[f].delete();
} catch (Exception e) {
}
}
}
return null;
}
});
}
if (tmpFontFiles != null) {
File[] files = new File[tmpFontFiles.size()];
files = tmpFontFiles.toArray(files);
for (int f=0; f<files.length;f++) {
try {
files[f].delete();
} catch (Exception e) {
}
}
}
}
};
AccessController.doPrivileged((PrivilegedAction<Void>) () -> {
ThreadGroup rootTG = ThreadGroupUtils.getRootThreadGroup();
fileCloser = new Thread(rootTG, fileCloserRunnable,
"FileCloser", 0, false);
fileCloser.setContextClassLoader(null);
Runtime.getRuntime().addShutdownHook(fileCloser);
return null;
});
ThreadGroup rootTG = ThreadGroupUtils.getRootThreadGroup();
fileCloser = new Thread(rootTG, fileCloserRunnable,
"FileCloser", 0, false);
fileCloser.setContextClassLoader(null);
Runtime.getRuntime().addShutdownHook(fileCloser);
}
}
}
@ -2930,7 +2880,6 @@ public abstract class SunFontManager implements FontSupport, FontManagerForSGE {
return fontPath;
}
@SuppressWarnings("removal")
protected void loadFonts() {
if (discoveredAllFonts) {
return;
@ -2943,28 +2892,23 @@ public abstract class SunFontManager implements FontSupport, FontManagerForSGE {
}
initialiseDeferredFonts();
AccessController.doPrivileged(new PrivilegedAction<Void>() {
public Void run() {
if (fontPath == null) {
fontPath = getPlatformFontPath(noType1Font);
registerFontDirs(fontPath);
}
if (fontPath != null) {
// this will find all fonts including those already
// registered. But we have checks in place to prevent
// double registration.
if (! gotFontsFromPlatform()) {
registerFontsOnPath(fontPath, false,
Font2D.UNKNOWN_RANK,
false, true);
loadedAllFontFiles = true;
}
}
registerOtherFontFiles(registeredFontFiles);
discoveredAllFonts = true;
return null;
if (fontPath == null) {
fontPath = getPlatformFontPath(noType1Font);
registerFontDirs(fontPath);
}
if (fontPath != null) {
// this will find all fonts including those already
// registered. But we have checks in place to prevent
// double registration.
if (! gotFontsFromPlatform()) {
registerFontsOnPath(fontPath, false,
Font2D.UNKNOWN_RANK,
false, true);
loadedAllFontFiles = true;
}
});
}
registerOtherFontFiles(registeredFontFiles);
discoveredAllFonts = true;
}
}
@ -3048,7 +2992,6 @@ public abstract class SunFontManager implements FontSupport, FontManagerForSGE {
return defaultFontName;
}
@SuppressWarnings("removal")
public void loadFontFiles() {
loadFonts();
if (loadedAllFontFiles) {
@ -3060,23 +3003,18 @@ public abstract class SunFontManager implements FontSupport, FontManagerForSGE {
Thread.dumpStack();
FontUtilities.logInfo("loadAllFontFiles() called");
}
AccessController.doPrivileged(new PrivilegedAction<Void>() {
public Void run() {
if (fontPath == null) {
fontPath = getPlatformFontPath(noType1Font);
}
if (fontPath != null) {
// this will find all fonts including those already
// registered. But we have checks in place to prevent
// double registration.
registerFontsOnPath(fontPath, false,
Font2D.UNKNOWN_RANK,
false, true);
}
loadedAllFontFiles = true;
return null;
}
});
if (fontPath == null) {
fontPath = getPlatformFontPath(noType1Font);
}
if (fontPath != null) {
// this will find all fonts including those already
// registered. But we have checks in place to prevent
// double registration.
registerFontsOnPath(fontPath, false,
Font2D.UNKNOWN_RANK,
false, true);
}
loadedAllFontFiles = true;
}
}
@ -3402,16 +3340,9 @@ public abstract class SunFontManager implements FontSupport, FontManagerForSGE {
// Provides an aperture to add native font family names to the map
protected void addNativeFontFamilyNames(TreeMap<String, String> familyNames, Locale requestedLocale) { }
@SuppressWarnings("removal")
public void register1dot0Fonts() {
AccessController.doPrivileged(new PrivilegedAction<Void>() {
public Void run() {
String type1Dir = "/usr/openwin/lib/X11/fonts/Type1";
registerFontsInDir(type1Dir, true, Font2D.TYPE1_RANK,
false, false);
return null;
}
});
String type1Dir = "/usr/openwin/lib/X11/fonts/Type1";
registerFontsInDir(type1Dir, true, Font2D.TYPE1_RANK, false, false);
}
/* Really we need only the JRE fonts family names, but there's little
@ -3442,33 +3373,28 @@ public abstract class SunFontManager implements FontSupport, FontManagerForSGE {
* on windows and uses that if set.
*/
private static Locale systemLocale = null;
@SuppressWarnings("removal")
private static Locale getSystemStartupLocale() {
if (systemLocale == null) {
systemLocale = AccessController.doPrivileged(new PrivilegedAction<Locale>() {
public Locale run() {
/* On windows the system locale may be different than the
* user locale. This is an unsupported configuration, but
* in that case we want to return a dummy locale that will
* never cause a match in the usage of this API. This is
* important because Windows documents that the family
* names of fonts are enumerated using the language of
* the system locale. BY returning a dummy locale in that
* case we do not use the platform API which would not
* return us the names we want.
*/
String fileEncoding = System.getProperty("file.encoding", "");
String sysEncoding = System.getProperty("sun.jnu.encoding");
if (sysEncoding != null && !sysEncoding.equals(fileEncoding)) {
return Locale.ROOT;
}
String language = System.getProperty("user.language", "en");
String country = System.getProperty("user.country","");
String variant = System.getProperty("user.variant","");
return Locale.of(language, country, variant);
}
});
/* On windows the system locale may be different than the
* user locale. This is an unsupported configuration, but
* in that case we want to return a dummy locale that will
* never cause a match in the usage of this API. This is
* important because Windows documents that the family
* names of fonts are enumerated using the language of
* the system locale. BY returning a dummy locale in that
* case we do not use the platform API which would not
* return us the names we want.
*/
String fileEncoding = System.getProperty("file.encoding", "");
String sysEncoding = System.getProperty("sun.jnu.encoding");
if (sysEncoding != null && !sysEncoding.equals(fileEncoding)) {
systemLocale = Locale.ROOT;
} else {
String language = System.getProperty("user.language", "en");
String country = System.getProperty("user.country","");
String variant = System.getProperty("user.variant","");
systemLocale = Locale.of(language, country, variant);
}
}
return systemLocale;
}

View File

@ -37,8 +37,6 @@ import sun.java2d.DisposerRecord;
import java.awt.geom.Point2D;
import java.lang.foreign.MemorySegment;
import java.lang.ref.SoftReference;
import java.security.AccessController;
import java.security.PrivilegedAction;
import java.util.concurrent.ConcurrentHashMap;
import java.util.WeakHashMap;
@ -167,10 +165,7 @@ public final class SunLayoutEngine implements LayoutEngine, LayoutEngineFactory
static boolean useFFM = true;
static {
@SuppressWarnings("removal")
String prop = AccessController.doPrivileged(
(PrivilegedAction<String>) () ->
System.getProperty("sun.font.layout.ffm", "true"));
String prop = System.getProperty("sun.font.layout.ffm", "true");
useFFM = "true".equals(prop);
}

View File

@ -38,9 +38,6 @@ import java.nio.IntBuffer;
import java.nio.ShortBuffer;
import java.nio.channels.ClosedChannelException;
import java.nio.channels.FileChannel;
import java.security.AccessController;
import java.security.PrivilegedActionException;
import java.security.PrivilegedExceptionAction;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Locale;
@ -246,13 +243,7 @@ public class TrueTypeFont extends FileFont {
FontUtilities.logInfo("open TTF: " + platName);
}
try {
@SuppressWarnings("removal")
RandomAccessFile raf = AccessController.doPrivileged(
new PrivilegedExceptionAction<RandomAccessFile>() {
public RandomAccessFile run() throws FileNotFoundException {
return new RandomAccessFile(platName, "r");
}
});
RandomAccessFile raf = new RandomAccessFile(platName, "r");
disposerRecord.channel = raf.getChannel();
fileSize = (int)disposerRecord.channel.size();
if (usePool) {
@ -261,13 +252,6 @@ public class TrueTypeFont extends FileFont {
((SunFontManager) fm).addToPool(this);
}
}
} catch (PrivilegedActionException e) {
close();
Throwable reason = e.getCause();
if (reason == null) {
reason = e;
}
throw new FontFormatException(reason.toString());
} catch (ClosedChannelException e) {
/* NIO I/O is interruptible, recurse to retry operation.
* The call to channel.size() above can throw this exception.
@ -664,7 +648,6 @@ public class TrueTypeFont extends FileFont {
};
private static String defaultCodePage = null;
@SuppressWarnings("removal")
static String getCodePage() {
if (defaultCodePage != null) {
@ -672,8 +655,7 @@ public class TrueTypeFont extends FileFont {
}
if (FontUtilities.isWindows) {
defaultCodePage =
AccessController.doPrivileged(new GetPropertyAction("file.encoding"));
defaultCodePage = System.getProperty("file.encoding");
} else {
if (languages.length != codePages.length) {
throw new InternalError("wrong code pages array length");

View File

@ -83,18 +83,10 @@ public class Type1Font extends FileFont {
fileName = name;
}
@SuppressWarnings("removal")
public synchronized void dispose() {
java.security.AccessController.doPrivileged(
new java.security.PrivilegedAction<Object>() {
public Object run() {
if (fileName != null) {
(new java.io.File(fileName)).delete();
}
return null;
}
});
if (fileName != null) {
(new java.io.File(fileName)).delete();
}
}
}
@ -191,18 +183,11 @@ public class Type1Font extends FileFont {
FontUtilities.logInfo("open Type 1 font: " + platName);
}
try {
@SuppressWarnings("removal")
RandomAccessFile raf = (RandomAccessFile)
java.security.AccessController.doPrivileged(
new java.security.PrivilegedAction<Object>() {
public Object run() {
try {
return new RandomAccessFile(platName, "r");
} catch (FileNotFoundException ffne) {
}
return null;
}
});
RandomAccessFile raf = null;
try {
raf = new RandomAccessFile(platName, "r");
} catch (FileNotFoundException ffne) {
}
FileChannel fc = raf.getChannel();
fileSize = (int)fc.size();
bbuf = ByteBuffer.allocate(fileSize);
@ -227,7 +212,6 @@ public class Type1Font extends FileFont {
}
/* called from native code to read file into a direct byte buffer */
@SuppressWarnings("removal")
void readFile(ByteBuffer buffer) {
RandomAccessFile raf = null;
FileChannel fc;
@ -235,17 +219,10 @@ public class Type1Font extends FileFont {
FontUtilities.logInfo("open Type 1 font: " + platName);
}
try {
raf = (RandomAccessFile)
java.security.AccessController.doPrivileged(
new java.security.PrivilegedAction<Object>() {
public Object run() {
try {
return new RandomAccessFile(platName, "r");
} catch (FileNotFoundException fnfe) {
}
return null;
}
});
try {
raf = new RandomAccessFile(platName, "r");
} catch (FileNotFoundException fnfe) {
}
fc = raf.getChannel();
while (buffer.remaining() > 0 && fc.read(buffer) != -1) {}
} catch (ClosedChannelException e) {