changeset 4638:abae34c163a2

7124511: [macosx] Strange NullPointerException (err message: 'CFMessagePort: bootstrap_register(): failed 110 Summary: Force AWT Headless mode when the graphics server is unavailable Reviewed-by: swingler
author anthony
date Thu, 29 Dec 2011 15:42:04 +0300
parents b35e80eb4475
children 546eea5433b1
files src/share/classes/java/awt/GraphicsEnvironment.java src/solaris/native/java/lang/java_props_md.c src/solaris/native/sun/awt/awt_LoadLibrary.c
diffstat 3 files changed, 19 insertions(+), 40 deletions(-) [+]
line wrap: on
line diff
--- a/src/share/classes/java/awt/GraphicsEnvironment.java	Thu Dec 29 12:21:21 2011 +0300
+++ b/src/share/classes/java/awt/GraphicsEnvironment.java	Thu Dec 29 15:42:04 2011 +0300
@@ -170,10 +170,20 @@
                         if (System.getProperty("javaplugin.version") != null) {
                             headless = defaultHeadless = Boolean.FALSE;
                         } else {
-                            String osName = System.getProperty("os.name");
-                            headless = defaultHeadless =
-                                Boolean.valueOf(("Linux".equals(osName) || "SunOS".equals(osName)) &&
-                                                (System.getenv("DISPLAY") == null));
+                            if ("sun.awt.HeadlessGraphicsEnvironment".equals(
+                                    System.getProperty("java.awt.graphicsenv")))
+                            {
+                                headless = defaultHeadless = Boolean.TRUE;
+                            } else {
+                                String osName = System.getProperty("os.name");
+                                headless = defaultHeadless =
+                                    Boolean.valueOf(("Linux".equals(osName) ||
+                                                     "SunOS".equals(osName) ||
+                                                     "FreeBSD".equals(osName) ||
+                                                     "NetBSD".equals(osName) ||
+                                                     "OpenBSD".equals(osName)) &&
+                                                     (System.getenv("DISPLAY") == null));
+                            }
                         }
                     } else if (nm.equals("true")) {
                         headless = Boolean.TRUE;
--- a/src/solaris/native/java/lang/java_props_md.c	Thu Dec 29 12:21:21 2011 +0300
+++ b/src/solaris/native/java/lang/java_props_md.c	Thu Dec 29 15:42:04 2011 +0300
@@ -426,7 +426,7 @@
 #ifdef MACOSX
                 break;
             default:
-                sprops.graphics_env = "sun.awt.HToolkit";
+                sprops.awt_toolkit = "sun.awt.HToolkit";
                 break;
         }
 #endif
--- a/src/solaris/native/sun/awt/awt_LoadLibrary.c	Thu Dec 29 12:21:21 2011 +0300
+++ b/src/solaris/native/sun/awt/awt_LoadLibrary.c	Thu Dec 29 15:42:04 2011 +0300
@@ -85,8 +85,8 @@
     JNIEnv *env = (JNIEnv *)JNU_GetEnv(vm, JNI_VERSION_1_2);
     void *v;
     char *envvar;
-    jstring toolkit = NULL, grenv = NULL, fmanager = NULL;
-    jstring tkProp = NULL, geProp = NULL, fmProp = NULL;
+    jstring fmanager = NULL;
+    jstring fmProp = NULL;
 
     if (awtHandle != NULL) {
         /* Avoid several loading attempts */
@@ -102,42 +102,24 @@
     p = strrchr(buf, '/');
 
     /*
-     * The code below is responsible for:
-     * 1. Loading appropriate awt library, i.e. xawt/libmawt or headless/libwawt
-     * 2. Setting "awt.toolkit" system property to use the appropriate Java toolkit class,
-     *    (if user has specified the toolkit in env varialble)
+     * 1. Set the "sun.font.fontmanager" system property,
+     * 2. Choose the library image name.
      */
 
-    tkProp = (*env)->NewStringUTF(env, "awt.toolkit");
-    geProp = (*env)->NewStringUTF(env, "java.awt.graphicsenv");
     fmProp = (*env)->NewStringUTF(env, "sun.font.fontmanager");
     /* Check if toolkit is specified in env variable */
 #ifdef MACOSX
     envvar = getenv("AWT_TOOLKIT");
     if (envvar && strstr(envvar, "XToolkit")) {
 #endif
-    toolkit = (*env)->NewStringUTF(env, "sun.awt.X11.XToolkit");
-        grenv = (*env)->NewStringUTF(env, "sun.awt.X11GraphicsEnvironment");
         fmanager = (*env)->NewStringUTF(env, "sun.awt.X11FontManager");
         tk = "/xawt/libmawt";
 #ifdef MACOSX
     } else {
-    toolkit = (*env)->NewStringUTF(env, "sun.lwawt.macosx.LWCToolkit");
-        grenv = (*env)->NewStringUTF(env, "sun.awt.CGraphicsEnvironment");
         fmanager = (*env)->NewStringUTF(env, "sun.font.CFontManager");
         tk = "/lwawt/liblwawt";
     }
 #endif
-    if (toolkit && tkProp) {
-        JNU_CallStaticMethodByName(env, NULL, "java/lang/System", "setProperty",
-                                   "(Ljava/lang/String;Ljava/lang/String;)Ljava/lang/String;",
-                                   tkProp, toolkit);
-    }
-    if (grenv && geProp) {
-        JNU_CallStaticMethodByName(env, NULL, "java/lang/System", "setProperty",
-                                   "(Ljava/lang/String;Ljava/lang/String;)Ljava/lang/String;",
-                                   geProp, grenv);
-    }
     if (fmanager && fmProp) {
         JNU_CallStaticMethodByName(env, NULL, "java/lang/System", "setProperty",
                                    "(Ljava/lang/String;Ljava/lang/String;)Ljava/lang/String;",
@@ -155,19 +137,6 @@
     }
 #endif
 
-    if (toolkit) {
-        (*env)->DeleteLocalRef(env, toolkit);
-    }
-    if (tkProp) {
-        (*env)->DeleteLocalRef(env, tkProp);
-    }
-    if (grenv) {
-        (*env)->DeleteLocalRef(env, grenv);
-    }
-    if (geProp) {
-        (*env)->DeleteLocalRef(env, geProp);
-    }
-
 #ifdef MACOSX
     strcat(p, ".dylib");
 #else