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; package sun.awt;
import java.awt.AWTEvent; import java.awt.AWTEvent;
import java.security.AccessController;
import java.security.PrivilegedAction;
import java.util.HashSet; import java.util.HashSet;
import java.util.IdentityHashMap; import java.util.IdentityHashMap;
import java.util.Map; 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 * Creates and starts a new blocker thread. Doesn't return until
* the new blocker thread starts. * the new blocker thread starts.
*/ */
@SuppressWarnings("removal")
private void activateBlockerThread() { private void activateBlockerThread() {
AccessController.doPrivileged((PrivilegedAction<Thread>) () -> { String name = "AWT-Shutdown";
String name = "AWT-Shutdown"; Thread thread = new Thread(ThreadGroupUtils.getRootThreadGroup(), this, name, 0, false);
Thread thread = new Thread( thread.setContextClassLoader(null);
ThreadGroupUtils.getRootThreadGroup(), this, name, 0, false); thread.setDaemon(false);
thread.setContextClassLoader(null); blockerThread = thread;
thread.setDaemon(false); thread.start();
blockerThread = thread;
return thread;
}).start();
try { try {
/* Wait for the blocker thread to start. */ /* Wait for the blocker thread to start. */
mainLock.wait(); mainLock.wait();

View File

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

View File

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

View File

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

View File

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

View File

@ -120,10 +120,7 @@ public class FontDescriptor implements Cloneable {
} }
static boolean isLE; static boolean isLE;
static { static {
@SuppressWarnings("removal") String enc = System.getProperty("sun.io.unicode.encoding", "UnicodeBig");
String enc = java.security.AccessController.doPrivileged(
new sun.security.action.GetPropertyAction("sun.io.unicode.encoding",
"UnicodeBig"));
isLE = !"UnicodeBig".equals(enc); 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 * For now, we know it's done by the implementation, and we assume
* that the name of the library is "awt". -br. * that the name of the library is "awt". -br.
*/ */
@SuppressWarnings({"removal", "restricted"}) @SuppressWarnings("restricted")
static void loadLibraries() { static void loadLibraries() {
java.security.AccessController.doPrivileged( System.loadLibrary("awt");
new java.security.PrivilegedAction<Void>() {
public Void run() {
System.loadLibrary("awt");
return null;
}
});
} }
} }

View File

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

View File

@ -38,8 +38,6 @@ import java.io.ObjectStreamClass;
import java.io.OutputStream; import java.io.OutputStream;
import java.lang.reflect.Modifier; import java.lang.reflect.Modifier;
import java.lang.reflect.Proxy; import java.lang.reflect.Proxy;
import java.security.AccessController;
import java.security.PrivilegedAction;
import java.util.HashMap; import java.util.HashMap;
import java.util.HashSet; import java.util.HashSet;
import java.util.Map; import java.util.Map;
@ -111,28 +109,14 @@ final class ClassLoaderObjectOutputStream extends ObjectOutputStream {
} }
protected void annotateClass(final Class<?> cl) throws IOException { protected void annotateClass(final Class<?> cl) throws IOException {
@SuppressWarnings("removal") ClassLoader classLoader = cl.getClassLoader();
ClassLoader classLoader = AccessController.doPrivileged(
new PrivilegedAction<ClassLoader>() {
public ClassLoader run() {
return cl.getClassLoader();
}
});
Set<String> s = new HashSet<String>(1); Set<String> s = new HashSet<String>(1);
s.add(cl.getName()); s.add(cl.getName());
map.put(s, classLoader); map.put(s, classLoader);
} }
protected void annotateProxyClass(final Class<?> cl) throws IOException { protected void annotateProxyClass(final Class<?> cl) throws IOException {
@SuppressWarnings("removal") ClassLoader classLoader = cl.getClassLoader();
ClassLoader classLoader = AccessController.doPrivileged(
new PrivilegedAction<ClassLoader>() {
public ClassLoader run() {
return cl.getClassLoader();
}
});
Class<?>[] interfaces = cl.getInterfaces(); Class<?>[] interfaces = cl.getInterfaces();
Set<String> s = new HashSet<String>(interfaces.length); Set<String> s = new HashSet<String>(interfaces.length);
for (int i = 0; i < interfaces.length; i++) { 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.event.InvocationEvent;
import java.awt.im.spi.InputMethodDescriptor; import java.awt.im.spi.InputMethodDescriptor;
import java.lang.reflect.InvocationTargetException; 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.Hashtable;
import java.util.Iterator; import java.util.Iterator;
import java.util.Locale; import java.util.Locale;
@ -252,24 +248,14 @@ class ExecutableInputMethodManager extends InputMethodManager
* initializes the input method locator list for all * initializes the input method locator list for all
* installed input method descriptors. * installed input method descriptors.
*/ */
@SuppressWarnings("removal")
private void initializeInputMethodLocatorList() { private void initializeInputMethodLocatorList() {
synchronized (javaInputMethodLocatorList) { synchronized (javaInputMethodLocatorList) {
javaInputMethodLocatorList.clear(); javaInputMethodLocatorList.clear();
try { for (InputMethodDescriptor descriptor :
AccessController.doPrivileged(new PrivilegedExceptionAction<Object>() { ServiceLoader.load(InputMethodDescriptor.class,
public Object run() { ClassLoader.getSystemClassLoader())) {
for (InputMethodDescriptor descriptor : ClassLoader cl = descriptor.getClass().getClassLoader();
ServiceLoader.load(InputMethodDescriptor.class, javaInputMethodLocatorList.add(new InputMethodLocator(descriptor, cl, null));
ClassLoader.getSystemClassLoader())) {
ClassLoader cl = descriptor.getClass().getClassLoader();
javaInputMethodLocatorList.add(new InputMethodLocator(descriptor, cl, null));
}
return null;
}
});
} catch (PrivilegedActionException e) {
e.printStackTrace();
} }
javaInputMethodCount = javaInputMethodLocatorList.size(); javaInputMethodCount = javaInputMethodLocatorList.size();
} }
@ -594,13 +580,8 @@ class ExecutableInputMethodManager extends InputMethodManager
} }
} }
@SuppressWarnings("removal")
private Preferences getUserRoot() { private Preferences getUserRoot() {
return AccessController.doPrivileged(new PrivilegedAction<Preferences>() { return Preferences.userRoot();
public Preferences run() {
return Preferences.userRoot();
}
});
} }
private Locale getAdvertisedLocale(InputMethodLocator locator, Locale locale) { 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.InputMethodRequests;
import java.awt.im.spi.InputMethod; import java.awt.im.spi.InputMethod;
import java.lang.Character.Subset; import java.lang.Character.Subset;
import java.security.AccessController;
import java.security.PrivilegedAction;
import java.text.MessageFormat; import java.text.MessageFormat;
import java.util.Collection; import java.util.Collection;
import java.util.HashMap; 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 * Initializes the input method selection key definition in preference trees
*/ */
@SuppressWarnings("removal")
private void initializeInputMethodSelectionKey() { private void initializeInputMethodSelectionKey() {
AccessController.doPrivileged(new PrivilegedAction<Object>() { // Look in user's tree
public Object run() { Preferences root = Preferences.userRoot();
// Look in user's tree inputMethodSelectionKey = getInputMethodSelectionKeyStroke(root);
Preferences root = Preferences.userRoot();
inputMethodSelectionKey = getInputMethodSelectionKeyStroke(root);
if (inputMethodSelectionKey == null) { if (inputMethodSelectionKey == null) {
// Look in system's tree // Look in system's tree
root = Preferences.systemRoot(); root = Preferences.systemRoot();
inputMethodSelectionKey = getInputMethodSelectionKeyStroke(root); inputMethodSelectionKey = getInputMethodSelectionKeyStroke(root);
} }
return null;
}
});
} }
private AWTKeyStroke getInputMethodSelectionKeyStroke(Preferences 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.font.TextHitInfo;
import java.awt.im.InputMethodRequests; import java.awt.im.InputMethodRequests;
import java.awt.im.spi.InputMethod; import java.awt.im.spi.InputMethod;
import java.security.AccessController;
import java.text.AttributedCharacterIterator; import java.text.AttributedCharacterIterator;
import java.text.AttributedCharacterIterator.Attribute; import java.text.AttributedCharacterIterator.Attribute;
import java.text.AttributedString; import java.text.AttributedString;
@ -72,9 +71,7 @@ public class InputMethodContext
static { static {
// check whether we should use below-the-spot input // check whether we should use below-the-spot input
// get property from command line // get property from command line
@SuppressWarnings("removal") String inputStyle = System.getProperty("java.awt.im.style");
String inputStyle = AccessController.doPrivileged
(new GetPropertyAction("java.awt.im.style", null));
// get property from awt.properties file // get property from awt.properties file
if (inputStyle == null) { if (inputStyle == null) {
inputStyle = Toolkit.getProperty("java.awt.im.style", 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.File;
import java.io.OutputStream; import java.io.OutputStream;
import java.security.AccessController;
import java.security.PrivilegedAction;
import java.util.HashMap; import java.util.HashMap;
import java.util.Map; import java.util.Map;
import java.util.concurrent.Semaphore; import java.util.concurrent.Semaphore;
@ -112,25 +110,21 @@ public class CreatedFontTracker {
private static HashMap<File, OutputStream> files = new HashMap<>(); private static HashMap<File, OutputStream> files = new HashMap<>();
private static Thread t = null; private static Thread t = null;
@SuppressWarnings("removal")
static void init() { static void init() {
if (t == null) { if (t == null) {
// Add a shutdown hook to remove the temp file. // Add a shutdown hook to remove the temp file.
AccessController.doPrivileged((PrivilegedAction<Void>) () -> { /* The thread must be a member of a thread group
/* The thread must be a member of a thread group * which will not get GCed before VM exit.
* which will not get GCed before VM exit. * Make its parent the top-level thread group.
* Make its parent the top-level thread group. */
*/ ThreadGroup rootTG = ThreadGroupUtils.getRootThreadGroup();
ThreadGroup rootTG = ThreadGroupUtils.getRootThreadGroup(); t = new Thread(rootTG, TempFileDeletionHook::runHooks,
t = new Thread(rootTG, TempFileDeletionHook::runHooks, "TempFontFileDeleter", 0, false);
"TempFontFileDeleter", 0, false); /* Set context class loader to null in order to avoid
/* Set context class loader to null in order to avoid * keeping a strong reference to an application classloader.
* keeping a strong reference to an application classloader. */
*/ t.setContextClassLoader(null);
t.setContextClassLoader(null); Runtime.getRuntime().addShutdownHook(t);
Runtime.getRuntime().addShutdownHook(t);
return null;
});
} }
} }

View File

@ -35,11 +35,7 @@ import java.nio.ByteBuffer;
import sun.java2d.Disposer; import sun.java2d.Disposer;
import sun.java2d.DisposerRecord; import sun.java2d.DisposerRecord;
import java.io.IOException;
import java.util.List; import java.util.List;
import java.security.AccessController;
import java.security.PrivilegedActionException;
import java.security.PrivilegedExceptionAction;
public abstract class FileFont extends PhysicalFont { public abstract class FileFont extends PhysicalFont {
@ -252,84 +248,35 @@ public abstract class FileFont extends PhysicalFont {
this.tracker = tracker; this.tracker = tracker;
} }
@SuppressWarnings("removal")
public void dispose() { public void dispose() {
java.security.AccessController.doPrivileged( synchronized (fontFile) {
new java.security.PrivilegedAction<Object>() { count--;
public Object run() { if (count > 0) {
synchronized (fontFile) { return;
count--; }
if (count > 0) { }
return null; if (fontFile != null) {
} try {
} if (tracker != null) {
if (fontFile != null) { tracker.subBytes((int)fontFile.length());
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;
} }
}); /* 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() { protected String getPublicFileName() {
SecurityManager sm = System.getSecurityManager();
if (sm == null) {
return platName; 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; import sun.awt.OSInfo;
@SuppressWarnings({"removal", "restricted"}) @SuppressWarnings("restricted")
public class FontManagerNativeLibrary { public class FontManagerNativeLibrary {
static { static {
java.security.AccessController.doPrivileged( /* REMIND do we really have to load awt here? */
new java.security.PrivilegedAction<Object>() { System.loadLibrary("awt");
public Object run() { if (OSInfo.getOSType() == OSInfo.OSType.WINDOWS) {
/* REMIND do we really have to load awt here? */ /* Ideally fontmanager library should not depend on
System.loadLibrary("awt"); particular implementation of the font scaler.
if (OSInfo.getOSType() == OSInfo.OSType.WINDOWS) { However, freetype scaler is basically small wrapper on
/* Ideally fontmanager library should not depend on top of freetype library (that is used in binary form).
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 This wrapper is compiled into fontmanager and this make
fontmanger library depending on freetype library. fontmanger library depending on freetype library.
On Windows DLL's in the JRE's BIN directory cannot be On Windows DLL's in the JRE's BIN directory cannot be
found by windows DLL loading as that directory is not found by windows DLL loading as that directory is not
on the Windows PATH. on the Windows PATH.
To avoid link error we have to load freetype explicitly To avoid link error we have to load freetype explicitly
before we load fontmanager. before we load fontmanager.
NB: consider moving freetype wrapper part to separate NB: consider moving freetype wrapper part to separate
shared library in order to avoid dependency. */ shared library in order to avoid dependency. */
System.loadLibrary("freetype"); System.loadLibrary("freetype");
} }
System.loadLibrary("fontmanager"); System.loadLibrary("fontmanager");
return null;
}
});
} }
/* /*

View File

@ -28,9 +28,7 @@ package sun.font;
import java.awt.Font; import java.awt.Font;
import java.lang.ref.SoftReference; import java.lang.ref.SoftReference;
import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.ConcurrentHashMap;
import java.security.AccessController;
import java.security.PrivilegedAction;
import javax.swing.plaf.FontUIResource; import javax.swing.plaf.FontUIResource;
import sun.awt.OSInfo; import sun.awt.OSInfo;
@ -59,65 +57,57 @@ public final class FontUtilities {
initStatic(); initStatic();
} }
@SuppressWarnings("removal") @SuppressWarnings("deprecation") // PlatformLogger.setLevel is deprecated.
private static void initStatic() { 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; isMacOSX = OSInfo.getOSType() == OSInfo.OSType.MACOSX;
if (isMacOSX) { if (isMacOSX) {
// os.version has values like 10.13.6, 10.14.6 // os.version has values like 10.13.6, 10.14.6
// If it is not positively recognised as 10.13 or less, // If it is not positively recognised as 10.13 or less,
// assume it means 10.14 or some later version. // assume it means 10.14 or some later version.
isMacOSX14 = true; isMacOSX14 = true;
String version = System.getProperty("os.version", ""); String version = System.getProperty("os.version", "");
if (version.startsWith("10.")) { if (version.startsWith("10.")) {
version = version.substring(3); version = version.substring(3);
int periodIndex = version.indexOf('.'); int periodIndex = version.indexOf('.');
if (periodIndex != -1) { if (periodIndex != -1) {
version = version.substring(0, periodIndex); 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;
} }
isWindows = OSInfo.getOSType() == OSInfo.OSType.WINDOWS; try {
String debugLevel = int v = Integer.parseInt(version);
System.getProperty("sun.java2d.debugfonts"); isMacOSX14 = (v >= 14);
} catch (NumberFormatException e) {
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();
} }
}
}
/* 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(); initStatic();
} }
@SuppressWarnings("removal")
private static void initStatic() { private static void initStatic() {
if (nativeAddressSize < 4) { if (nativeAddressSize < 4) {
@ -271,37 +270,28 @@ public final class StrikeCache {
nativeAddressSize); nativeAddressSize);
} }
java.security.AccessController.doPrivileged( /* Allow a client to override the reference type used to
new java.security.PrivilegedAction<Object>() { * cache strikes. The default is "soft" which hints to keep
public Object run() { * 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 String minStrikesStr =
* cache strikes. The default is "soft" which hints to keep System.getProperty("sun.java2d.font.minstrikes");
* the strikes around. This property allows the client to if (minStrikesStr != null) {
* override this to "weak" which hint to the GC to free try {
* memory more aggressively. MINSTRIKES = Integer.parseInt(minStrikesStr);
*/ if (MINSTRIKES <= 0) {
String refType = MINSTRIKES = 1;
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) {
}
} }
} catch (NumberFormatException e) {
recentStrikes = new FontStrike[MINSTRIKES];
return null;
} }
}); }
recentStrikes = new FontStrike[MINSTRIKES];
} }

View File

@ -33,8 +33,6 @@ import java.io.FileInputStream;
import java.io.FilenameFilter; import java.io.FilenameFilter;
import java.io.IOException; import java.io.IOException;
import java.io.InputStreamReader; import java.io.InputStreamReader;
import java.security.AccessController;
import java.security.PrivilegedAction;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.HashMap; import java.util.HashMap;
import java.util.HashSet; import java.util.HashSet;
@ -262,30 +260,24 @@ public abstract class SunFontManager implements FontSupport, FontManagerForSGE {
initStatic(); initStatic();
} }
@SuppressWarnings("removal")
private static void initStatic() { private static void initStatic() {
AccessController.doPrivileged(new PrivilegedAction<Void>() { FontManagerNativeLibrary.load();
public Void run() {
FontManagerNativeLibrary.load();
// JNI throws an exception if a class/method/field is not found, // JNI throws an exception if a class/method/field is not found,
// so there's no need to do anything explicit here. // so there's no need to do anything explicit here.
initIDs(); initIDs();
switch (StrikeCache.nativeAddressSize) { switch (StrikeCache.nativeAddressSize) {
case 8: longAddresses = true; break; case 8: longAddresses = true; break;
case 4: longAddresses = false; break; case 4: longAddresses = false; break;
default: throw new RuntimeException("Unexpected address size"); default: throw new RuntimeException("Unexpected address size");
} }
noType1Font = "true".equals(System.getProperty("sun.java2d.noType1Font")); noType1Font = "true".equals(System.getProperty("sun.java2d.noType1Font"));
jreLibDirName = System.getProperty("java.home","") + File.separator + "lib"; jreLibDirName = System.getProperty("java.home","") + File.separator + "lib";
jreFontDirName = jreLibDirName + File.separator + "fonts"; jreFontDirName = jreLibDirName + File.separator + "fonts";
maxSoftRefCnt = Integer.getInteger("sun.java2d.font.maxSoftRefs", 10); maxSoftRefCnt = Integer.getInteger("sun.java2d.font.maxSoftRefs", 10);
return null;
}
});
} }
/** /**
@ -304,150 +296,142 @@ public abstract class SunFontManager implements FontSupport, FontManagerForSGE {
/* Initialise ptrs used by JNI methods */ /* Initialise ptrs used by JNI methods */
private static native void initIDs(); private static native void initIDs();
@SuppressWarnings("removal")
protected SunFontManager() { protected SunFontManager() {
AccessController.doPrivileged(new PrivilegedAction<Void>() { File badFontFile =
public Void run() { new File(jreFontDirName + File.separator + "badfonts.txt");
File badFontFile = if (badFontFile.exists()) {
new File(jreFontDirName + File.separator + "badfonts.txt"); badFonts = new ArrayList<>();
if (badFontFile.exists()) { try (FileInputStream fis = new FileInputStream(badFontFile);
badFonts = new ArrayList<>(); BufferedReader br = new BufferedReader(new InputStreamReader(fis))) {
try (FileInputStream fis = new FileInputStream(badFontFile); while (true) {
BufferedReader br = new BufferedReader(new InputStreamReader(fis))) { String name = br.readLine();
while (true) { if (name == null) {
String name = br.readLine(); break;
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;
} else { } 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);
} }
} catch (IOException e) {
initCompositeFonts(fontConfig, null);
return null;
} }
}); }
/* 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, public Font2DHandle getNewComposite(String family, int style,
@ -1095,7 +1079,6 @@ public abstract class SunFontManager implements FontSupport, FontManagerForSGE {
private boolean haveCheckedUnreferencedFontFiles; private boolean haveCheckedUnreferencedFontFiles;
@SuppressWarnings("removal")
private String[] getFontFilesFromPath(boolean noType1) { private String[] getFontFilesFromPath(boolean noType1) {
final FilenameFilter filter; final FilenameFilter filter;
if (noType1) { if (noType1) {
@ -1103,34 +1086,30 @@ public abstract class SunFontManager implements FontSupport, FontManagerForSGE {
} else { } else {
filter = new TTorT1Filter(); filter = new TTorT1Filter();
} }
return AccessController.doPrivileged(new PrivilegedAction<String[]>() { if (pathDirs.length == 1) {
public String[] run() { File dir = new File(pathDirs[0]);
if (pathDirs.length == 1) { String[] files = dir.list(filter);
File dir = new File(pathDirs[0]); if (files == null) {
String[] files = dir.list(filter); return new String[0];
if (files == null) { }
return new String[0]; for (int f=0; f<files.length; f++) {
} files[f] = files[f].toLowerCase();
for (int f=0; f<files.length; f++) { }
files[f] = files[f].toLowerCase(); return files;
} } else {
return files; ArrayList<String> fileList = new ArrayList<>();
} else { for (int i = 0; i< pathDirs.length; i++) {
ArrayList<String> fileList = new ArrayList<>(); File dir = new File(pathDirs[i]);
for (int i = 0; i< pathDirs.length; i++) { String[] files = dir.list(filter);
File dir = new File(pathDirs[i]); if (files == null) {
String[] files = dir.list(filter); continue;
if (files == null) { }
continue; for (int f = 0; f < files.length ; f++) {
} fileList.add(files[f].toLowerCase());
for (int f = 0; f < files.length ; f++) {
fileList.add(files[f].toLowerCase());
}
}
return fileList.toArray(STR_ARRAY);
} }
} }
}); return fileList.toArray(STR_ARRAY);
}
} }
/* This is needed since some windows registry names don't match /* 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); return new HashMap<>(0);
} }
@SuppressWarnings("removal")
Font2D findFontFromPlatformMap(String lcName, int style) { Font2D findFontFromPlatformMap(String lcName, int style) {
HashMap<String, FamilyDescription> platformFontMap = SunFontManager.platformFontMap; HashMap<String, FamilyDescription> platformFontMap = SunFontManager.platformFontMap;
if (platformFontMap == null) { if (platformFontMap == null) {
@ -1524,20 +1502,16 @@ public abstract class SunFontManager implements FontSupport, FontManagerForSGE {
final String[] files = { final String[] files = {
plainFile, boldFile, italicFile, boldItalicFile } ; plainFile, boldFile, italicFile, boldItalicFile } ;
failure = AccessController.doPrivileged(new PrivilegedAction<Boolean>() { for (int i=0; i<files.length; i++) {
public Boolean run() { if (files[i] == null) {
for (int i=0; i<files.length; i++) { continue;
if (files[i] == null) {
continue;
}
File f = new File(files[i]);
if (!f.exists()) {
return Boolean.TRUE;
}
}
return Boolean.FALSE;
} }
}); File f = new File(files[i]);
if (!f.exists()) {
failure = true;
break;
}
}
if (failure) { if (failure) {
if (FontUtilities.isLogging()) { if (FontUtilities.isLogging()) {
@ -1724,21 +1698,11 @@ public abstract class SunFontManager implements FontSupport, FontManagerForSGE {
} else if (pathDirs.length==1) { } else if (pathDirs.length==1) {
return pathDirs[0] + File.separator + s; return pathDirs[0] + File.separator + s;
} else { } else {
@SuppressWarnings("removal") for (int p = 0; p < pathDirs.length; p++) {
String path = AccessController.doPrivileged( f = new File(pathDirs[p] + File.separator + s);
new PrivilegedAction<String>() { if (f.exists()) {
public String run() { return f.getAbsolutePath();
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;
} }
} }
return s; // shouldn't happen, but harmless return s; // shouldn't happen, but harmless
@ -2181,7 +2145,6 @@ public abstract class SunFontManager implements FontSupport, FontManagerForSGE {
private int createdFontCount = 0; private int createdFontCount = 0;
@SuppressWarnings("removal")
public Font2D[] createFont2D(File fontFile, int fontFormat, boolean all, public Font2D[] createFont2D(File fontFile, int fontFormat, boolean all,
boolean isCopy, CreatedFontTracker tracker) boolean isCopy, CreatedFontTracker tracker)
throws FontFormatException { throws FontFormatException {
@ -2229,15 +2192,10 @@ public abstract class SunFontManager implements FontSupport, FontManagerForSGE {
} }
} catch (FontFormatException e) { } catch (FontFormatException e) {
if (isCopy) { if (isCopy) {
AccessController.doPrivileged(new PrivilegedAction<Void>() { if (_tracker != null) {
public Void run() { _tracker.subBytes((int)fFile.length());
if (_tracker != null) { }
_tracker.subBytes((int)fFile.length()); fFile.delete();
}
fFile.delete();
return null;
}
});
} }
throw(e); throw(e);
} }
@ -2253,39 +2211,31 @@ public abstract class SunFontManager implements FontSupport, FontManagerForSGE {
if (fileCloser == null) { if (fileCloser == null) {
final Runnable fileCloserRunnable = new Runnable() { final Runnable fileCloserRunnable = new Runnable() {
public void run() { public void run() {
AccessController.doPrivileged(new PrivilegedAction<Void>() { for (int i = 0;i < CHANNELPOOLSIZE; i++) {
public Void run() { if (fontFileCache[i] != null) {
for (int i = 0;i < CHANNELPOOLSIZE; i++) { try {
if (fontFileCache[i] != null) { fontFileCache[i].close();
try { } catch (Exception e) {
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();
ThreadGroup rootTG = ThreadGroupUtils.getRootThreadGroup(); fileCloser = new Thread(rootTG, fileCloserRunnable,
fileCloser = new Thread(rootTG, fileCloserRunnable, "FileCloser", 0, false);
"FileCloser", 0, false); fileCloser.setContextClassLoader(null);
fileCloser.setContextClassLoader(null); Runtime.getRuntime().addShutdownHook(fileCloser);
Runtime.getRuntime().addShutdownHook(fileCloser);
return null;
});
} }
} }
} }
@ -2930,7 +2880,6 @@ public abstract class SunFontManager implements FontSupport, FontManagerForSGE {
return fontPath; return fontPath;
} }
@SuppressWarnings("removal")
protected void loadFonts() { protected void loadFonts() {
if (discoveredAllFonts) { if (discoveredAllFonts) {
return; return;
@ -2943,28 +2892,23 @@ public abstract class SunFontManager implements FontSupport, FontManagerForSGE {
} }
initialiseDeferredFonts(); initialiseDeferredFonts();
AccessController.doPrivileged(new PrivilegedAction<Void>() { if (fontPath == null) {
public Void run() { fontPath = getPlatformFontPath(noType1Font);
if (fontPath == null) { registerFontDirs(fontPath);
fontPath = getPlatformFontPath(noType1Font); }
registerFontDirs(fontPath); if (fontPath != null) {
} // this will find all fonts including those already
if (fontPath != null) { // registered. But we have checks in place to prevent
// this will find all fonts including those already // double registration.
// registered. But we have checks in place to prevent if (! gotFontsFromPlatform()) {
// double registration. registerFontsOnPath(fontPath, false,
if (! gotFontsFromPlatform()) { Font2D.UNKNOWN_RANK,
registerFontsOnPath(fontPath, false, false, true);
Font2D.UNKNOWN_RANK, loadedAllFontFiles = true;
false, true);
loadedAllFontFiles = true;
}
}
registerOtherFontFiles(registeredFontFiles);
discoveredAllFonts = true;
return null;
} }
}); }
registerOtherFontFiles(registeredFontFiles);
discoveredAllFonts = true;
} }
} }
@ -3048,7 +2992,6 @@ public abstract class SunFontManager implements FontSupport, FontManagerForSGE {
return defaultFontName; return defaultFontName;
} }
@SuppressWarnings("removal")
public void loadFontFiles() { public void loadFontFiles() {
loadFonts(); loadFonts();
if (loadedAllFontFiles) { if (loadedAllFontFiles) {
@ -3060,23 +3003,18 @@ public abstract class SunFontManager implements FontSupport, FontManagerForSGE {
Thread.dumpStack(); Thread.dumpStack();
FontUtilities.logInfo("loadAllFontFiles() called"); FontUtilities.logInfo("loadAllFontFiles() called");
} }
AccessController.doPrivileged(new PrivilegedAction<Void>() { if (fontPath == null) {
public Void run() { fontPath = getPlatformFontPath(noType1Font);
if (fontPath == null) { }
fontPath = getPlatformFontPath(noType1Font); if (fontPath != null) {
} // this will find all fonts including those already
if (fontPath != null) { // registered. But we have checks in place to prevent
// this will find all fonts including those already // double registration.
// registered. But we have checks in place to prevent registerFontsOnPath(fontPath, false,
// double registration. Font2D.UNKNOWN_RANK,
registerFontsOnPath(fontPath, false, false, true);
Font2D.UNKNOWN_RANK, }
false, true); loadedAllFontFiles = true;
}
loadedAllFontFiles = true;
return null;
}
});
} }
} }
@ -3402,16 +3340,9 @@ public abstract class SunFontManager implements FontSupport, FontManagerForSGE {
// Provides an aperture to add native font family names to the map // Provides an aperture to add native font family names to the map
protected void addNativeFontFamilyNames(TreeMap<String, String> familyNames, Locale requestedLocale) { } protected void addNativeFontFamilyNames(TreeMap<String, String> familyNames, Locale requestedLocale) { }
@SuppressWarnings("removal")
public void register1dot0Fonts() { public void register1dot0Fonts() {
AccessController.doPrivileged(new PrivilegedAction<Void>() { String type1Dir = "/usr/openwin/lib/X11/fonts/Type1";
public Void run() { registerFontsInDir(type1Dir, true, Font2D.TYPE1_RANK, false, false);
String type1Dir = "/usr/openwin/lib/X11/fonts/Type1";
registerFontsInDir(type1Dir, true, Font2D.TYPE1_RANK,
false, false);
return null;
}
});
} }
/* Really we need only the JRE fonts family names, but there's little /* 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. * on windows and uses that if set.
*/ */
private static Locale systemLocale = null; private static Locale systemLocale = null;
@SuppressWarnings("removal")
private static Locale getSystemStartupLocale() { private static Locale getSystemStartupLocale() {
if (systemLocale == null) { if (systemLocale == null) {
systemLocale = AccessController.doPrivileged(new PrivilegedAction<Locale>() { /* On windows the system locale may be different than the
public Locale run() { * user locale. This is an unsupported configuration, but
/* On windows the system locale may be different than the * in that case we want to return a dummy locale that will
* user locale. This is an unsupported configuration, but * never cause a match in the usage of this API. This is
* in that case we want to return a dummy locale that will * important because Windows documents that the family
* never cause a match in the usage of this API. This is * names of fonts are enumerated using the language of
* important because Windows documents that the family * the system locale. BY returning a dummy locale in that
* names of fonts are enumerated using the language of * case we do not use the platform API which would not
* the system locale. BY returning a dummy locale in that * return us the names we want.
* 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");
String fileEncoding = System.getProperty("file.encoding", ""); if (sysEncoding != null && !sysEncoding.equals(fileEncoding)) {
String sysEncoding = System.getProperty("sun.jnu.encoding"); systemLocale = Locale.ROOT;
if (sysEncoding != null && !sysEncoding.equals(fileEncoding)) { } else {
return Locale.ROOT; String language = System.getProperty("user.language", "en");
} String country = System.getProperty("user.country","");
String variant = System.getProperty("user.variant","");
String language = System.getProperty("user.language", "en"); systemLocale = Locale.of(language, country, variant);
String country = System.getProperty("user.country",""); }
String variant = System.getProperty("user.variant","");
return Locale.of(language, country, variant);
}
});
} }
return systemLocale; return systemLocale;
} }

View File

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

View File

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

View File

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