提交 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 { ...@@ -1157,12 +1157,9 @@ public abstract class Toolkit {
* takes JobAttributes and PageAttributes objects. This object * takes JobAttributes and PageAttributes objects. This object
* may be updated to reflect the user's job choices on exit. May * may be updated to reflect the user's job choices on exit. May
* be null. * be null.
*
* @return a <code>PrintJob</code> object, or <code>null</code> if the * @return a <code>PrintJob</code> object, or <code>null</code> if the
* user cancelled the print job. * user cancelled the print job.
* @throws NullPointerException if frame is null. This exception is * @throws NullPointerException if frame is null
* always thrown when GraphicsEnvironment.isHeadless() returns
* true.
* @throws SecurityException if this thread is not allowed to initiate a * @throws SecurityException if this thread is not allowed to initiate a
* print job request * print job request
* @see java.awt.GraphicsEnvironment#isHeadless * @see java.awt.GraphicsEnvironment#isHeadless
...@@ -1201,12 +1198,9 @@ public abstract class Toolkit { ...@@ -1201,12 +1198,9 @@ public abstract class Toolkit {
* job. The attributes will be updated to reflect the user's * job. The attributes will be updated to reflect the user's
* choices as outlined in the PageAttributes documentation. May be * choices as outlined in the PageAttributes documentation. May be
* null. * null.
*
* @return a <code>PrintJob</code> object, or <code>null</code> if the * @return a <code>PrintJob</code> object, or <code>null</code> if the
* user cancelled the print job. * user cancelled the print job.
* @throws NullPointerException if frame is null and either jobAttributes * @throws NullPointerException if frame is null
* is null or jobAttributes.getDialog() returns
* JobAttributes.DialogType.NATIVE.
* @throws IllegalArgumentException if pageAttributes specifies differing * @throws IllegalArgumentException if pageAttributes specifies differing
* cross feed and feed resolutions. Also if this thread has * cross feed and feed resolutions. Also if this thread has
* access to the file system and jobAttributes specifies * access to the file system and jobAttributes specifies
...@@ -1218,9 +1212,6 @@ public abstract class Toolkit { ...@@ -1218,9 +1212,6 @@ public abstract class Toolkit {
* opportunity to select a file and proceed with printing. * opportunity to select a file and proceed with printing.
* The dialog will ensure that the selected output file * The dialog will ensure that the selected output file
* is valid before returning from this method. * 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 * @throws SecurityException if this thread is not allowed to initiate a
* print job request, or if jobAttributes specifies print to file, * print job request, or if jobAttributes specifies print to file,
* and this thread is not allowed to access the file system * and this thread is not allowed to access the file system
...@@ -1236,10 +1227,6 @@ public abstract class Toolkit { ...@@ -1236,10 +1227,6 @@ public abstract class Toolkit {
PageAttributes pageAttributes) { PageAttributes pageAttributes) {
// Override to add printing support with new job/page control classes // Override to add printing support with new job/page control classes
if (GraphicsEnvironment.isHeadless()) {
throw new IllegalArgumentException();
}
if (this != Toolkit.getDefaultToolkit()) { if (this != Toolkit.getDefaultToolkit()) {
return Toolkit.getDefaultToolkit().getPrintJob(frame, jobtitle, return Toolkit.getDefaultToolkit().getPrintJob(frame, jobtitle,
jobAttributes, jobAttributes,
......
...@@ -320,8 +320,7 @@ public class HeadlessToolkit extends Toolkit ...@@ -320,8 +320,7 @@ public class HeadlessToolkit extends Toolkit
// Should never happen // Should never happen
throw new HeadlessException(); throw new HeadlessException();
} }
throw new IllegalArgumentException( throw new NullPointerException("frame must not be null");
"PrintJob not supported in a headless environment");
} }
public PrintJob getPrintJob(Frame frame, String doctitle, Properties props) public PrintJob getPrintJob(Frame frame, String doctitle, Properties props)
...@@ -330,8 +329,7 @@ public class HeadlessToolkit extends Toolkit ...@@ -330,8 +329,7 @@ public class HeadlessToolkit extends Toolkit
// Should never happen // Should never happen
throw new HeadlessException(); throw new HeadlessException();
} }
throw new IllegalArgumentException( throw new NullPointerException("frame must not be null");
"PrintJob not supported in a headless environment");
} }
/* /*
......
...@@ -1222,8 +1222,8 @@ public final class XToolkit extends UNIXToolkit implements Runnable { ...@@ -1222,8 +1222,8 @@ public final class XToolkit extends UNIXToolkit implements Runnable {
public PrintJob getPrintJob(final Frame frame, final String doctitle, public PrintJob getPrintJob(final Frame frame, final String doctitle,
final Properties props) { final Properties props) {
if (GraphicsEnvironment.isHeadless()) { if (frame == null) {
throw new IllegalArgumentException(); throw new NullPointerException("frame must not be null");
} }
PrintJob2D printJob = new PrintJob2D(frame, doctitle, props); PrintJob2D printJob = new PrintJob2D(frame, doctitle, props);
...@@ -1236,11 +1236,10 @@ public final class XToolkit extends UNIXToolkit implements Runnable { ...@@ -1236,11 +1236,10 @@ public final class XToolkit extends UNIXToolkit implements Runnable {
public PrintJob getPrintJob(final Frame frame, final String doctitle, public PrintJob getPrintJob(final Frame frame, final String doctitle,
final JobAttributes jobAttributes, final JobAttributes jobAttributes,
final PageAttributes pageAttributes) { final PageAttributes pageAttributes)
{
if (frame == null) {
if (GraphicsEnvironment.isHeadless()) { throw new NullPointerException("frame must not be null");
throw new IllegalArgumentException();
} }
PrintJob2D printJob = new PrintJob2D(frame, doctitle, PrintJob2D printJob = new PrintJob2D(frame, doctitle,
......
...@@ -630,10 +630,10 @@ public class WToolkit extends SunToolkit implements Runnable { ...@@ -630,10 +630,10 @@ public class WToolkit extends SunToolkit implements Runnable {
public PrintJob getPrintJob(Frame frame, String doctitle, public PrintJob getPrintJob(Frame frame, String doctitle,
JobAttributes jobAttributes, JobAttributes jobAttributes,
PageAttributes pageAttributes) { PageAttributes pageAttributes)
{
if (GraphicsEnvironment.isHeadless()) { if (frame == null) {
throw new IllegalArgumentException(); throw new NullPointerException("frame must not be null");
} }
PrintJob2D printJob = new PrintJob2D(frame, doctitle, 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.
先完成此消息的编辑!
想要评论请 注册