Skip to content

Commit 6daca7e

Browse files
Renjithkannathprsadhuk
authored andcommitted
8268675: RTE from "Printable.print" propagates through "PrinterJob.print"
Reviewed-by: psadhukhan, prr
1 parent d7f4365 commit 6daca7e

File tree

2 files changed

+17
-19
lines changed

2 files changed

+17
-19
lines changed

src/java.desktop/share/classes/sun/print/RasterPrinterJob.java

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 1998, 2025, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 1998, 2026, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* This code is free software; you can redistribute it and/or modify it
@@ -1610,6 +1610,11 @@ public void print(PrintRequestAttributeSet attributes)
16101610
cancelDoc();
16111611
}
16121612

1613+
} catch (PrinterException pe) {
1614+
throw pe;
1615+
} catch (Throwable printError) {
1616+
throw (PrinterException)
1617+
new PrinterException().initCause(printError.getCause());
16131618
} finally {
16141619
// reset previousPaper in case this job is invoked again.
16151620
previousPaper = null;

test/jdk/java/awt/print/PrinterJob/ExceptionFromPrintableIsIgnoredTest.java

Lines changed: 11 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2021, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2021, 2026, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* This code is free software; you can redistribute it and/or modify it
@@ -21,15 +21,16 @@
2121
* questions.
2222
*/
2323

24-
/* @test
25-
@bug 8262731
26-
@key headful printer
27-
@summary Verify that "PrinterJob.print" throws the expected exception,
28-
if "Printable.print" throws an exception.
29-
@run main ExceptionFromPrintableIsIgnoredTest MAIN PE
30-
@run main ExceptionFromPrintableIsIgnoredTest MAIN RE
31-
@run main ExceptionFromPrintableIsIgnoredTest EDT PE
32-
@run main ExceptionFromPrintableIsIgnoredTest EDT RE
24+
/*
25+
* @test
26+
* @bug 8262731 8268675
27+
* @key printer
28+
* @summary Verify that "PrinterJob.print" throws the expected exception,
29+
* if "Printable.print" throws an exception.
30+
* @run main ExceptionFromPrintableIsIgnoredTest MAIN PE
31+
* @run main ExceptionFromPrintableIsIgnoredTest MAIN RE
32+
* @run main ExceptionFromPrintableIsIgnoredTest EDT PE
33+
* @run main ExceptionFromPrintableIsIgnoredTest EDT RE
3334
*/
3435

3536
import java.awt.Graphics;
@@ -64,14 +65,6 @@ public ExceptionFromPrintableIsIgnoredTest(
6465
"Test started. threadType='%s', exceptionType='%s'",
6566
threadType, exceptionType));
6667

67-
String osName = System.getProperty("os.name");
68-
boolean isOSX = osName.toLowerCase().startsWith("mac");
69-
if ((exceptionType == TestExceptionType.RE) && !isOSX) {
70-
System.out.println(
71-
"Currently this test scenario can be verified only on macOS.");
72-
return;
73-
}
74-
7568
printError = null;
7669

7770
if (threadType == TestThreadType.MAIN) {

0 commit comments

Comments
 (0)