From df6063fb258eedc215381a96dfe99b43e14a3f7a Mon Sep 17 00:00:00 2001 From: malenkov Date: Fri, 27 Sep 2013 22:25:58 +0400 Subject: [PATCH] 7117595: ArrayIndexOutOfBoundsException in Win32GraphicsEnvironment if display is removed Reviewed-by: anthony, serb --- src/macosx/classes/sun/awt/CGraphicsEnvironment.java | 3 +++ src/share/classes/sun/java2d/SunGraphicsEnvironment.java | 6 +++++- src/solaris/classes/sun/awt/X11GraphicsEnvironment.java | 7 ++++++- src/windows/classes/sun/awt/Win32GraphicsEnvironment.java | 7 ++++++- 4 files changed, 20 insertions(+), 3 deletions(-) diff --git a/src/macosx/classes/sun/awt/CGraphicsEnvironment.java b/src/macosx/classes/sun/awt/CGraphicsEnvironment.java index a2319e675..a117d99f4 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 724fa2f1d..5bd2d2f99 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 4e1c816fd..3dece38d4 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 a3a48e2d7..c3e684b41 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]; } /** -- GitLab