[OpenJDK 2D-Dev] RFR: 8215537: [TEST_BUG] java/awt/print/PrinterJob/LandscapeStackOverflow.java fails by timeout [v2]

Prasanta Sadhukhan psadhukhan at openjdk.java.net
Wed Jan 6 04:29:11 UTC 2021


On Tue, 5 Jan 2021 16:34:11 GMT, Phil Race <prr at openjdk.org> wrote:

>> test/jdk/java/awt/print/PrinterJob/LandscapeStackOverflow.java line 50:
>> 
>>> 48:         PrintService defaultPrtSrv = PrintServiceLookup.lookupDefaultPrintService();
>>> 49:         if (printjob.getPrintService() == null || defaultPrtSrv == null) {
>>> 50:             throw new RuntimeException("No printer found");
>> 
>> We need to make this more robust.
>> The checks should be before we create the pritner job and should be to find ANY printer and none
>> throws the excepton, but if there is only a non-default one, set that as the printer for the job after creating the job.
>> 
>> That may not matter on Windows but on other platforms I am sure you can have printers, but not a default one.
>
>>         if (printService.length == 1) {
> 
> So if there are two, you do nothing ?
> 
> I was thinking of code like this
> 
> PrintService[] printService = PrinterJob.lookupPrintServices();
> if (printService.length == 0) {
>    throw new RuntimeException("no printer found");
> }
> PrinterJob printjob = PrinterJob.getPrinterJob();
> if  (printjob.getPrintService() == null) {
>     printjob.setPrintService(printService[0]);
> }

I was of the understanding that if there are multiple, then we have to choose one as default so defaultPrintService will not be null. But, the above code looks more apt.

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

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


More information about the 2d-dev mailing list