src/java.desktop/share/classes/java/awt/Desktop.java

Print this page

        

@@ -1,7 +1,7 @@
 /*
- * Copyright (c) 2005, 2006, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2005, 2015, 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.  Oracle designates this

@@ -23,23 +23,20 @@
  * questions.
  */
 
 package java.awt;
 
+import java.awt.peer.DesktopPeer;
 import java.io.File;
+import java.io.FilePermission;
 import java.io.IOException;
-import java.net.URISyntaxException;
+import java.net.MalformedURLException;
 import java.net.URI;
+import java.net.URISyntaxException;
 import java.net.URL;
-import java.net.MalformedURLException;
-import java.awt.AWTPermission;
-import java.awt.GraphicsEnvironment;
-import java.awt.HeadlessException;
-import java.awt.peer.DesktopPeer;
+
 import sun.awt.SunToolkit;
-import sun.awt.HeadlessToolkit;
-import java.io.FilePermission;
 import sun.security.util.SecurityConstants;
 
 /**
  * The {@code Desktop} class allows a Java application to launch
  * associated applications registered on the native desktop to handle

@@ -120,11 +117,15 @@
 
     /**
      * Suppresses default constructor for noninstantiability.
      */
     private Desktop() {
-        peer = Toolkit.getDefaultToolkit().createDesktopPeer(this);
+        Toolkit defaultToolkit = Toolkit.getDefaultToolkit();
+        // same cast as in isDesktopSupported()
+        if (defaultToolkit instanceof SunToolkit) {
+            peer = ((SunToolkit) defaultToolkit).createDesktopPeer(this);
+        }
     }
 
     /**
      * Returns the <code>Desktop</code> instance of the current
      * browser context.  On some platforms the Desktop API may not be