# HG changeset patch # User prr # Date 1294876695 28800 # Node ID f4ec6ef455c375751a11bce0db1214637f5486dd # Parent 6e45e1e87347f6f4b7a8b18af2586843c0944374 6958221: java.awt.Font.getFamily() leads to JVM crash on Linux on JDK7 for "custom" fonts Reviewed-by: igor, jgodinez diff -r 6e45e1e87347 -r f4ec6ef455c3 jdk/make/sun/awt/mapfile-mawt-vers --- a/jdk/make/sun/awt/mapfile-mawt-vers Wed Jan 05 11:21:00 2011 -0800 +++ b/jdk/make/sun/awt/mapfile-mawt-vers Wed Jan 12 15:58:15 2011 -0800 @@ -515,8 +515,7 @@ 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 -r 6e45e1e87347 -r f4ec6ef455c3 jdk/make/sun/awt/mapfile-vers-linux --- a/jdk/make/sun/awt/mapfile-vers-linux Wed Jan 05 11:21:00 2011 -0800 +++ b/jdk/make/sun/awt/mapfile-vers-linux Wed Jan 12 15:58:15 2011 -0800 @@ -537,8 +537,7 @@ 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 -r 6e45e1e87347 -r f4ec6ef455c3 jdk/make/sun/headless/mapfile-vers --- a/jdk/make/sun/headless/mapfile-vers Wed Jan 05 11:21:00 2011 -0800 +++ b/jdk/make/sun/headless/mapfile-vers Wed Jan 12 15:58:15 2011 -0800 @@ -65,7 +65,6 @@ 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 -r 6e45e1e87347 -r f4ec6ef455c3 jdk/make/sun/xawt/mapfile-vers --- a/jdk/make/sun/xawt/mapfile-vers Wed Jan 05 11:21:00 2011 -0800 +++ b/jdk/make/sun/xawt/mapfile-vers Wed Jan 12 15:58:15 2011 -0800 @@ -188,8 +188,7 @@ 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 -r 6e45e1e87347 -r f4ec6ef455c3 jdk/src/solaris/classes/sun/awt/X11FontManager.java --- a/jdk/src/solaris/classes/sun/awt/X11FontManager.java Wed Jan 05 11:21:00 2011 -0800 +++ b/jdk/src/solaris/classes/sun/awt/X11FontManager.java Wed Jan 12 15:58:15 2011 -0800 @@ -718,25 +718,6 @@ 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 -r 6e45e1e87347 -r f4ec6ef455c3 jdk/test/java/awt/FontClass/X11FontPathCrashTest.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/jdk/test/java/awt/FontClass/X11FontPathCrashTest.java Wed Jan 12 15:58:15 2011 -0800 @@ -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(); + } +} +