JDK-8230640 : Canceling an octet-stream Printjob as byte array fails
  • Type: Bug
  • Component: client-libs
  • Sub-Component: 2d
  • Affected Version: 8,11,12,13,14
  • Priority: P3
  • Status: Open
  • Resolution: Unresolved
  • OS: windows_10
  • CPU: x86_64
  • Submitted: 2019-08-20
  • Updated: 2019-09-11
The Version table provides details related to the release that this issue/RFE will be addressed.

Unresolved : Release in which this issue/RFE will be addressed.
Resolved: Release in which this issue/RFE has been resolved.
Fixed : Release in which this issue/RFE has been fixed. The release containing this fix may be available for download as an Early Access Release or a General Availability Release.

To download the current JDK release, click here.
Other
tbdUnresolved
Description
ADDITIONAL SYSTEM INFORMATION :
OS: Microsoft Windows 10 Education
OS Version: 10.0.17763 Build 17763
Java Runtime Information: 12.0.1

A DESCRIPTION OF THE PROBLEM :
If using the javax.print library to create a printjob with a DocFlavor "application/octet-stream" and  className "[B", the canceling of  this job throws always a javax.print.PrintException with the message: 
Job could not be cancelled.
	at java.desktop/sun.print.Win32PrintJob.cancel(Win32PrintJob.java:747) 
       ....



STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
Create a byte array (with random data)
Create a DocFlavor with mimeType = "application/octet-stream" and className = "[B"
Create a javax.print.Doc with the byte array, the DocFlavor and for the attributes null
Create a Printservice
Create a PrintRequestAttributeSet
Create a DocPrintJob with the PrintService (service.createPrintJob())
Call (PrintJob).print with the Doc and the PrintRequestAttributeSet
Create a CancelablePrintJob from the previous printjob (cast the job to
(CancelablePrintJob))
Call cancel


EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
Job is canceled.
ACTUAL -
javax.print.PrintException: Job could not be cancelled.
	at java.desktop/sun.print.Win32PrintJob.cancel(Win32PrintJob.java:747)

---------- BEGIN SOURCE ----------
import javax.print.CancelablePrintJob;
import javax.print.Doc;
import javax.print.DocFlavor;
import javax.print.DocPrintJob;
import javax.print.PrintException;
import javax.print.PrintService;
import javax.print.PrintServiceLookup;
import javax.print.SimpleDoc;
import javax.print.attribute.HashPrintRequestAttributeSet;
import javax.print.attribute.PrintRequestAttributeSet;
import javax.print.attribute.standard.JobName;

public class Main {
    public static void main(final String[] args) {
        byte[] test = {0x30, 0x31, 0x32};
        DocFlavor docflavor = new DocFlavor("application/octet-stream", "[B");
        Doc doc = new SimpleDoc(test, docflavor, null);
        // Just a dummyprinter
        PrintService service = PrintServiceLookup.lookupDefaultPrintService();
        PrintRequestAttributeSet asset = new HashPrintRequestAttributeSet();
        asset.add(new JobName("Testprinting", null));
        DocPrintJob job = service.createPrintJob();
        try {
            job.print(doc, asset);
        } catch (PrintException p) {
            p.printStackTrace();
        }

        CancelablePrintJob cancelableJob = (CancelablePrintJob) job;
        try {
            cancelableJob.cancel();
        } catch (PrintException e) {
            e.printStackTrace();
        }
    }
}
---------- END SOURCE ----------

FREQUENCY : always



Comments
Using the javax.print library to create a printjob with a DocFlavor "application/octet-stream" and className "[B", the canceling of this job always throws a javax.print.PrintException with the message: Job could not be cancelled. at java.desktop/sun.print.Win32PrintJob.cancel(Win32PrintJob.java:747) When checked in Windows 10, issue is frequently reproducible with reported JDK version 12.0.1 Result: ============= 8: Fail 8u221: Fail 12.0.1: Fail 13 ea b33: Fail 14 ea b12: Fail To verify, run the attached test case with respective JDK version. > java Main javax.print.PrintException: Job could not be cancelled. at sun.print.Win32PrintJob.cancel(Win32PrintJob.java:750) at Main.main(Main.java:31)
05-09-2019