changeset 3506:8b33567d68b0

6939417: ArrayIndexOutOfBoundsException in Win 7 on selected printers Reviewed-by: igor, prr
author jgodinez
date Fri, 14 Jan 2011 14:25:47 -0800
parents 5cb6bb816a34
children c2fcb5530ba5
files src/windows/classes/sun/print/Win32PrintService.java test/javax/print/DialogMargins.java
diffstat 2 files changed, 9 insertions(+), 2 deletions(-) [+]
line wrap: on
line diff
--- a/src/windows/classes/sun/print/Win32PrintService.java	Fri Jan 14 12:10:45 2011 -0800
+++ b/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/test/javax/print/DialogMargins.java	Fri Jan 14 12:10:45 2011 -0800
+++ b/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