JDK-8038142 : [macosx] Graphics2d.drawImage is failing when printing for mac only
  • Type: Bug
  • Component: client-libs
  • Sub-Component: 2d
  • Affected Version: 7u25,8,9
  • Priority: P3
  • Status: Closed
  • Resolution: Duplicate
  • OS: os_x
  • CPU: x86
  • Submitted: 2014-03-12
  • Updated: 2017-01-31
  • Resolved: 2017-01-31
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
tbd_majorResolved
Related Reports
Duplicate :  
Duplicate :  
Relates :  
Description
FULL PRODUCT VERSION :
JDK 7u51 - is found also in JDK 7u25

ADDITIONAL OS VERSION INFORMATION :
Mac OSX 10.9.1

A DESCRIPTION OF THE PROBLEM :
When printing with a mac if Graphics2D.drawImage is called an error is thrown in sun.java2d.CRenderer.doImage.  This does not appear running the same code on a windows machine.  This has been seen since upgrading to Java 7 for macs, and was previously working in Java 6.  Also tried on a RC version of Java 8 and the problem still seems to be there.

REGRESSION.  Last worked in version 6u45

ADDITIONAL REGRESSION INFORMATION: 
JDK 6u45

STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
Create a program that shows a print screen on a mac and select PDF -> Open PDF in Preview.  In the print method of the class that implements Printable call graphics.drawImage and it will cause an error.  This same code will work fine on a Windows machine.

EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
Was expecting a PDF to show with the preview of what was to be printed.
ACTUAL -
Just got an error message.

ERROR MESSAGES/STACK TRACES THAT OCCUR :
2014-03-12 09:48:20.427 java[9531:1903] Cocoa AWT: Not running on AppKit thread 0 when expected. (
	0   libosxapp.dylib                     0x00000001543b895f +[ThreadUtilities getJNIEnv] + 34
	1   liblwawt.dylib                      0x000000015434550f syncFromJavaPixels + 1842
	2   liblwawt.dylib                      0x000000015434590b LockImage + 75
	3   liblwawt.dylib                      0x000000015433fe46 Java_sun_java2d_CRenderer_doImage + 170
	4   ???                                 0x00000001062114b9 0x0 + 4397798585
	5   ???                                 0x00000001061ff0d8 0x0 + 4397723864
)
2014-03-12 09:48:20.427 java[9531:1903] 	Please file a bug report at http://java.net/jira/browse/MACOSX_PORT with this message and a reproducible test case.
2014-03-12 09:48:20.432 java[9531:1903] java.lang.StackOverflowError
	at sun.java2d.CRenderer.doImage(Native Method)
	at sun.java2d.OSXSurfaceData.blitImage(OSXSurfaceData.java:1025)
	at sun.java2d.CRenderer.blitImage(CRenderer.java:461)
	at sun.java2d.CRenderer.copyImage(CRenderer.java:479)
	at sun.java2d.CRenderer.copyImage(CRenderer.java:545)
	at sun.java2d.pipe.ValidatePipe.copyImage(ValidatePipe.java:196)
	at sun.java2d.SunGraphics2D.copyImage(SunGraphics2D.java:3080)
	at sun.java2d.SunGraphics2D.drawImage(SunGraphics2D.java:3121)
	at sun.java2d.SunGraphics2D.drawImage(SunGraphics2D.java:3065)
	at sun.print.ProxyGraphics2D.drawImage(ProxyGraphics2D.java:856)
	at PrintTest.print(PrintTest.java:25)
	at sun.lwawt.macosx.CPrinterJob$4.run(CPrinterJob.java:593)
	at sun.lwawt.macosx.CPrinterJob.printToPathGraphics(CPrinterJob.java:607)
	at sun.lwawt.macosx.CPrinterJob.printLoop(Native Method)
	at sun.lwawt.macosx.CPrinterJob.print(CPrinterJob.java:261)
	at sun.print.RasterPrinterJob.print(RasterPrinterJob.java:1277)
	at SimplePrint.main(SimplePrint.java:16)
2014-03-12 09:48:20.540 java[9531:1903] NSAlert is being used from a background thread, which is not safe.  This is probably going to crash sometimes. Break on void _NSAlertWarnUnsafeBackgroundThreadUsage() to debug.  This will be logged only once.  This may break in the future.
2014-03-12 09:48:22.253 java[9531:1903] An uncaught exception was raised
2014-03-12 09:48:22.253 java[9531:1903] Printing failed because PMSessionEndDocumentNoDialog() returned -30871.
2014-03-12 09:48:22.254 java[9531:1903] (
	0   CoreFoundation                      0x00007fff8a25a41c __exceptionPreprocess + 172
	1   libobjc.A.dylib                     0x00007fff8baeee75 objc_exception_throw + 43
	2   CoreFoundation                      0x00007fff8a25a2cc +[NSException raise:format:] + 204
	3   AppKit                              0x00007fff8608761e -[NSPrintSpoolingGraphicsContext dealloc] + 43
	4   libobjc.A.dylib                     0x00007fff8bae865a _ZN12_GLOBAL__N_119AutoreleasePoolPage3popEPv + 502
	5   CoreFoundation                      0x00007fff8a144d72 _CFAutoreleasePoolPop + 50
	6   liblwawt.dylib                      0x000000015433cb11 Java_sun_lwawt_macosx_CPrinterJob_printLoop + 165
	7   ???                                 0x00000001062114b9 0x0 + 4397798585
)
2014-03-12 09:48:22.254 java[9531:1903] *** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'Printing failed because PMSessionEndDocumentNoDialog() returned -30871.'
*** First throw call stack:
(
	0   CoreFoundation                      0x00007fff8a25a41c __exceptionPreprocess + 172
	1   libobjc.A.dylib                     0x00007fff8baeee75 objc_exception_throw + 43
	2   CoreFoundation                      0x00007fff8a25a2cc +[NSException raise:format:] + 204
	3   AppKit                              0x00007fff8608761e -[NSPrintSpoolingGraphicsContext dealloc] + 43
	4   libobjc.A.dylib                     0x00007fff8bae865a _ZN12_GLOBAL__N_119AutoreleasePoolPage3popEPv + 502
	5   CoreFoundation                      0x00007fff8a144d72 _CFAutoreleasePoolPop + 50
	6   liblwawt.dylib                      0x000000015433cb11 Java_sun_lwawt_macosx_CPrinterJob_printLoop + 165
	7   ???                                 0x00000001062114b9 0x0 + 4397798585
)
libc++abi.dylib: terminating with uncaught exception of type NSException


REPRODUCIBILITY :
This bug can be reproduced always.

---------- BEGIN SOURCE ----------
import java.applet.Applet;
import java.awt.print.PrinterException;
import java.awt.print.PrinterJob;


public class SimplePrint extends Applet
{
	public static void main(String[] args)
	{
		PrinterJob job = PrinterJob.getPrinterJob();
		job.setPrintable(new PrintTest());
		if (job.printDialog())
		{
			try
			{
				job.print();
			}
			catch (PrinterException e)
			{
				System.out.println("exception - " + e);
			}
		}
		else
		{
			System.out.println("else");
		}
	}
}





import java.awt.Graphics;
import java.awt.GraphicsEnvironment;
import java.awt.Rectangle;
import java.awt.Shape;
import java.awt.Transparency;
import java.awt.image.BufferedImage;
import java.awt.print.PageFormat;
import java.awt.print.Printable;
import java.awt.print.PrinterException;

public class PrintTest implements Printable
{
	@Override
	public int print(Graphics graphics, PageFormat pageFormat, int pageIndex) throws PrinterException
	{
		if (pageIndex != 0)
			return NO_SUCH_PAGE;

		Shape shape = new Rectangle(110, 110, 10, 10);
		Rectangle rect = shape.getBounds();

		BufferedImage image = GraphicsEnvironment.getLocalGraphicsEnvironment().getDefaultScreenDevice().getDefaultConfiguration().createCompatibleImage(rect.width,
																																						 rect.height,
																																						 Transparency.BITMASK);
		graphics.drawImage(image, rect.x, rect.y, rect.width, rect.height, null);
		
		return PAGE_EXISTS;
	}

}

---------- END SOURCE ----------

CUSTOMER SUBMITTED WORKAROUND :
None found at this time.


Comments
Fixed under JDK-8163889
31-01-2017

not a regression in 8 or 9
16-05-2014