JDK-6174596 : ArrayIndexOutOfBoundsException when opening PrintDialog with HP LaserJet 1300
  • Type: Bug
  • Component: client-libs
  • Sub-Component: 2d
  • Affected Version: 1.4.2
  • Priority: P4
  • Status: Resolved
  • Resolution: Fixed
  • OS: windows_xp
  • CPU: x86
  • Submitted: 2004-10-05
  • Updated: 2010-04-02
  • Resolved: 2005-03-07
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 JDK 6
1.4.2_10Fixed 6 betaFixed
Related Reports
Relates :  
Description
FULL PRODUCT VERSION :
Java 1.4.2_04 with Sun Microsystems Inc. Java HotSpot(TM) Client VM
    (mixed mode)

ADDITIONAL OS VERSION INFORMATION :
Windows XP

EXTRA RELEVANT SYSTEM CONFIGURATION :
HP LaserJet 1300

A DESCRIPTION OF THE PROBLEM :
When HP LaserJet 1300 is set to be my default printer, I get the following exception when I first bring up the print dialog (using 1.4 printing API):

java.lang.ArrayIndexOutOfBoundsException: -1
	at sun.print.Win32PrintService.getMediaTrays(Unknown Source)
	at sun.print.Win32PrintService.getSupportedAttributeValues(Unknown Source)
	at sun.print.ServiceDialog$MediaPanel.updateInfo(Unknown Source)
	at sun.print.ServiceDialog$PageSetupPanel.updateInfo(Unknown Source)
	at sun.print.ServiceDialog.updatePanels(Unknown Source)
	at sun.print.ServiceDialog.<init>(Unknown Source)
	at javax.print.ServiceUI.printDialog(Unknown Source) ...

Subsequent attempts to print within the same application session succeed.


STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
Set HP LaserJet 1300 to be your system's default printer
Run a test application that brings up the 1.4 print dialog.
Exception is thrown.

EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
Expect print dialog to open, allowing printing of application.
ACTUAL -
Exception is thrown.

ERROR MESSAGES/STACK TRACES THAT OCCUR :
java.lang.ArrayIndexOutOfBoundsException: -1
	at sun.print.Win32PrintService.getMediaTrays(Unknown Source)
	at sun.print.Win32PrintService.getSupportedAttributeValues(Unknown Source)
	at sun.print.ServiceDialog$MediaPanel.updateInfo(Unknown Source)
	at sun.print.ServiceDialog$PageSetupPanel.updateInfo(Unknown Source)
	at sun.print.ServiceDialog.updatePanels(Unknown Source)
	at sun.print.ServiceDialog.<init>(Unknown Source)
	at javax.print.ServiceUI.printDialog(Unknown Source)


REPRODUCIBILITY :
This bug can be reproduced always.

---------- BEGIN SOURCE ----------
import javax.swing.*;
import javax.print.DocFlavor;
import javax.print.PrintService;
import javax.print.PrintServiceLookup;
import javax.print.ServiceUI;
import javax.print.attribute.PrintRequestAttributeSet;
import javax.print.attribute.HashPrintRequestAttributeSet;
import java.awt.*;
import java.awt.print.Printable;
import java.awt.print.PageFormat;
import java.awt.print.PrinterException;


public class PrintTest{
   private JFrame fFrame;
   private MyTextArea fTextArea;

   public PrintTest(){
       //bring up a 1.4 print dialog for a text area.
       fFrame = new JFrame("Text Area");
       fTextArea = new MyTextArea("foo bar test\n" +
               "foo bar test\n" +
               "test test test");
       fFrame.getContentPane().add(fTextArea);
       fFrame.setSize(200, 200);
       fFrame.setVisible(true);
       print();
   }

   public void print(){
       DocFlavor flavor = DocFlavor.SERVICE_FORMATTED.PRINTABLE;
       PrintService defaultService =
PrintServiceLookup.lookupDefaultPrintService();
       final PrintRequestAttributeSet pras = new HashPrintRequestAttributeSet();

       PrintService[] printService = // using pras above causes
problems-- no printers returned
               PrintServiceLookup.lookupPrintServices(flavor, new HashPrintRequestAttributeSet());

       Point location = fFrame.getLocationOnScreen();
       ServiceUI.printDialog(null, location.x + 100, location.y + 100,
               printService, defaultService, flavor, pras);

   }

   public class MyTextArea extends JTextArea implements Printable{
       public MyTextArea(String text){
           super(text);
       }

       public int print(Graphics g, PageFormat pf, int pageIndex) throws PrinterException{
           return -1;
       }
   }

   public static void main(String[] args){
       new PrintTest();
   }
}

---------- END SOURCE ----------
###@###.### 10/5/04 22:28 GMT

Comments
EVALUATION I reproduced this with the PCL6 driver for LaserJet 1300 that I downloaded from hp.com. The problem exists in 1.4.2 and in 1.5. I didn't try any other release. It doesn't occur with the (PCL5e) LaserJet 1200 driver ###@###.### 10/5/04 22:31 GMT We could fix the Exception not being thrown but take note that this driver is returning an invalid value. When DeviceCapabilities is called to get all the supported DC_BINS, it returned the last bin as 0. Note that 0 is not defined as one of the possible bin selections in windows so java code did not take this into account. ###@###.### 10/7/04 18:28 GMT Fixed by handling invalid bin values. ###@###.### 2005-1-27 20:34:55 GMT
05-10-2004