提交 39b88e35 编写于 作者: D dav

7023011: Toolkit.getPrintJob(Frame,String,Properties) throws HE instead of specified NPE

Reviewed-by: dcherepanov, art
上级 e9f1dce7
......@@ -1157,12 +1157,9 @@ public abstract class Toolkit {
* takes JobAttributes and PageAttributes objects. This object
* may be updated to reflect the user's job choices on exit. May
* be null.
*
* @return a <code>PrintJob</code> object, or <code>null</code> if the
* user cancelled the print job.
* @throws NullPointerException if frame is null. This exception is
* always thrown when GraphicsEnvironment.isHeadless() returns
* true.
* @throws NullPointerException if frame is null
* @throws SecurityException if this thread is not allowed to initiate a
* print job request
* @see java.awt.GraphicsEnvironment#isHeadless
......@@ -1201,12 +1198,9 @@ public abstract class Toolkit {
* job. The attributes will be updated to reflect the user's
* choices as outlined in the PageAttributes documentation. May be
* null.
*
* @return a <code>PrintJob</code> object, or <code>null</code> if the
* user cancelled the print job.
* @throws NullPointerException if frame is null and either jobAttributes
* is null or jobAttributes.getDialog() returns
* JobAttributes.DialogType.NATIVE.
* @throws NullPointerException if frame is null
* @throws IllegalArgumentException if pageAttributes specifies differing
* cross feed and feed resolutions. Also if this thread has
* access to the file system and jobAttributes specifies
......@@ -1218,9 +1212,6 @@ public abstract class Toolkit {
* opportunity to select a file and proceed with printing.
* The dialog will ensure that the selected output file
* is valid before returning from this method.
* <p>
* This exception is always thrown when GraphicsEnvironment.isHeadless()
* returns true.
* @throws SecurityException if this thread is not allowed to initiate a
* print job request, or if jobAttributes specifies print to file,
* and this thread is not allowed to access the file system
......@@ -1236,10 +1227,6 @@ public abstract class Toolkit {
PageAttributes pageAttributes) {
// Override to add printing support with new job/page control classes
if (GraphicsEnvironment.isHeadless()) {
throw new IllegalArgumentException();
}
if (this != Toolkit.getDefaultToolkit()) {
return Toolkit.getDefaultToolkit().getPrintJob(frame, jobtitle,
jobAttributes,
......
......@@ -320,8 +320,7 @@ public class HeadlessToolkit extends Toolkit
// Should never happen
throw new HeadlessException();
}
throw new IllegalArgumentException(
"PrintJob not supported in a headless environment");
throw new NullPointerException("frame must not be null");
}
public PrintJob getPrintJob(Frame frame, String doctitle, Properties props)
......@@ -330,8 +329,7 @@ public class HeadlessToolkit extends Toolkit
// Should never happen
throw new HeadlessException();
}
throw new IllegalArgumentException(
"PrintJob not supported in a headless environment");
throw new NullPointerException("frame must not be null");
}
/*
......
......@@ -1222,8 +1222,8 @@ public final class XToolkit extends UNIXToolkit implements Runnable {
public PrintJob getPrintJob(final Frame frame, final String doctitle,
final Properties props) {
if (GraphicsEnvironment.isHeadless()) {
throw new IllegalArgumentException();
if (frame == null) {
throw new NullPointerException("frame must not be null");
}
PrintJob2D printJob = new PrintJob2D(frame, doctitle, props);
......@@ -1236,11 +1236,10 @@ public final class XToolkit extends UNIXToolkit implements Runnable {
public PrintJob getPrintJob(final Frame frame, final String doctitle,
final JobAttributes jobAttributes,
final PageAttributes pageAttributes) {
if (GraphicsEnvironment.isHeadless()) {
throw new IllegalArgumentException();
final PageAttributes pageAttributes)
{
if (frame == null) {
throw new NullPointerException("frame must not be null");
}
PrintJob2D printJob = new PrintJob2D(frame, doctitle,
......
......@@ -630,10 +630,10 @@ public class WToolkit extends SunToolkit implements Runnable {
public PrintJob getPrintJob(Frame frame, String doctitle,
JobAttributes jobAttributes,
PageAttributes pageAttributes) {
if (GraphicsEnvironment.isHeadless()) {
throw new IllegalArgumentException();
PageAttributes pageAttributes)
{
if (frame == null) {
throw new NullPointerException("frame must not be null");
}
PrintJob2D printJob = new PrintJob2D(frame, doctitle,
......
/*
@test
@bug 7023011
@library ../../../regtesthelpers
@build Sysout
@summary Toolkit.getPrintJob() throws wrong exceptions
@author andrei dmitriev: area=awt.headless
@run main GetPrintJob
*/
import java.awt.*;
import java.util.Properties;
import test.java.awt.regtesthelpers.Sysout;
/*
* In headfull mode we should always getting NPE on the getPrintJob() call if frame == null.
*/
public class GetPrintJob {
public static void main(String[] s) {
boolean stage1Passed = false;
boolean stage2Passed = false;
try {
Toolkit.getDefaultToolkit().getPrintJob(
(Frame) null, "title", new Properties());
} catch (NullPointerException e) {
stage1Passed = true;
Sysout.println("Stage 1 passed. getPrintJob(null, String, property) has thrown NPE.");
}
if (!stage1Passed) {
throw new RuntimeException("getPrintJob() should have thrown NPE but didn't.");
}
try {
Toolkit.getDefaultToolkit().getPrintJob(
(Frame) null, "title", new JobAttributes(), new PageAttributes());
} catch (NullPointerException e) {
stage2Passed = true;
Sysout.println("Stage 2 passed. getPrintJob(null, String, jobAttrs, pageAttr) has thrown NPE.");
}
if (!stage2Passed) {
throw new RuntimeException("getPrintJob() should have thrown NPE but didn't.");
}
Sysout.println("Test PASSED");
}
}
/*
@test
@bug 7023011
@library ../../../regtesthelpers
@build Sysout
@summary Toolkit.getPrintJob() throws wrong exceptions
@author andrei dmitriev: area=awt.headless
@run main/othervm -Djava.awt.headless=true GetPrintJobHeadless
*/
/*
* In headless mode we should always getting NPE on the getPrintJob() call
*/
import java.awt.*;
import java.util.Properties;
import test.java.awt.regtesthelpers.Sysout;
public class GetPrintJobHeadless {
public static void main(String[] s) {
boolean stage1Passed = false;
boolean stage2Passed = false;
try {
Toolkit.getDefaultToolkit().getPrintJob(
(Frame) null, "title", new Properties());
} catch (NullPointerException e) {
stage1Passed = true;
e.printStackTrace();
Sysout.println("Stage 1 passed. getPrintJob(null, String, property) has thrown NPE.");
}
if (!stage1Passed) {
throw new RuntimeException("getPrintJob() should have thrown NPE but didn't.");
}
try {
Toolkit.getDefaultToolkit().getPrintJob(
(Frame) null, "title", new JobAttributes(), new PageAttributes());
} catch (NullPointerException e) {
stage2Passed = true;
e.printStackTrace();
Sysout.println("Stage 2 passed. getPrintJob(null, String, jobAttrs, pageAttr) has thrown NPE.");
}
if (!stage2Passed) {
throw new RuntimeException("getPrintJob() should have thrown NPE but didn't.");
}
Sysout.println("Test PASSED");
}
}
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册