changeset 8216:0042f54f65d0

7117595: ArrayIndexOutOfBoundsException in Win32GraphicsEnvironment if display is removed Reviewed-by: anthony, serb
author malenkov
date Fri, 27 Sep 2013 22:25:58 +0400
parents bfff9e9120ec
children 603cd3cefbb0
files src/macosx/classes/sun/awt/CGraphicsEnvironment.java src/share/classes/sun/java2d/SunGraphicsEnvironment.java src/solaris/classes/sun/awt/X11GraphicsEnvironment.java src/windows/classes/sun/awt/Win32GraphicsEnvironment.java
diffstat 4 files changed, 20 insertions(+), 3 deletions(-) [+]
line wrap: on
line diff
--- a/src/macosx/classes/sun/awt/CGraphicsEnvironment.java	Fri Sep 27 22:17:24 2013 +0400
+++ b/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/src/share/classes/sun/java2d/SunGraphicsEnvironment.java	Fri Sep 27 22:17:24 2013 +0400
+++ b/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/src/solaris/classes/sun/awt/X11GraphicsEnvironment.java	Fri Sep 27 22:17:24 2013 +0400
+++ b/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/src/windows/classes/sun/awt/Win32GraphicsEnvironment.java	Fri Sep 27 22:17:24 2013 +0400
+++ b/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];
     }
 
     /**