Skip to content

Commit 623ab91

Browse files
author
Roland Mesde
committed
8378417: Printing All pages results in NPE for 1.1 PrintJob
Reviewed-by: phh Backport-of: 8c4c8a1
1 parent 8ecc43c commit 623ab91

3 files changed

Lines changed: 65 additions & 2 deletions

File tree

src/java.desktop/windows/classes/sun/awt/windows/WPrinterJob.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1742,7 +1742,9 @@ private void setRangeCopiesAttribute(int from, int to, boolean isRangeSet,
17421742
attributes.add(new PageRanges(from, to));
17431743
setPageRange(from, to);
17441744
} else {
1745-
attributes.remove(PageRanges.class);
1745+
// Sets default values for PageRange attribute and setPageRange
1746+
attributes.add(new PageRanges(1,
1747+
Integer.MAX_VALUE));
17461748
setPageRange(Pageable.UNKNOWN_NUMBER_OF_PAGES,
17471749
Pageable.UNKNOWN_NUMBER_OF_PAGES);
17481750
}
Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
/*
2+
* Copyright (c) 2026, Oracle and/or its affiliates. All rights reserved.
3+
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4+
*
5+
* This code is free software; you can redistribute it and/or modify it
6+
* under the terms of the GNU General Public License version 2 only, as
7+
* published by the Free Software Foundation.
8+
*
9+
* This code is distributed in the hope that it will be useful, but WITHOUT
10+
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11+
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
12+
* version 2 for more details (a copy is included in the LICENSE file that
13+
* accompanied this code).
14+
*
15+
* You should have received a copy of the GNU General Public License version
16+
* 2 along with this work; if not, write to the Free Software Foundation,
17+
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18+
*
19+
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20+
* or visit www.oracle.com if you need additional information or have any
21+
* questions.
22+
*/
23+
24+
import java.awt.Frame;
25+
import java.awt.JobAttributes;
26+
import java.awt.PrintJob;
27+
import java.awt.Robot;
28+
import java.awt.Toolkit;
29+
import java.awt.event.KeyEvent;
30+
31+
/*
32+
* @test
33+
* @bug 8378417
34+
* @key headful printer
35+
* @summary Verifies No Exception is thrown when Printing "All" pages
36+
* @run main TestPrintNoException
37+
*/
38+
39+
public class TestPrintNoException {
40+
41+
public static void main(String[] args) throws Exception {
42+
Robot robot = new Robot();
43+
Thread t = new Thread (() -> {
44+
robot.delay(5000);
45+
robot.keyPress(KeyEvent.VK_ENTER);
46+
robot.keyRelease(KeyEvent.VK_ENTER);
47+
robot.waitForIdle();
48+
});
49+
50+
Frame testFrame = new Frame("print");
51+
try {
52+
t.start();
53+
PrintJob pj = Toolkit.getDefaultToolkit().getPrintJob(testFrame, null, null);
54+
if (pj != null) {
55+
pj.end();
56+
}
57+
} finally {
58+
testFrame.dispose();
59+
}
60+
}
61+
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323

2424
/*
2525
* @test
26-
* @bug 6575331 8297191 8373239
26+
* @bug 6575331 8297191 8373239 8378417
2727
* @key printer
2828
* @summary The specified pages should be printed.
2929
* @library /java/awt/regtesthelpers

0 commit comments

Comments
 (0)