7117595: ArrayIndexOutOfBoundsException in Win32GraphicsEnvironment if display is removed
Reviewed-by: anthony, serb
--- a/jdk/src/macosx/classes/sun/awt/CGraphicsEnvironment.java Fri Sep 27 22:17:24 2013 +0400
+++ b/jdk/src/macosx/classes/sun/awt/CGraphicsEnvironment.java Fri Sep 27 22:25:58 2013 +0400
@@ -181,6 +181,9 @@
initDevices();
d = devices.get(mainDisplayID);
+ if (d == null) {
+ throw new AWTError("no screen devices");
+ }
}
return d;
}
--- a/jdk/src/share/classes/sun/java2d/SunGraphicsEnvironment.java Fri Sep 27 22:17:24 2013 +0400
+++ b/jdk/src/share/classes/sun/java2d/SunGraphicsEnvironment.java Fri Sep 27 22:25:58 2013 +0400
@@ -165,7 +165,11 @@
* 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];
}
/**
--- a/jdk/src/solaris/classes/sun/awt/X11GraphicsEnvironment.java Fri Sep 27 22:17:24 2013 +0400
+++ b/jdk/src/solaris/classes/sun/awt/X11GraphicsEnvironment.java Fri Sep 27 22:25:58 2013 +0400
@@ -200,7 +200,12 @@
* 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() {
--- a/jdk/src/windows/classes/sun/awt/Win32GraphicsEnvironment.java Fri Sep 27 22:17:24 2013 +0400
+++ b/jdk/src/windows/classes/sun/awt/Win32GraphicsEnvironment.java Fri Sep 27 22:25:58 2013 +0400
@@ -93,7 +93,12 @@
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];
}
/**