7117595: ArrayIndexOutOfBoundsException in Win32GraphicsEnvironment if display is removed

Reviewed-by: anthony, serb
This commit is contained in:
Sergey Malenkov 2013-09-27 22:25:58 +04:00
parent dd224c8deb
commit e37d16f11b
4 changed files with 20 additions and 3 deletions

View File

@ -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;
}

View File

@ -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];
}
/**

View File

@ -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() {

View File

@ -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];
}
/**