[prev in list] [next in list] [prev in thread] [next in thread]
List: openjdk-2d-dev
Subject: Re: [OpenJDK 2D-Dev] [13] JDK-8221411: NullPointerException in RasterPrinterJob without PrinterResol
From: Phil Race <philip.race () oracle ! com>
Date: 2019-03-27 15:50:56
Message-ID: 87d3a923-003a-3dac-6f64-7ca9e06db9ea () oracle ! com
[Download RAW message or body]
Printer drivers sometimes are hard to fathom.
I don't know if this means we are missing something but the fix seems
safe enough.
+1
-phil.
On 3/27/19 5:08 AM, Prasanta Sadhukhan wrote:
>
> Hi All,
>
> Please review a fix for an issue where a NPE is seen when an attempt
> is made to print without PrinterResolution attributes in HP Deskjet
> 1510 printer.
>
> 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.
>
> Bug: https://bugs.openjdk.java.net/browse/JDK-8221411
> webrev: http://cr.openjdk.java.net/~psadhukhan/8221411/webrev.0/
>
> Regards
> Prasanta
> [1]
> [https://msdn.microsoft.com/en-us/library/windows/desktop/dd183576(v=vs.85).aspx]
[Attachment #3 (text/html)]
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
</head>
<body text="#000000" bgcolor="#FFFFFF">
Printer drivers sometimes are hard to fathom.<br>
I don't know if this means we are missing something but the fix
seems safe enough.<br>
<br>
+1<br>
<br>
-phil.<br>
<br>
<br>
<br>
<div class="moz-cite-prefix">On 3/27/19 5:08 AM, Prasanta Sadhukhan
wrote:<br>
</div>
<blockquote type="cite"
cite="mid:596d6ffc-343f-da64-1884-2a067d48a4d1@oracle.com">
<meta http-equiv="content-type" content="text/html; charset=UTF-8">
<p>Hi All,</p>
Please review a fix for an issue where a NPE is seen when an
attempt is made to print without PrinterResolution attributes in
HP Deskjet 1510 printer.<br>
<br>
It seems when RasterPrinterJob#setAttributes() is called with no
PrinterResolution attribute set, it first checks if
PrinterResolution category is supported. <br>
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 <br>
[as "printer resolution attribute" object is null] <br>
It then goes to get the default resolution attribute via
getDefaultAttributeValue() which calls getDefaultPrinterSettings()
and <br>
use yRes,Quality from this printer to construct a
"PrinterResolution" object.<br>
<br>
JDK uses DocumentProperties function[1] to query the printer
configuration data in windows and pDevMode->dmFields is
initialized to 200bf43<br>
which corresponds to <br>
DM_ORIENTATION | DM_PAPERSIZE | DM_COPIES | DM_DEFAULTSOURCE |
DM_PRINTQUALITY | DM_COLOR | DM_DUPLEX | DM_YRESOLUTION |
DM_COLLATE | DM_NUP | DM_MEDIATYPE<br>
so even though DM_YRESOLUTION and DM_PRINTQUALITY indices are set,
<br>
it seems for HP Deskjet 1510 printer returns -3 for both
pDevMode->dmYResolution and pDevMode->dmPrintQuality<br>
<br>
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<br>
<pre style="background-color:#ffffff;color:#000000;font-family:'Courier \
New';font-size:7.2pt;"><span style="color:#000080;font-weight:bold;">if </span>(res \
> <span style="color:#0000ff;">0</span>) { <span \
style="color:#000080;font-weight:bold;">return new </span>PrinterResolution(res, res, \
PrinterResolution.<span \
style="color:#660e7a;font-weight:bold;font-style:italic;">DPI</span>); }</pre>
causing RasterPrinterJob#setAttributes to cause an NPE when it
tries to call <span \
style="color:#660e7a;font-weight:bold;">printerResAttr</span>.getCrossFeedResolution(ResolutionSyntax.<span
style="color:#660e7a;font-weight:bold;font-style:italic;">DPI</span>);<br>
<br>
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)<br>
<br>
Proposed fix is to check if printerResAttr is null or not so <span
style="color:#660e7a;font-weight:bold;">printerResAttr</span>.getCrossFeedResolution(ResolutionSyntax.<span
style="color:#660e7a;font-weight:bold;font-style:italic;">DPI</span>);
will not be called for bad values.<br>
<br>
Bug: <a class="moz-txt-link-freetext"
href="https://bugs.openjdk.java.net/browse/JDK-8221411"
moz-do-not-send="true">https://bugs.openjdk.java.net/browse/JDK-8221411</a><br>
webrev: <a class="moz-txt-link-freetext"
href="http://cr.openjdk.java.net/~psadhukhan/8221411/webrev.0/"
moz-do-not-send="true">http://cr.openjdk.java.net/~psadhukhan/8221411/webrev.0/</a><br>
<br>
Regards<br>
Prasanta<br>
[1] [<a class="moz-txt-link-freetext"
href="https://msdn.microsoft.com/en-us/library/windows/desktop/dd183576%28v=vs.85%29.aspx"
moz-do-not-send="true">https://msdn.microsoft.com/en-us/library/windows/desktop/dd183576(v=vs.85).aspx</a>]
</blockquote>
<br>
</body>
</html>
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic