JDK-4980454 : PIT: "PrintToFile" feature is broken for cross-platform print dialog
  • Type: Bug
  • Component: client-libs
  • Sub-Component: javax.swing
  • Affected Version: 5.0
  • Priority: P2
  • Status: Closed
  • Resolution: Duplicate
  • OS: generic
  • CPU: generic
  • Submitted: 2004-01-20
  • Updated: 2004-03-10
  • Resolved: 2004-02-02
Related Reports
Duplicate :  
Relates :  
Description
I am trying to print some print data to a file using Cross-Platform print dialog. I am selecting 'PrintToFile' option from the print dialog and clicking 'OK'. A file dialog pops up and it is defaulted with 'out.ps' file name. When I click 'OK' in the file dialog a null pointer exception is thrown.

This is reproducible on all platforms with the cross-platform dialog on the PIT build. This is working fine on the previous builds (tested on Tiger - b32a). I tested this on WinXP and Solaris 9 using the following PIT build:

java version "2d.pit-jcg-sparc-01-2004-01-18.tiger"
Java(TM) 2 Runtime Environment, Standard Edition (build 2d.pit-jcg-sparc-01-2004-01-18.tiger)
Java HotSpot(TM) Client VM (build 1.5.0-beta2-b33, mixed mode)

The exception is thrown only when we specify a file name that does not exist in the given directory. Same case applies for the default file name also.

Printing to a file is a basic feature which has been working in all the previous builds and this has no workaround. 

I have attached a sample code. Execute the sample code. Choose 'PrintToFile' option and click 'OK'. Specify a non-existant file name in the file dialog and click 'OK' in the file dialog (or make sure you don't have the default file already in the selected dir). You will get the NPE on the console.

Here is the exception:
java.lang.NullPointerException
at sun.print.ServiceDialog$ValidatingFileChooser.approveSelection(ServiceDialog.java:2717)
at javax.swing.plaf.basic.BasicFileChooserUI$ApproveSelectionAction.actionPerformed(BasicFileChooserUI.java:918)
at javax.swing.AbstractButton.fireActionPerformed(AbstractButton.java:1834)
at javax.swing.AbstractButton$Handler.actionPerformed(AbstractButton.java:2152)
at javax.swing.DefaultButtonModel.fireActionPerformed(DefaultButtonModel.java:420)
at javax.swing.DefaultButtonModel.setPressed(DefaultButtonModel.java:258)
at javax.swing.plaf.basic.BasicButtonListener.mouseReleased(BasicButtonListener.java:234)
at java.awt.AWTEventMulticaster.mouseReleased(AWTEventMulticaster.java:231)
at java.awt.Component.processMouseEvent(Component.java:5465)
at javax.swing.JComponent.processMouseEvent(JComponent.java:3052)
at java.awt.Component.processEvent(Component.java:5230)
at java.awt.Container.processEvent(Container.java:1961)
at java.awt.Component.dispatchEventImpl(Component.java:3933)
at java.awt.Container.dispatchEventImpl(Container.java:2019)
at java.awt.Component.dispatchEvent(Component.java:3781)
at java.awt.LightweightDispatcher.retargetMouseEvent(Container.java:4203)
at java.awt.LightweightDispatcher.processMouseEvent(Container.java:3883)
at java.awt.LightweightDispatcher.dispatchEvent(Container.java:3813)
at java.awt.Container.dispatchEventImpl(Container.java:2005)
at java.awt.Window.dispatchEventImpl(Window.java:1757)
at java.awt.Component.dispatchEvent(Component.java:3781)
at java.awt.EventQueue.dispatchEvent(EventQueue.java:463)
at java.awt.EventDispatchThread.pumpOneEventForHierarchy(EventDispatchThread.java:234)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:163)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:153)
at java.awt.Dialog+1.run(Dialog.java:514)
at java.awt.Dialog.show(Dialog.java:535)
at javax.swing.JFileChooser.showDialog(JFileChooser.java:717)
at sun.print.ServiceDialog.showFileChooser(ServiceDialog.java:407)
at sun.print.ServiceDialog.actionPerformed(ServiceDialog.java:362)
at javax.swing.AbstractButton.fireActionPerformed(AbstractButton.java:1834)
at javax.swing.AbstractButton$Handler.actionPerformed(AbstractButton.java:2152)
at javax.swing.DefaultButtonModel.fireActionPerformed(DefaultButtonModel.java:420)
at javax.swing.DefaultButtonModel.setPressed(DefaultButtonModel.java:258)
at javax.swing.plaf.basic.BasicButtonListener.mouseReleased(BasicButtonListener.java:234)
at java.awt.Component.processMouseEvent(Component.java:5465)
at javax.swing.JComponent.processMouseEvent(JComponent.java:3052)
at java.awt.Component.processEvent(Component.java:5230)
at java.awt.Container.processEvent(Container.java:1961)
at java.awt.Component.dispatchEventImpl(Component.java:3933)
at java.awt.Container.dispatchEventImpl(Container.java:2019)
at java.awt.Component.dispatchEvent(Component.java:3781)
at java.awt.LightweightDispatcher.retargetMouseEvent(Container.java:4203)
at java.awt.LightweightDispatcher.processMouseEvent(Container.java:3883)
at java.awt.LightweightDispatcher.dispatchEvent(Container.java:3813)
at java.awt.Container.dispatchEventImpl(Container.java:2005)
at java.awt.Window.dispatchEventImpl(Window.java:1757)
at java.awt.Component.dispatchEvent(Component.java:3781)
at java.awt.EventQueue.dispatchEvent(EventQueue.java:463)
at java.awt.EventDispatchThread.pumpOneEventForHierarchy(EventDispatchThread.java:234)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:163)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:153)
at java.awt.Dialog+1.run(Dialog.java:514)
at java.awt.event.InvocationEvent.dispatch(InvocationEvent.java:201)
at java.awt.EventQueue.dispatchEvent(EventQueue.java:461)
at java.awt.EventDispatchThread.pumpOneEventForHierarchy(EventDispatchThread.java:234)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:163)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:157)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:149)
at java.awt.EventDispatchThread.run(EventDispatchThread.java:110)

Comments
EVALUATION =============================== I could not reproduce the NPE but I noticed that the file dialog is always selecting the first file in the directory disregarding any file selected or typed in. This bug started to appear in the 1/17/04 2d nightly build after a bringover of some swing files. Assigning to swing for further evaluation. ###@###.### 2004-01-20 ==================================== Name: keR10081 Date: 01/22/2004 We can apply suggested fix to correct this behaviour. ###@###.### ====================================================================== Name: keR10081 Date: 02/02/2004 This bug would be fixed by fix for bug 4980406. So, this one would be closed as a duplicate. However I would like to mention that sun.print.ServiceDialog.java's class ValidatingFileChooser should check for null in its code, since it could easily become null and we would get the same exception. ###@###.### ======================================================================
24-08-2004

SUGGESTED FIX Name: keR10081 Date: 01/22/2004 ------- FilePane.java ------- *** /tmp/sccs.Khaa8Z Thu Jan 22 18:49:26 2004 --- FilePane.java Thu Jan 22 18:24:03 2004 *************** *** 1150,1155 **** --- 1150,1158 ---- applyEdit(); resetEditIndex(); clearSelection(); + if (list != null) { + list.setSelectedIndex(0); + } ensureIndexIsVisible(0); File currentDirectory = fc.getCurrentDirectory(); if (currentDirectory != null) { *************** *** 1239,1246 **** } public void clearSelection() { ! if (listSelectionModel != null && list != null) { ! list.setSelectedIndex(0); listSelectionModel.clearSelection(); } } --- 1242,1248 ---- } public void clearSelection() { ! if (listSelectionModel != null) { listSelectionModel.clearSelection(); } } ======================================================================
24-08-2004