RFR: 8378417: Printing All pages results in NPE for 1.1 PrintJob [v2]

Prasanta Sadhukhan psadhukhan at openjdk.org
Tue Feb 24 03:32:44 UTC 2026


On Mon, 23 Feb 2026 21:47:18 GMT, Alexey Ivanov <aivanov at openjdk.org> wrote:

>> src/java.desktop/share/classes/sun/print/PrintJobDelegate.java line 529:
>> 
>>> 527: 
>>> 528:         PageRanges range = (PageRanges)attributes.get(PageRanges.class);
>>> 529:         if (range != null) {
>> 
>> I wonder if this is right ?
>> Surely if the PageRanges is not there any more, we should update the JobAttributes to a default range ?
>> This would leave whatever stale value is present.
>
> I looked at the code review #29312 for [JDK-8373239](https://bugs.openjdk.org/browse/JDK-8373239)… and wondered whether that code should rather ensure `PageRanges.class` attribute is present instead of removing it and the range to the default value.
> 
> https://github.com/openjdk/jdk/blob/6b576235b84f51e273da44158bfcadbb48f51baa/src/java.desktop/windows/classes/sun/awt/windows/WPrinterJob.java#L1737-L1739

> I wonder if this is right ? Surely if the PageRanges is not there any more, we should update the JobAttributes to a default range ? This would leave whatever stale value is present.

Since null check is being frowned upon, I have modified [JDK-8373239](https://bugs.openjdk.org/browse/JDK-8373239) fix to not remove PageRanges attribute and set it to default value incase native code doesn't set `isRangeSet` parameter via JNI.

The default value of PageRanges according to spec  
https://docs.oracle.com/en/java/javase/25/docs/api/java.desktop/javax/print/attribute/standard/PageRanges.html

`In other words, the default value for the PageRanges attribute is always {{1, Integer.MAX_VALUE}}. ` 

and having Pageable.UNKNOWN_NUMBER_OF_PAGES will cause IllegalArgumentException 
https://github.com/openjdk/jdk/blob/f25d429c8d6d099666aefd698ed14628cce5b1cf/src/java.desktop/share/classes/javax/print/attribute/standard/PageRanges.java#L193-L194


but kept setPageRanges value same as Pageable.UNKNOWN_NUMBER_OF_PAGES to honour its spec

https://github.com/openjdk/jdk/blob/f25d429c8d6d099666aefd698ed14628cce5b1cf/src/java.desktop/share/classes/sun/print/RasterPrinterJob.java#L1847-L1858

Regarding test, since the problem is reproduced in 1.1 PrintJob by just selecting "ALL" in print dialog, which is the default selection, [and there is no need to verify actual print output] and since ScaledImagePrinting test uses default printdialog settings, it will reproduce the issue and it will also avoid another new manual printing test

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

PR Review Comment: https://git.openjdk.org/jdk/pull/29874#discussion_r2844282422


More information about the client-libs-dev mailing list