United StatesChange Country, Oracle Worldwide Web Sites Communities I am a... I want to...
Bug ID: JDK-6174596 ArrayIndexOutOfBoundsException when opening PrintDialog with HP LaserJet 1300
JDK-6174596 : ArrayIndexOutOfBoundsException when opening PrintDialog with HP LaserJet 1300

Details
Type:
Bug
Submit Date:
2004-10-05
Status:
Resolved
Updated Date:
2010-04-02
Project Name:
JDK
Resolved Date:
2005-03-07
Component:
client-libs
OS:
windows_xp
Sub-Component:
2d
CPU:
x86
Priority:
P4
Resolution:
Fixed
Affected Versions:
1.4.2
Fixed Versions:

Related Reports
Backport:
Backport:
Relates:

Sub Tasks

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
                                     
2004-10-05



Hardware and Software, Engineered to Work Together