From efefa140388e224dc30e3597e7fde824a26feaff Mon Sep 17 00:00:00 2001 From: Phil Race Date: Wed, 12 Jan 2011 15:58:15 -0800 Subject: [PATCH] 6958221: java.awt.Font.getFamily() leads to JVM crash on Linux on JDK7 for "custom" fonts Reviewed-by: igor, jgodinez --- jdk/make/sun/awt/mapfile-mawt-vers | 3 +- jdk/make/sun/awt/mapfile-vers-linux | 3 +- jdk/make/sun/headless/mapfile-vers | 1 - jdk/make/sun/xawt/mapfile-vers | 3 +- .../classes/sun/awt/X11FontManager.java | 26 ++----- .../classes/sun/awt/motif/MToolkit.java | 7 -- jdk/src/solaris/native/sun/awt/fontpath.c | 74 ++----------------- .../awt/FontClass/X11FontPathCrashTest.java | 41 ++++++++++ 8 files changed, 58 insertions(+), 100 deletions(-) create mode 100644 jdk/test/java/awt/FontClass/X11FontPathCrashTest.java diff --git a/jdk/make/sun/awt/mapfile-mawt-vers b/jdk/make/sun/awt/mapfile-mawt-vers index b80f30fed50..f1b7143e948 100644 --- a/jdk/make/sun/awt/mapfile-mawt-vers +++ b/jdk/make/sun/awt/mapfile-mawt-vers @@ -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 diff --git a/jdk/make/sun/awt/mapfile-vers-linux b/jdk/make/sun/awt/mapfile-vers-linux index 60fa9ccef69..d2fbf560c9b 100644 --- a/jdk/make/sun/awt/mapfile-vers-linux +++ b/jdk/make/sun/awt/mapfile-vers-linux @@ -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 diff --git a/jdk/make/sun/headless/mapfile-vers b/jdk/make/sun/headless/mapfile-vers index c82b6116fcc..d04e70700f0 100644 --- a/jdk/make/sun/headless/mapfile-vers +++ b/jdk/make/sun/headless/mapfile-vers @@ -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; diff --git a/jdk/make/sun/xawt/mapfile-vers b/jdk/make/sun/xawt/mapfile-vers index 7eac730927d..479a55a800d 100644 --- a/jdk/make/sun/xawt/mapfile-vers +++ b/jdk/make/sun/xawt/mapfile-vers @@ -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; diff --git a/jdk/src/solaris/classes/sun/awt/X11FontManager.java b/jdk/src/solaris/classes/sun/awt/X11FontManager.java index fea46ff56c3..36eeb15d607 100644 --- a/jdk/src/solaris/classes/sun/awt/X11FontManager.java +++ b/jdk/src/solaris/classes/sun/awt/X11FontManager.java @@ -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; iSolaris 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 #ifndef __linux__ /* i.e. is solaris */ #include diff --git a/jdk/test/java/awt/FontClass/X11FontPathCrashTest.java b/jdk/test/java/awt/FontClass/X11FontPathCrashTest.java new file mode 100644 index 00000000000..cbc762a36ed --- /dev/null +++ b/jdk/test/java/awt/FontClass/X11FontPathCrashTest.java @@ -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(); + } +} +