mirror of
https://github.com/openjdk/jdk.git
synced 2025-09-21 19:44:41 +02:00
6958221: java.awt.Font.getFamily() leads to JVM crash on Linux on JDK7 for "custom" fonts
Reviewed-by: igor, jgodinez
This commit is contained in:
parent
ef05d0b18a
commit
efefa14038
8 changed files with 58 additions and 100 deletions
|
@ -515,8 +515,7 @@ SUNWprivate_1.1 {
|
|||
getDefaultConfig;
|
||||
Java_sun_font_FontConfigManager_getFontConfig;
|
||||
Java_sun_font_FontConfigManager_getFontConfigAASettings;
|
||||
Java_sun_awt_X11FontManager_getFontPath;
|
||||
Java_sun_awt_X11FontManager_setNativeFontPath;
|
||||
Java_sun_awt_X11FontManager_getFontPathNative;
|
||||
Java_sun_font_SunFontManager_populateFontFileNameMap;
|
||||
|
||||
# CDE private entry point
|
||||
|
|
|
@ -537,8 +537,7 @@ SUNWprivate_1.1 {
|
|||
getDefaultConfig;
|
||||
Java_sun_font_FontConfigManager_getFontConfig;
|
||||
Java_sun_font_FontConfigManager_getFontConfigAASettings;
|
||||
Java_sun_awt_X11FontManager_getFontPath;
|
||||
Java_sun_awt_X11FontManager_setNativeFontPath;
|
||||
Java_sun_awt_X11FontManager_getFontPathNative;
|
||||
Java_sun_font_SunFontManager_populateFontFileNameMap;
|
||||
|
||||
# CDE private entry point
|
||||
|
|
|
@ -65,7 +65,6 @@ SUNWprivate_1.1 {
|
|||
Java_sun_font_FontConfigManager_getFontConfig;
|
||||
Java_sun_font_FontConfigManager_getFontConfigAASettings;
|
||||
Java_sun_font_FontConfigManager_getFontConfigVersion;
|
||||
Java_sun_awt_X11FontManager_getFontPath;
|
||||
|
||||
Java_sun_awt_FontDescriptor_initIDs;
|
||||
Java_sun_awt_PlatformFont_initIDs;
|
||||
|
|
|
@ -188,8 +188,7 @@ SUNWprivate_1.1 {
|
|||
Java_sun_font_FontConfigManager_getFontConfig;
|
||||
Java_sun_font_FontConfigManager_getFontConfigAASettings;
|
||||
Java_sun_font_FontConfigManager_getFontConfigVersion;
|
||||
Java_sun_awt_X11FontManager_getFontPath;
|
||||
Java_sun_font_X11FontManager_setNativeFontPath;
|
||||
Java_sun_awt_X11FontManager_getFontPathNative;
|
||||
Java_sun_awt_X11GraphicsEnvironment_initDisplay;
|
||||
Java_sun_awt_X11GraphicsEnvironment_initGLX;
|
||||
Java_sun_awt_X11GraphicsEnvironment_initXRender;
|
||||
|
|
|
@ -718,25 +718,6 @@ public class X11FontManager extends SunFontManager {
|
|||
fontdirs = (String[])fontConfigDirs.toArray(new String[0]);
|
||||
}
|
||||
|
||||
/* Called by MToolkit to set the X11 font path */
|
||||
public static void setNativeFontPath() {
|
||||
if (fontdirs == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
// need to register these individually rather than by one call
|
||||
// to ensure that one bad directory doesn't cause all to be rejected
|
||||
for (int i=0; i<fontdirs.length; i++) {
|
||||
if (FontUtilities.debugFonts()) {
|
||||
FontUtilities.getLogger().info("Add " + fontdirs[i] + " to X11 fontpath");
|
||||
}
|
||||
setNativeFontPath(fontdirs[i]);
|
||||
}
|
||||
}
|
||||
|
||||
private synchronized static native void setNativeFontPath(String fontPath);
|
||||
|
||||
|
||||
// Implements SunGraphicsEnvironment.createFontConfiguration.
|
||||
protected FontConfiguration createFontConfiguration() {
|
||||
/* The logic here decides whether to use a preconfigured
|
||||
|
@ -780,7 +761,12 @@ public class X11FontManager extends SunFontManager {
|
|||
preferLocaleFonts, preferPropFonts);
|
||||
}
|
||||
|
||||
public synchronized native String getFontPath(boolean noType1Fonts);
|
||||
public synchronized native String getFontPathNative(boolean noType1Fonts);
|
||||
|
||||
public synchronized String getFontPath(boolean noType1Fonts) {
|
||||
isHeadless(); // make sure GE is inited, as its the X11 lock.
|
||||
return getFontPathNative(noType1Fonts);
|
||||
}
|
||||
|
||||
public String[] getDefaultPlatformFont() {
|
||||
if (defaultPlatformFont != null) {
|
||||
|
|
|
@ -120,13 +120,6 @@ public class MToolkit extends UNIXToolkit implements Runnable {
|
|||
getDefaultConfiguration());
|
||||
}
|
||||
|
||||
/* Add font properties font directories to the X11 font path.
|
||||
* Its called here *after* the X connection has been initialised
|
||||
* and when we know that MToolkit is the one that will be used,
|
||||
* since XToolkit doesn't need the X11 font path set
|
||||
*/
|
||||
X11FontManager.getInstance().setNativeFontPath();
|
||||
|
||||
motifdnd = ((Boolean)java.security.AccessController.doPrivileged(
|
||||
new GetBooleanAction("awt.dnd.motifdnd"))).booleanValue();
|
||||
}
|
||||
|
|
|
@ -502,6 +502,13 @@ static char *getPlatformFontPathChars(JNIEnv *env, jboolean noType1) {
|
|||
#ifdef __linux__ /* There's no headless build on linux ... */
|
||||
if (!AWTIsHeadless()) { /* .. so need to call a function to check */
|
||||
#endif
|
||||
/* Using the X11 font path to locate font files is now a fallback
|
||||
* useful only if fontconfig failed, or is incomplete. So we could
|
||||
* remove this code completely and the consequences should be rare
|
||||
* and non-fatal. If this happens, then the calling Java code can
|
||||
* be modified to no longer require that the AWT lock (the X11GE)
|
||||
* be initialised prior to calling this code.
|
||||
*/
|
||||
AWT_LOCK();
|
||||
if (isDisplayLocal(env)) {
|
||||
x11dirs = getX11FontPath();
|
||||
|
@ -527,7 +534,7 @@ static char *getPlatformFontPathChars(JNIEnv *env, jboolean noType1) {
|
|||
return path;
|
||||
}
|
||||
|
||||
JNIEXPORT jstring JNICALL Java_sun_awt_X11FontManager_getFontPath
|
||||
JNIEXPORT jstring JNICALL Java_sun_awt_X11FontManager_getFontPathNative
|
||||
(JNIEnv *env, jobject thiz, jboolean noType1) {
|
||||
jstring ret;
|
||||
static char *ptr = NULL; /* retain result across calls */
|
||||
|
@ -539,71 +546,6 @@ JNIEXPORT jstring JNICALL Java_sun_awt_X11FontManager_getFontPath
|
|||
return ret;
|
||||
}
|
||||
|
||||
/*
|
||||
* In general setting the font path in a remote display situation is
|
||||
* problematic. But for Solaris->Solaris the paths needed by the JRE should
|
||||
* also be available to the server, although we have no way to check this
|
||||
* for sure.
|
||||
* So set the font path if we think its safe to do so:
|
||||
* All Solaris X servers at least back to 2.6 and up to Solaris 10
|
||||
* define the exact same vendor string.
|
||||
* The version number for Solaris 2.6 is 3600, for 2.7 is 3610 and
|
||||
* for Solaris 8 6410
|
||||
* we want to set the font path only for 2.8 and onwards. Earlier releases
|
||||
* are unlikely to have the right fonts and can't install "all locales"
|
||||
* as needed to be sure. Also Solaris 8 is the earliest release supported
|
||||
* by 1.5.
|
||||
*/
|
||||
#ifndef HEADLESS
|
||||
static int isSunXServer() {
|
||||
#ifdef __solaris__
|
||||
return ((strncmp(ServerVendor(awt_display), "Sun Microsystems, Inc.", 22) == 0) ||
|
||||
(strncmp(ServerVendor(awt_display), "Oracle Corporation", 18) == 0) &&
|
||||
VendorRelease(awt_display) >= 6410);
|
||||
#else
|
||||
return 0;
|
||||
#endif /* __solaris__ */
|
||||
}
|
||||
|
||||
/* Avoid re-doing work for every call to setNativeFontPath */
|
||||
static int doSetFontPath = -1;
|
||||
static int shouldSetXFontPath(JNIEnv *env) {
|
||||
if (doSetFontPath == -1) {
|
||||
doSetFontPath =
|
||||
awt_display != NULL && (isDisplayLocal(env) || isSunXServer());
|
||||
}
|
||||
return doSetFontPath;
|
||||
}
|
||||
#endif /* !HEADLESS */
|
||||
|
||||
JNIEXPORT void JNICALL Java_sun_font_X11FontManager_setNativeFontPath
|
||||
(JNIEnv *env, jclass obj, jstring theString) {
|
||||
#ifdef HEADLESS
|
||||
return;
|
||||
#else
|
||||
fDirRecord fDir;
|
||||
const char *theChars;
|
||||
|
||||
if (awt_display == NULL) {
|
||||
return;
|
||||
}
|
||||
AWT_LOCK();
|
||||
if (shouldSetXFontPath(env)) {
|
||||
theChars = (*env)->GetStringUTFChars (env, theString, 0);
|
||||
fDir.num = 1;
|
||||
fDir.name[0] = theChars;
|
||||
/* printf ("Registering the font path here %s \n", theChars ); */
|
||||
AddFontsToX11FontPath ( &fDir );
|
||||
if (theChars) {
|
||||
(*env)->ReleaseStringUTFChars (env,
|
||||
theString, (const char*)theChars);
|
||||
}
|
||||
}
|
||||
AWT_UNLOCK();
|
||||
|
||||
#endif
|
||||
}
|
||||
|
||||
#include <dlfcn.h>
|
||||
#ifndef __linux__ /* i.e. is solaris */
|
||||
#include <link.h>
|
||||
|
|
41
jdk/test/java/awt/FontClass/X11FontPathCrashTest.java
Normal file
41
jdk/test/java/awt/FontClass/X11FontPathCrashTest.java
Normal file
|
@ -0,0 +1,41 @@
|
|||
/*
|
||||
* Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation.
|
||||
*
|
||||
* This code is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* version 2 for more details (a copy is included in the LICENSE file that
|
||||
* accompanied this code).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License version
|
||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
|
||||
/*
|
||||
* @test
|
||||
* @bug 6958221
|
||||
* @summary Test no crashing getting fonts on X11
|
||||
* @run main X11FontPathCrashTest
|
||||
*/
|
||||
|
||||
import java.awt.*;
|
||||
import java.awt.font.*;
|
||||
import java.awt.geom.*;
|
||||
|
||||
|
||||
public class X11FontPathCrashTest {
|
||||
public static void main(String[] args) {
|
||||
new Font("nonexistentfont", Font.PLAIN, 12).getFamily();
|
||||
}
|
||||
}
|
||||
|
Loading…
Add table
Add a link
Reference in a new issue