7117595: ArrayIndexOutOfBoundsException in Win32GraphicsEnvironment if display is removed
authormalenkov
Fri, 27 Sep 2013 22:25:58 +0400
changeset 20433 f6d501f12376
parent 20432 5060b1928712
child 20434 19c5cdb0d7a2
7117595: ArrayIndexOutOfBoundsException in Win32GraphicsEnvironment if display is removed Reviewed-by: anthony, serb
jdk/src/macosx/classes/sun/awt/CGraphicsEnvironment.java
jdk/src/share/classes/sun/java2d/SunGraphicsEnvironment.java
jdk/src/solaris/classes/sun/awt/X11GraphicsEnvironment.java
jdk/src/windows/classes/sun/awt/Win32GraphicsEnvironment.java
--- 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];
     }
 
     /**