[prev in list] [next in list] [prev in thread] [next in thread] 

List:       openjdk-2d-dev
Subject:    [OpenJDK 2D-Dev] [10] RFR JDK-8186987:NullPointerException in RasterPrinterJob without PrinterResolu
From:       Prasanta Sadhukhan <prasanta.sadhukhan () oracle ! com>
Date:       2017-08-31 10:20:35
Message-ID: 655a810c-0c64-5334-2ae9-6fa8a42e8ac6 () oracle ! com
[Download RAW message or body]

Hi All,

Please review a fix for an issue where it a NPE is seen when an attempt 
is made to print to Brother HL-2240D series 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.

Now, it seems in Brother HL-2240D series printer, it supports 3 
resolution [300, 600, HQ 1200] but for all these 3 resolutions, 
getDefaultPrinterSettings() returns -50 for yRes and Quality.
So, as per this code 
http://hg.openjdk.java.net/jdk10/client/jdk/file/dbb5b171a16b/src/java.desktop/windows/classes/sun/print/Win32PrintService.java#l1189
 res < 0 and no PrinterResolution object is instantiated so when RPJ 
accesses
printerResAttr.getCrossFeedResolution(ResolutionSyntax.DPI);     it causes 
NPE.

Proposed fix is to create a default lowly 300 dpi PrinterResolution if, 
for some reason, yRes and Quality from printer comes out -ve.
http://cr.openjdk.java.net/~psadhukhan/8186987/webrev.00/

Regards
Prasanta


[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic