<AWT Dev> RFR: 8262731: [macOS] Exception from "Printable.print" is swallowed during "PrinterJob.print" [v2]

Anton Litvinov alitvinov at openjdk.java.net
Mon May 31 14:00:22 UTC 2021


On Sun, 30 May 2021 18:11:18 GMT, Phil Race <prr at openjdk.org> wrote:

>> Anton Litvinov has updated the pull request incrementally with one additional commit since the last revision:
>> 
>>   Second version of the fix
>
> test/jdk/java/awt/print/PrinterJob/ExceptionFromPrintableIsIgnoredTest.java line 120:
> 
>> 118:                     (exceptionType == TestExceptionType.PE)) ||
>> 119:                 ((printEx instanceof RuntimeException) &&
>> 120:                     (exceptionType == TestExceptionType.RE))) {
> 
> 1) I am fairly sure that I tested this case on Windows and nothing caught it so does this test work on Windows ?
> 
> 2) I raised the question / suggestion that should we not wrap these in a PrinterException ? 
> It at least needs to be thought through.

1. The test does not fail on Windows in all 4 tested scenarios. You can run this regression test on Windows and you will see in the test report in the test output that the test successfully throws the required "PrinterException" or "RuntimeException" from "java.awt.print.Printable.print​(Graphics, PageFormat, int)" and that the test successfully catches this "PrinterException" or "RuntimeException" and prints out it to "System.out" "PrintStream" in the test method "ExceptionFromPrintableIsIgnoredTest.runTest(final TestExceptionType)".

Line 115    printEx.printStackTrace(System.out);

This line in the test is done exactly as the evidence that the exception was really propagated from the method "PrinterJob.print()" and caught by the test. I verified that it is "true" on macOS, Windows, Linux.

I reported this in the code review and in JBS bug record itself that in JDK 17 and in JDK 8u291 and even in JDK 8-b132 on Windows and on Linux "PrinterJob.print()", which is called on EDT, propagates "PrinterException" and "RuntimeException" which are thrown from "Printable.print​(Graphics, PageFormat, int)" method. If you still do not trust this, then I suggest you just to recheck it yourself by any trustworthy mean in addition to this regression test and the purely manual test case "ExceptionFromPrintableIsIgnored.java" attached to the bug record.

2. By current moment in JDK versions on Windows and Linux the "RuntimeException" thrown from "Printable.print​(Graphics, PageFormat, int)" has been propagated through "PrinterJob.print()" as is without wrapping it into "PrinterException", as my experiments show even in JDK 8-b132 and in currently latest GA release of JDK 8 and in JDK 17.
 
>From my viewpoint not wrapping "RuntimeException" into "PrinterException" and propagating "RuntimeException" through "PrinterJob.print()" will just bring behavior of JDK on macOS into correspondence with existing behavior of JDK on Windows and Linux. If we wrap "RuntimeException" into "PrinterException" on macOS, then at some point in time somebody will need to change JDK code for Windows and Linux to also do the same wrapping of the exception which is currently not done. I do not insist on any variant.

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

PR: https://git.openjdk.java.net/jdk/pull/4036


More information about the awt-dev mailing list