JDK-6574633 : native printDialog crashes when changing printer
  • Type: Bug
  • Component: client-libs
  • Sub-Component: 2d
  • Affected Version: 5.0u2
  • Priority: P3
  • Status: Resolved
  • Resolution: Fixed
  • OS: windows_vista
  • CPU: x86
  • Submitted: 2007-06-27
  • Updated: 2010-12-08
  • Resolved: 2009-03-24
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 JDK 7
5.0u19 b01Fixed 6u10Fixed 7Fixed
Related Reports
Relates :  
Description
This is related to 6358747.  
Occurs in 1.5 update but not in 1.6.

To reproduce:
Run the following test and when the printDialog is shown, change the printer.

import java.awt.Graphics;
import java.awt.print.*;
import javax.swing.*;
import javax.swing.SwingUtilities;

public class CrashJVM
{ static public void main(String[] args)
  {  new AFrame().setVisible(true);
  }
  private static class AFrame extends JFrame
  {  public AFrame()
     {  final APanel aPanel = new APanel();
        SwingUtilities.invokeLater(new Runnable()
             {   public void run()
                 { aPanel.startPrint();
                 }
             });
     }
  }
  private static class APanel extends JPanel
  {  private APrintable report;
     public APanel()
     {   report = new APrintable();
     }
     public Book getBook(PageFormat format)
     {  return report.getBook(format);
     }
     public void startPrint()
     {  PrinterJob job = PrinterJob.getPrinterJob();
        Paper a4Paper = new Paper();
        a4Paper.setSize(595, 840);
        a4Paper.setImageableArea(40, 40, 515, 760);
        PageFormat pageFormat = job.defaultPage();
        pageFormat.setOrientation(PageFormat.PORTRAIT);
        pageFormat.setPaper(a4Paper);
		for (int i=0; i<4; ++i) {
        //pageFormat = job.pageDialog(pageFormat);
        //job.setPageable(getBook(pageFormat));
			job.printDialog(); // <-- crashes the JVM
		}
     }
     private class APrintable extends JPanel implements Printable
     {  public Book getBook(PageFormat format)
        {  return new PrintBook(format);
        }
        public int print(Graphics g, PageFormat format, int page)
        {  return PAGE_EXISTS;
        }
        private class PrintBook extends Book
        {  public PrintBook(PageFormat format)
           { append(APrintable.this, format, 1);
           }
        }
     }
  }
}

RESULT:
Crash on msctf.ime

Comments
EVALUATION Same cause as 6358747 except that we missed the case when we switch the printers. The native call to change the printer frees the hDevmode, hDevnames handles which may have already been freed by PrintDlg..
03-07-2007