JDK-8221411 : NullPointerException in RasterPrinterJob without PrinterResolution
  • Type: Bug
  • Component: client-libs
  • Sub-Component: 2d
  • Affected Version: 11.0.2
  • Priority: P3
  • Status: Resolved
  • Resolution: Fixed
  • OS: windows_10
  • CPU: x86_64
  • Submitted: 2019-03-25
  • Updated: 2019-06-28
  • Resolved: 2019-03-28
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.
JDK 11 JDK 13
11.0.5-oracleFixed 13 b15Fixed
Related Reports
Duplicate :  
Relates :  
Description
ADDITIONAL SYSTEM INFORMATION :
Windows 10, OpenJDK 64-Bit Server VM 11.0.2

A DESCRIPTION OF THE PROBLEM :
Printing to HP Deskjet 1510 printer fails with 

java.lang.NullPointerException
	at java.desktop/sun.print.RasterPrinterJob.setAttributes(RasterPrinterJob.java:1280)
	at java.desktop/sun.awt.windows.WPrinterJob.setAttributes(WPrinterJob.java:696)
	at java.desktop/sun.print.RasterPrinterJob.print(RasterPrinterJob.java:1550)
	at java.desktop/sun.print.RasterPrinterJob.print(RasterPrinterJob.java:1483)

This problem has been reported before as https://bugs.openjdk.java.net/browse/JDK-8186987 and has been and currently still is marked as fixed for Java 10. However, the error still occurs for Java 11! This is not much of a surprise, because the inital fix http://hg.openjdk.java.net/jdk10/client/jdk/file/dbb5b171a16b/src/java.desktop/windows/classes/sun/print/Win32PrintService.java#l1189 has been stripped from the corresponding repository! I think you should at least re-open issues if you strip away the corresponding fixes.

Finally, a very simple fix for this issue would be:
src/java.desktop/share/classes/sun/print/RasterPrinterJob.java
1279,1282c1279,1284
<             double xr =
<                printerResAttr.getCrossFeedResolution(ResolutionSyntax.DPI);
<             double yr = printerResAttr.getFeedResolution(ResolutionSyntax.DPI);
<             setXYRes(xr, yr);
---
>             if (isSupportedValue(printerResAttr,  attributes)) {
>                 double xr =
>                    printerResAttr.getCrossFeedResolution(ResolutionSyntax.DPI);
>                 double yr = printerResAttr.getFeedResolution(ResolutionSyntax.DPI);
>                 setXYRes(xr, yr);
>             }

REGRESSION : Last worked in version 8u201

STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
see https://bugs.openjdk.java.net/browse/JDK-8186987

EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
see https://bugs.openjdk.java.net/browse/JDK-8186987
ACTUAL -
see https://bugs.openjdk.java.net/browse/JDK-8186987

---------- BEGIN SOURCE ----------
see https://bugs.openjdk.java.net/browse/JDK-8186987
---------- END SOURCE ----------

CUSTOMER SUBMITTED WORKAROUND :
see https://bugs.openjdk.java.net/browse/JDK-8186987

FREQUENCY : always



Comments
Fix request (11u): Request backport of this item to OpenJDK 11u for parity with Oracle 11.0.5. Fix applies cleanly. Will be run through SAP test system for regression testing.
22-06-2019

It seems when RasterPrinterJob#setAttributes() is called with no PrinterResolution attribute set, it first checks if PrinterResolution category is supported. If it is supported, then it sees if the supplied resolution value is supported. Now, since no PrinterResolution attribute is set, so isSupportedValue() returns false [as "printer resolution attribute" object is null] It then goes to get the default resolution attribute via getDefaultAttributeValue() which calls getDefaultPrinterSettings() and use yRes,Quality from this printer to construct a "PrinterResolution" object. JDK uses DocumentProperties function[1] to query the printer configuration data in windows and pDevMode->dmFields is initialized to 200bf43 which corresponds to DM_ORIENTATION | DM_PAPERSIZE | DM_COPIES | DM_DEFAULTSOURCE | DM_PRINTQUALITY | DM_COLOR | DM_DUPLEX | DM_YRESOLUTION | DM_COLLATE | DM_NUP | DM_MEDIATYPE so even though DM_YRESOLUTION and DM_PRINTQUALITY indices are set, it seems for HP Deskjet 1510 printer returns -3 for both pDevMode->dmYResolution and pDevMode->dmPrintQuality so then Win32PrintService#getDefaultAttributeValue() checks for yRes,Quality and if they are < 0 then it does not instantiate PrinterResolution class ie printerResAttr object is null if (res > 0) { return new PrinterResolution(res, res, PrinterResolution.DPI); } causing RasterPrinterJob#setAttributes to cause an NPE when it tries to call printerResAttr.getCrossFeedResolution(ResolutionSyntax.DPI); We have seen similar issue for Brother HL-2240D series printer, where DM_YRESOLUTION and DM_PRINTQUALITY was not set in dmFields even though pDevMode->dmYResolution and pDevMode->dmPrintQuality was populated so we check for those values and store that but here the values itself are -ve so it does not get stored and ultimately resulted in returning GETDEFAULT_ERROR(-50) Proposed fix is to check if printerResAttr is null or not so printerResAttr.getCrossFeedResolution(ResolutionSyntax.DPI); will not be called for bad values.
27-03-2019

Reported with Windows 10, and OpenJDK 11.0.2 , Printing to HP Deskjet 1510 printer fails with java.lang.NullPointerException The issue is reportedly fixed in JDK 10 courtesy JDK-8186987, however is still active in JDK 11.
25-03-2019