JDK-4722616 : ArrayIndexOutOfBoundsException when printing with a Card Printer
  • Type: Bug
  • Component: client-libs
  • Sub-Component: 2d
  • Affected Version: 1.4.0
  • Priority: P4
  • Status: Resolved
  • Resolution: Fixed
  • OS: windows_2000
  • CPU: x86
  • Submitted: 2002-07-30
  • Updated: 2002-10-16
  • Resolved: 2002-10-16
The Version table provides details related to the release that this issue/RFE will be addressed.

Unresolved : Release in which this issue/RFE will be addressed.
Resolved: Release in which this issue/RFE has been resolved.
Fixed : Release in which this issue/RFE has been fixed. The release containing this fix may be available for download as an Early Access Release or a General Availability Release.

To download the current JDK release, click here.
Other
1.4.2 mantisFixed
Description

Name: jk109818			Date: 07/29/2002


FULL PRODUCT VERSION :
java version "1.4.0"
Java(TM) 2 Runtime Environment, Standard Edition (build 1.4.0-b92)
Java HotSpot(TM) Client VM (build 1.4.0-b92, mixed mode)

FULL OPERATING SYSTEM VERSION :

Microsoft Windows 2000 [Version 5.00.2195]

A DESCRIPTION OF THE PROBLEM :
I am trying to write a program that will perform
silent printing to a card printer.  Everything seems
to work when printing to another printer that we have but
nothing seems to happen when the program prints
to the card printer.  I tried playing around and
noticed that an exception gets thrown when
trying to get default values from the printer.

printer driver url:
http://www.eltroncards.com/drivers/downloads/winnt/p420_wnt_
0206.exe

ERROR MESSAGES/STACK TRACES THAT OCCUR :
java.lang.ArrayIndexOutOfBoundsException
	at sun.print.Win32PrintService.getDefaultAttributeValue
(Win32PrintService.java:786)
	at sun.print.Win32PrintService.getSupportedAttributeValues
(Win32PrintService.java:1049)


This bug can be reproduced always.

---------- BEGIN SOURCE ----------


import javax.print.*;
import javax.print.event.*;
import javax.print.attribute.*;
import javax.print.attribute.standard.*;

public class test {

  public test() {
                PrintService printer =
PrintServiceLookup.lookupDefaultPrintService();
              Class[] categories = printer.getSupportedAttributeCategories();

		for (int i=0; i<categories.length; i++)
		{
			System.out.print("Class "+categories[i]);
			System.out.print(' ');
			Object value = printer.getSupportedAttributeValues
(categories[i], null, null);
			if (value.getClass().isArray())
			{
				Object[] v = (Object[])value;
				for (int j=0; j<v.length; j++)
				{
					if (j > 0)
						System.out.print(", ");
					System.out.print(v[j]);
				}
			}
			else
				System.out.print(value);
			System.out.println();
		}


  }
  public static void main(String[] args) {
    test test1 = new test();
  }
}
---------- END SOURCE ----------
(Review ID: 145232) 
======================================================================

Comments
CONVERTED DATA BugTraq+ Release Management Values COMMIT TO FIX: mantis FIXED IN: mantis INTEGRATED IN: mantis mantis-b04
14-06-2004

EVALUATION Looks like we are accessing an array with 0 size. To avoid this exception, we need to check for mediasizenames.length > 0. ###@###.### 2002-07-29 No longer reproducible with the recent fix for 4701198 but length still needs to be checked. ###@###.### 2002-09-04 ================================= Fix: Added check for length = 0. ###@###.### 2002-09-16 ====================================
04-09-2002