On Thu, 5 Mar 2026 04:29:22 GMT, Prasanta Sadhukhan <[email protected]> 
wrote:

>> After [JDK-8373239](https://bugs.openjdk.org/browse/JDK-8373239):, Printing 
>> ALL pages results in NPE for 1.1 PrintJob because of lack of set pageranges 
>> citing
>> 
>> Exception in thread "AWT-EventQueue-0" java.lang.NullPointerException: 
>> Cannot invoke "javax.print.attribute.standard.PageRanges.getMembers()" 
>> because "range" is null
>>         at 
>> java.desktop/sun.print.PrintJobDelegate.updateAttributes(PrintJobDelegate.java:529)
>>         at 
>> java.desktop/sun.print.PrintJobDelegate.printDialog(PrintJobDelegate.java:424)
>>         at java.desktop/sun.print.PrintJob2D.printDialog(PrintJob2D.java:65)
>>         at 
>> java.desktop/sun.awt.windows.WToolkit.getPrintJob(WToolkit.java:644)
>>         at 
>> java.desktop/sun.awt.windows.WToolkit.getPrintJob(WToolkit.java:629) 
>> 
>> A null check is now added as we are now removing PageRange attribute if not 
>> set..It works fine for PrinterJob but fails for 1.1 PrintJob as 
>> PrintJobDelegate.updateAttributes called in 1.1 PrintJob use pageRange 
>> variable without checking if it exists.
>
> Prasanta Sadhukhan has updated the pull request incrementally with one 
> additional commit since the last revision:
> 
>   Add null check

Changes requested by aivanov (Reviewer).

test/jdk/java/awt/PrintJob/TestPrintNoException.java line 61:

> 59:     }
> 60: 
> 61:     private static Frame createUI() {

This fits nicely into 
[`splitUI`](https://cr.openjdk.org/~aivanov/PassFailJFrame/api/PassFailJFrame.Builder.html#splitUI(PassFailJFrame.PanelCreator))
 use case.

See 
[`PrintLatinCJKTest.java`](https://github.com/openjdk/jdk/blob/master/test/jdk/java/awt/print/PrinterJob/PrintLatinCJKTest.java)
 for an example, specifically:

https://github.com/openjdk/jdk/blob/dfea6eb9f84142aaa3e51181ea345e8575729ea2/test/jdk/java/awt/print/PrinterJob/PrintLatinCJKTest.java#L117

https://github.com/openjdk/jdk/blob/dfea6eb9f84142aaa3e51181ea345e8575729ea2/test/jdk/java/awt/print/PrinterJob/PrintLatinCJKTest.java#L68-L92

test/jdk/java/awt/PrintJob/TestPrintNoException.java line 65:

> 63:         Button b = new Button("Print");
> 64:         b.addActionListener(new ActionListener() {
> 65:             public void actionPerformed(ActionEvent e) {

@DamonGuy advocated using lambda expressions instead of anonymous class, and I 
agree that the code becomes less verbose.


b.addActionListener((e) -> {
});

test/jdk/java/awt/PrintJob/TestPrintNoException.java line 75:

> 73:                     PassFailJFrame.log(ex.toString());
> 74:                     return;
> 75:                 }

An exception means the test fails, doesn't it?

-------------

PR Review: https://git.openjdk.org/jdk/pull/29874#pullrequestreview-3895789004
PR Review Comment: https://git.openjdk.org/jdk/pull/29874#discussion_r2889401044
PR Review Comment: https://git.openjdk.org/jdk/pull/29874#discussion_r2889480867
PR Review Comment: https://git.openjdk.org/jdk/pull/29874#discussion_r2889484074

Reply via email to