changeset 5240:038b17edbb4b

7184951: [macosx] Exception at java.awt.datatransfer on headless mode (only in GUI session) Reviewed-by: art, serb
author kizune
date Tue, 24 Jul 2012 12:43:40 +0400
parents 348fea6059d2
children f2738a05273d
files src/macosx/classes/sun/lwawt/macosx/CDataTransferer.java src/macosx/classes/sun/lwawt/macosx/CToolkitThreadBlockedHandler.java
diffstat 2 files changed, 11 insertions(+), 2 deletions(-) [+]
line wrap: on
line diff
--- a/src/macosx/classes/sun/lwawt/macosx/CDataTransferer.java	Mon Jul 23 21:52:27 2012 +0400
+++ b/src/macosx/classes/sun/lwawt/macosx/CDataTransferer.java	Tue Jul 24 12:43:40 2012 +0400
@@ -182,6 +182,10 @@
         Long format = predefinedClipboardNameMap.get(str);
 
         if (format == null) {
+            if (java.awt.GraphicsEnvironment.getLocalGraphicsEnvironment().isHeadlessInstance()) {
+                // Do not try to access GUI manager for unknown format
+                return new Long(-1);
+            }
             format = new Long(registerFormatWithPasteboard(str));
             predefinedClipboardNameMap.put(str, format);
             predefinedClipboardFormatMap.put(format, str);
--- a/src/macosx/classes/sun/lwawt/macosx/CToolkitThreadBlockedHandler.java	Mon Jul 23 21:52:27 2012 +0400
+++ b/src/macosx/classes/sun/lwawt/macosx/CToolkitThreadBlockedHandler.java	Tue Jul 24 12:43:40 2012 +0400
@@ -28,7 +28,10 @@
 import sun.awt.datatransfer.ToolkitThreadBlockedHandler;
 
 final class CToolkitThreadBlockedHandler implements ToolkitThreadBlockedHandler {
-    private final LWCToolkit toolkit = (LWCToolkit)java.awt.Toolkit.getDefaultToolkit();
+    private final LWCToolkit toolkit =
+            java.awt.Toolkit.getDefaultToolkit() instanceof LWCToolkit
+                    ? (LWCToolkit)java.awt.Toolkit.getDefaultToolkit()
+                    : null;
 
     public void lock() {
     }
@@ -44,7 +47,9 @@
         // Despite the naming of this method, on MacOS only one
         // event is read and dispatched before this method returns.
         // This call is non-blocking and does not wait for an event
-        toolkit.startNativeNestedEventLoop();
+        if (toolkit != null) {
+            toolkit.startNativeNestedEventLoop();
+        }
     }
 
     public void exit() {