6939417: ArrayIndexOutOfBoundsException in Win 7 on selected printers
authorjgodinez
Fri, 14 Jan 2011 14:25:47 -0800
changeset 7939 4b122be94252
parent 7938 970d0e025e57
child 7940 7d20d72dd3b9
6939417: ArrayIndexOutOfBoundsException in Win 7 on selected printers Reviewed-by: igor, prr
jdk/src/windows/classes/sun/print/Win32PrintService.java
jdk/test/javax/print/DialogMargins.java
--- a/jdk/src/windows/classes/sun/print/Win32PrintService.java	Fri Jan 14 12:10:45 2011 -0800
+++ b/jdk/src/windows/classes/sun/print/Win32PrintService.java	Fri Jan 14 14:25:47 2011 -0800
@@ -439,7 +439,14 @@
 
         MediaTray[] arr = new MediaTray[nTray];
         int dmBin;
-        for (int i = 0, j=0; i < mediaTr.length; i++) {
+
+        /* Some drivers in Win 7 don't have the same length for DC_BINS and
+         * DC_BINNAMES so there is no guarantee that lengths of mediaTr and
+         * winMediaTrayNames are equal. To avoid getting ArrayIndexOutOfBounds,
+         * we need to make sure we get the minimum of the two.
+         */
+
+        for (int i = 0, j=0; i < Math.min(mediaTr.length, winMediaTrayNames.length); i++) {
             dmBin = mediaTr[i];
             if (dmBin > 0) {
                 // check for unsupported DMBINs and create new Win32MediaTray
--- a/jdk/test/javax/print/DialogMargins.java	Fri Jan 14 12:10:45 2011 -0800
+++ b/jdk/test/javax/print/DialogMargins.java	Fri Jan 14 14:25:47 2011 -0800
@@ -25,7 +25,7 @@
 
 /**
  * @test
- * @bug 4485755 6361370 6448717 5080051
+ * @bug 4485755 6361370 6448717 5080051 6939417
  * @summary dialog doesn't have way to specify margins
  *          for 6361370, verify exception for offline printer in Windows
  *          for 6448717, faster display of print dialog