[OpenJDK 2D-Dev] [9] RFR: JDK-8066139, , Null return from PrintJob.getGraphics() running closed/java/awt/PrintJob/HighResTest/HighResTest.java

prasanta sadhukhan prasanta.sadhukhan at oracle.com
Wed Mar 16 08:46:56 UTC 2016


Hi Jay,

Updated testcase
http://cr.openjdk.java.net/~psadhukhan/8066139/webrev.03/

Regards
Prasanta
On 3/16/2016 12:58 PM, Jayathirth D V wrote:
>
> HI Prasanta,
>
> Changes are fine. Both the print dialogs are coming and there is no NPE.
>
> In test case please change copyright year to 2016 and also it is 
> better to have jtreg comments before import statements for readability.
>
> Thanks,
>
> Jay
>
> *From:*Phil Race
> *Sent:* Wednesday, March 16, 2016 3:45 AM
> *To:* prasanta sadhukhan
> *Cc:* 2d-dev at openjdk.java.net
> *Subject:* Re: [OpenJDK 2D-Dev] [9] RFR: JDK-8066139, , Null return 
> from PrintJob.getGraphics() running 
> closed/java/awt/PrintJob/HighResTest/HighResTest.java
>
> On 03/10/2016 02:34 AM, prasanta sadhukhan wrote:
>
>     Hi Phil,
>
>     Please find the modified webrev
>     http://cr.openjdk.java.net/~psadhukhan/8066139/webrev.02/
>     <http://cr.openjdk.java.net/%7Epsadhukhan/8066139/webrev.02/>
>
>
> +1
>
>
>     I tested in Mac too but there it seems to be working (ie no NPE)
>     without and with this fix.
>
>
> The mac code is sufficiently different that it is not a surprise that 
> it behaves differently.
>
>
>
>     For issue seen on windows , I have raised a bug JDK-8151589
>     <https://bugs.openjdk.java.net/browse/JDK-8151589> (strangely it
>     is not seen in jdk1.8.0_76 but seen from  1.9.0-ea-b01 onwards,
>     can you tell me what is the release version before b01?]
>
>
> That suggests a bug introduced before 8GA, fixed in an 8-update, but 
> not in 9.
> But I find that a bit unlikely and I don't want to speculate more. It 
> just needs investigation.
>
> -phil.
>
>
>
>     Regards
>     Prasanta
>
>     On 3/8/2016 9:45 PM, Philip Race wrote:
>
>         > However, I am finding a strange issue with and without this
>         fix too. The "Center" string is not printed
>
>         Sounds completely unrelated to anything to do with the NPE bug.
>
>         It is probably appropriate to file that as a separate bug.
>         No big surprise that the behaviour is platform-specific as there
>         is a lot of difference in Windows vs Linux (or vs Mac) in the
>         printing code.
>
>         -phil.
>
>         On 3/8/16, 2:30 AM, prasanta sadhukhan wrote:
>
>             On 3/8/2016 2:17 AM, Phil Race wrote:
>
>                 I don't think starting a new thread can be right. That
>                 would re-invoke
>                 printerJob.print() which even if you can reuse a
>                 PrinterJob (something that
>                 was never set out in spec.) you are surely getting a
>                 new spool job .. not
>                 a continuation. There a couple of other things I am
>                 not sure about either.
>
>                 I've looked into this - only on Linux - and I believe
>                 the issue is that
>                 the test program has decided up-front how many pages
>                 it is going to
>                 print and it is paying no attention to the selected
>                 page ranges.
>                 Not what the 'user' asked for but it is perfectly
>                 within its rights to do so.
>
>                 However the 2D PrinterJob operates in a way where it
>                 calls back
>                 asking for the specific pages it wants to be printed
>                 and there the
>                 app. must comply. The PrinterJob terminates once it
>                 has done.
>
>                 In the case when the 2D PrinterJob is being used to
>                 'run' a
>                 PrintJob then it must *never* return until the
>                 application has
>                 called "end" - or some exception occurs.
>
>                 So we need to remove the elements that will cause the
>                 job to exit.
>
>                 ---
>                 a/src/java.desktop/share/classes/sun/print/PrintJob2D.java
>                 +++
>                 b/src/java.desktop/share/classes/sun/print/PrintJob2D.java
>                 @@ -995,6 +995,7 @@
>                      public void run() {
>
>                          try {
>                 +            attributes.remove(PageRanges.class);
>                              printerJob.print(attributes);
>                          } catch (PrinterException e) {
>                              //REMIND: need to store this away and not
>                 rethrow it.
>                 diff --git
>                 a/src/java.desktop/share/classes/sun/print/RasterPrinterJob.java
>                 b/src/java.desktop/share/classes/sun/print/RasterPrinterJob.java
>                 ---
>                 a/src/java.desktop/share/classes/sun/print/RasterPrinterJob.java
>                 +++
>                 b/src/java.desktop/share/classes/sun/print/RasterPrinterJob.java
>                 @@ -1172,6 +1172,7 @@
>                          pageRangesAttr =
>                 (PageRanges)attributes.get(PageRanges.class);
>                          if (!isSupportedValue(pageRangesAttr,
>                 attributes)) {
>                              pageRangesAttr = null;
>                 +            setPageRange(-1, -1);
>                          } else {
>                              if
>                 ((SunPageSelection)attributes.get(SunPageSelection.class)
>                                       == SunPageSelection.RANGE) {
>
>
>                 This works for me on Linux although
>                 a) I have not tried Windows)
>
>             I tried on windows. The NPE is not seen and it prints 2 pages.
>             However, I am finding a strange issue with and without
>             this fix too. The "Center" string is not printed in the
>             1st page in both "Portrait" and "Landscape" mode (although
>             the rectangles are printed) but is printed in the 2nd page.
>             I do not find this issue in linux.
>
>             Regards
>             Prasanta
>
>                 b) I have not verified if there are no negative
>                 consequences from the 2nd change.
>
>                 -phil.
>
>                 On 03/01/2016 03:14 AM, prasanta sadhukhan wrote:
>
>                     Hi Phil,
>
>                     Please find an updated webrev:
>                     http://cr.openjdk.java.net/~psadhukhan/8066139/webrev.01/
>                     <http://cr.openjdk.java.net/%7Epsadhukhan/8066139/webrev.01/>
>
>                     It seems if printerJobThread finished printing, it
>                     will set graphicsToBeDrawn/graphicsDrawn ArrayList
>                     to null resulting in getGraphics() returning null
>                     in the 2nd iteration causing NPE so
>                      I have modified printerJobThread#run so that when
>                     it has finished printing, do not set the arrayList
>                     to null but set a flag. In getGraphics(), I check
>                     that flag and start a new printerJobThread to
>                     handle the next printing.
>                     I have tested "All" and "Pages" selection.
>
>                     Regards
>                     Prasanta
>
>                     On 2/22/2016 1:35 PM, Philip Race wrote:
>
>                         > It seems this behaviour is same in linux too
>                         for this HighResTest testcase.
>
>                         OK that is good information .. so is not
>                         really a regression from 8061267
>                         <https://bugs.openjdk.java.net/browse/JDK-8061267>
>                         as that is not in
>                         any way touching linux .. it is a pre-existing
>                         issue in a code path that was not being tested.
>
>                         -phil.
>
>                         On 2/22/16, 11:59 AM, prasanta sadhukhan wrote:
>
>                             Hi Phil,
>
>                             >>Additionally, have you tried running the
>                             original test case provided with 8061267
>                             >> against your fix ?
>                             The 8061267 testcase behaves similarly
>                             before and after my fix.
>
>                             >> If I manually select it, (ie select
>                             that "Pages" radio button) then press print,
>                             >> then voila, the NPE is back!
>                             It seems this behaviour is same in linux
>                             too for this HighResTest testcase.
>
>                             Regards
>                             Prasanta
>
>                             On 2/20/2016 1:55 AM, Phil Race wrote:
>
>                                 I am having trouble building JDK 9 at
>                                 the moment so i applied 8061267 to
>                                 jdk8u-dev
>                                 and was able to reproduce the
>                                 regression and have a couple of
>                                 observations
>
>                                 - I am now seeing the NPE after the
>                                 first page as you did .. puzzling.
>                                 - I next applied your fix but still
>                                 see the NPE !
>
>                                 It appears that all your fix did is
>                                 stop the "PD_PAGENUMS"  flag being
>                                 automatically
>                                 set. If I manually select it, (ie
>                                 select that "Pages" radio button) then
>                                 press print,
>                                 then voila, the NPE is back!
>
>                                 -phil.
>
>
>                                 On 02/19/2016 10:53 AM, Phil Race wrote:
>
>                                     I am not sure I can be correctly
>                                     understanding the fix as the
>                                     ramification seems
>                                     to be that if the users wants to
>                                     print only Page 3 of a 10 page
>                                     document and so sets
>                                     from page=3 and to page=3, that
>                                     this request will be ignored and
>                                     all pages will
>                                     be printed .. can you test such a
>                                     scenario.
>
>                                     Additionally, have you tried
>                                     running the original test case
>                                     provided with 8061267
>                                     against your fix ?
>
>                                     Also when I ran the HighResTest on
>                                     a current build I saw a null
>                                     graphics on
>                                     the very first call to
>                                     getGraphics() which is different
>                                     than what I interpret
>                                     you as saying - you see the null
>                                     *after* the first page is printed.
>
>                                     -phil.
>
>                                     On 02/19/2016 01:18 AM, prasanta
>                                     sadhukhan wrote:
>
>                                         Hi Phil, All,
>
>                                         Bug:
>                                         https://bugs.openjdk.java.net/browse/JDK-8066139
>                                         webrev:
>                                         http://cr.openjdk.java.net/~psadhukhan/8066139/webrev.00/
>                                         <http://cr.openjdk.java.net/%7Epsadhukhan/8066139/webrev.00/>
>
>                                         It was seen after fix of
>                                         JDK-8061267
>                                         <https://bugs.openjdk.java.net/browse/JDK-8061267>:
>                                         PrinterJob: Specified Page
>                                         Ranges not displayed in
>                                         Windows Native Print Dialog
>                                         the
>                                         closed/java/awt/PrintJob/HighResTest/HighResTest.java
>                                         was failing with NPE when
>                                         PrinterJob.getGraphics() is
>                                         called the 2nd time before
>                                         calling PrinterJob.end().
>
>                                         The above fix caused this
>                                         regression because it sets the
>                                         PD_PAGENUMS flag for windows
>                                         PrintDlg struct which causes
>                                         *Pages* radio button to be
>                                         selected in print dialog.
>                                         However, fromPage and toPage
>                                         was both set to 1 so after the
>                                         1st page is printed,
>                                         RasterPrinterJob.print(attributes)
>                                         finishes and
>                                         graphicsToBeDrawn.closeWhenEmpty()
>                                         gets called
>                                         http://hg.openjdk.java.net/jdk9/client/jdk/file/d8def65c6c00/src/java.desktop/share/classes/sun/print/PrintJob2D.java#l1006
>
>                                         which sets the queue to null
>                                         so when
>                                         PrinterJob2D#getGraphics()
>                                         calls graphicsToBeDrawn.pop()
>                                         it sees queue to be null and
>                                         sets graphics object to be null so
>                                         PrinterJob.getGraphics() gets
>                                         null and g.drawLine in
>                                         testcase causes NPE since g is
>                                         null.
>
>                                         Fix was done to set the
>                                         PD_PAGENUMS flag only when
>                                         toPage is more than fromPage
>                                         in which case, "All" will be
>                                         selected in printer dialog and
>                                         RasterPrinterJob.print() will
>                                         finish only after printing all
>                                         the pages.
>
>                                         Regards
>                                         Prasanta
>

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.openjdk.java.net/pipermail/2d-dev/attachments/20160316/90b2570a/attachment.html>


More information about the 2d-dev mailing list