On Mon, 4 Jan 2021 20:31:56 GMT, Phil Race <[email protected]> wrote:
>> Prasanta Sadhukhan has updated the pull request incrementally with one
>> additional commit since the last revision:
>>
>> Fail the test if no printer is found
>
> 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]);
}
-------------
PR: https://git.openjdk.java.net/jdk/pull/1927