--- old/jdk/src/macosx/classes/sun/awt/CGraphicsEnvironment.java 2013-09-23 21:55:59.091237700 +0400 +++ new/jdk/src/macosx/classes/sun/awt/CGraphicsEnvironment.java 2013-09-23 21:55:58.599209500 +0400 @@ -167,6 +167,9 @@ devices.put(id, old.containsKey(id) ? old.get(id) : new CGraphicsDevice(id)); } + if (devices.isEmpty()) { + throw new AWTError("no screen devices"); + } } displayChanged(); } --- old/jdk/src/share/classes/sun/java2d/SunGraphicsEnvironment.java 2013-09-23 21:56:02.412427700 +0400 +++ new/jdk/src/share/classes/sun/java2d/SunGraphicsEnvironment.java 2013-09-23 21:56:01.866396400 +0400 @@ -25,6 +25,7 @@ package sun.java2d; +import java.awt.AWTError; import java.awt.Color; import java.awt.Font; import java.awt.Graphics2D; @@ -134,6 +135,9 @@ GraphicsDevice[] ret = screens; if (ret == null) { int num = getNumScreens(); + if (num == 0) { + throw new AWTError("no screen devices"); + } ret = new GraphicsDevice[num]; for (int i = 0; i < num; i++) { ret[i] = makeScreenDevice(i); --- old/jdk/src/solaris/classes/sun/awt/X11GraphicsEnvironment.java 2013-09-23 21:56:05.477603000 +0400 +++ new/jdk/src/solaris/classes/sun/awt/X11GraphicsEnvironment.java 2013-09-23 21:56:04.989575100 +0400 @@ -200,7 +200,9 @@ * Returns the default screen graphics device. */ public GraphicsDevice getDefaultScreenDevice() { - return getScreenDevices()[getDefaultScreenNum()]; + GraphicsDevice[] screens = getScreenDevices(); + int index = getDefaultScreenNum(); + return screens[0 < index && index < screens.length ? index : 0]; } public boolean isDisplayLocal() { --- old/jdk/src/windows/classes/sun/awt/Win32GraphicsEnvironment.java 2013-09-23 21:56:08.391769700 +0400 +++ new/jdk/src/windows/classes/sun/awt/Win32GraphicsEnvironment.java 2013-09-23 21:56:07.920742700 +0400 @@ -25,6 +25,7 @@ package sun.awt; +import java.awt.AWTError; import java.awt.GraphicsConfiguration; import java.awt.GraphicsDevice; import java.awt.GraphicsEnvironment; @@ -93,7 +94,9 @@ protected native int getDefaultScreen(); public GraphicsDevice getDefaultScreenDevice() { - return getScreenDevices()[getDefaultScreen()]; + GraphicsDevice[] screens = getScreenDevices(); + int index = getDefaultScreen(); + return screens[0 < index && index < screens.length ? index : 0]; } /** @@ -127,6 +130,9 @@ public void displayChanged() { // getNumScreens() will return the correct current number of screens GraphicsDevice newDevices[] = new GraphicsDevice[getNumScreens()]; + if (newDevices.length == 0) { + throw new AWTError("no screen devices"); + } GraphicsDevice oldScreens[] = screens; // go through the list of current devices and determine if they // could be reused, or will have to be replaced