changeset 15053:5fd466022aed

6218397: Printing to file does not throw a PrinterException if the file cannot be created Reviewed-by: prr, jdv
author psadhukhan
date Fri, 01 Jul 2016 10:54:18 +0530
parents d2ed88149cf3
children fc4d994fcd07
files src/java.desktop/share/classes/sun/print/PSPrinterJob.java src/java.desktop/share/classes/sun/print/RasterPrinterJob.java
diffstat 2 files changed, 9 insertions(+), 1 deletions(-) [+]
line wrap: on
line diff
--- a/src/java.desktop/share/classes/sun/print/PSPrinterJob.java	Thu Jun 30 23:26:42 2016 -0500
+++ b/src/java.desktop/share/classes/sun/print/PSPrinterJob.java	Fri Jul 01 10:54:18 2016 +0530
@@ -501,7 +501,7 @@
         // Note that we only open a file if it has been nominated by
         // the end-user in a dialog that we ouselves put up.
 
-        OutputStream output;
+        OutputStream output = null;
 
         if (epsPrinter == null) {
             if (getPrintService() instanceof PSStreamPrintService) {
@@ -526,6 +526,7 @@
                         spoolFile = new File(mDestination);
                         output =  new FileOutputStream(spoolFile);
                     } catch (IOException ex) {
+                        abortDoc();
                         throw new PrinterIOException(ex);
                     }
                 } else {
@@ -771,6 +772,10 @@
         if (mPSStream != null) {
             mPSStream.println(EOF_COMMENT);
             mPSStream.flush();
+            if (mPSStream.checkError()) {
+                abortDoc();
+                throw new PrinterException("Error while writing to file");
+            }
             if (mDestType != RasterPrinterJob.STREAM) {
                 mPSStream.close();
             }
--- a/src/java.desktop/share/classes/sun/print/RasterPrinterJob.java	Thu Jun 30 23:26:42 2016 -0500
+++ b/src/java.desktop/share/classes/sun/print/RasterPrinterJob.java	Fri Jul 01 10:54:18 2016 +0530
@@ -1627,6 +1627,9 @@
              (!f.isFile() || !f.canWrite())) ||
             ((pFile != null) &&
              (!pFile.exists() || (pFile.exists() && !pFile.canWrite())))) {
+            if (f.exists()) {
+                f.delete();
+            }
             throw new PrinterException("Cannot write to file:"+
                                        dest);
         }