diff --git a/src/macosx/classes/sun/awt/CGraphicsEnvironment.java b/src/macosx/classes/sun/awt/CGraphicsEnvironment.java index a2319e675f0d65203f252642db74a30a77d3fb0a..a117d99f42c60149c438b4dd727914f406ffad7c 100644 --- a/src/macosx/classes/sun/awt/CGraphicsEnvironment.java +++ b/src/macosx/classes/sun/awt/CGraphicsEnvironment.java @@ -181,6 +181,9 @@ public final class CGraphicsEnvironment extends SunGraphicsEnvironment { initDevices(); d = devices.get(mainDisplayID); + if (d == null) { + throw new AWTError("no screen devices"); + } } return d; } diff --git a/src/share/classes/sun/java2d/SunGraphicsEnvironment.java b/src/share/classes/sun/java2d/SunGraphicsEnvironment.java index 724fa2f1d1095f88b6b69a6b67c8f5b7ea1388a2..5bd2d2f99ee13386a85b47ae6765a913ee8d9fc7 100644 --- a/src/share/classes/sun/java2d/SunGraphicsEnvironment.java +++ b/src/share/classes/sun/java2d/SunGraphicsEnvironment.java @@ -165,7 +165,11 @@ public abstract class SunGraphicsEnvironment extends GraphicsEnvironment * Returns the default screen graphics device. */ public GraphicsDevice getDefaultScreenDevice() { - return getScreenDevices()[0]; + GraphicsDevice[] screens = getScreenDevices(); + if (screens.length == 0) { + throw new AWTError("no screen devices"); + } + return screens[0]; } /** diff --git a/src/solaris/classes/sun/awt/X11GraphicsEnvironment.java b/src/solaris/classes/sun/awt/X11GraphicsEnvironment.java index 4e1c816fd1802c9730699125b5f549e652e9eaf6..3dece38d457138438ed9c62cdccd723da91f772e 100644 --- a/src/solaris/classes/sun/awt/X11GraphicsEnvironment.java +++ b/src/solaris/classes/sun/awt/X11GraphicsEnvironment.java @@ -200,7 +200,12 @@ public class X11GraphicsEnvironment * Returns the default screen graphics device. */ public GraphicsDevice getDefaultScreenDevice() { - return getScreenDevices()[getDefaultScreenNum()]; + GraphicsDevice[] screens = getScreenDevices(); + if (screens.length == 0) { + throw new AWTError("no screen devices"); + } + int index = getDefaultScreenNum(); + return screens[0 < index && index < screens.length ? index : 0]; } public boolean isDisplayLocal() { diff --git a/src/windows/classes/sun/awt/Win32GraphicsEnvironment.java b/src/windows/classes/sun/awt/Win32GraphicsEnvironment.java index a3a48e2d7b491373b296ba5f7be82b1e2450771f..c3e684b4142c09b6b82184703d069e5b5377db62 100644 --- a/src/windows/classes/sun/awt/Win32GraphicsEnvironment.java +++ b/src/windows/classes/sun/awt/Win32GraphicsEnvironment.java @@ -93,7 +93,12 @@ public class Win32GraphicsEnvironment protected native int getDefaultScreen(); public GraphicsDevice getDefaultScreenDevice() { - return getScreenDevices()[getDefaultScreen()]; + GraphicsDevice[] screens = getScreenDevices(); + if (screens.length == 0) { + throw new AWTError("no screen devices"); + } + int index = getDefaultScreen(); + return screens[0 < index && index < screens.length ? index : 0]; } /**