JDK-6943487 : NPE in makeMultiCharsetString while printing on linux
  • Type: Bug
  • Component: client-libs
  • Sub-Component: 2d
  • Affected Version: 5.0,7
  • Priority: P2
  • Status: Closed
  • Resolution: Fixed
  • OS:
    linux_redhat_5.0,linux_ubuntu,solaris,solaris_10,windows_xp linux_redhat_5.0,linux_ubuntu,solaris,solaris_10,windows_xp
  • CPU: x86,sparc
  • Submitted: 2010-04-13
  • Updated: 2014-10-24
  • Resolved: 2011-03-08
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.
JDK 7
7 b102Fixed
Related Reports
Duplicate :  
Duplicate :  
Relates :  
Relates :  
Relates :  
Relates :  
Description
FULL PRODUCT VERSION :
java version "1.7.0-ea"
Java(TM) SE Runtime Environment (build 1.7.0-ea-b87)
Java HotSpot(TM) 64-Bit Server VM (build 18.0-b01, mixed mode)

ADDITIONAL OS VERSION INFORMATION :
Linux ubuntu01 2.6.24-25-generic #1 SMP Tue Oct 20 06:49:12 UTC 2009 x86_64 GNU/Linux


A DESCRIPTION OF THE PROBLEM :
NPE while printing under linux

STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
Launch test case under linux

EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
A page should be printed
ACTUAL -
Working under Windows (jdk 1.6 and jdk1.7ea)
Working under Linux (jdk 1.6)
Fails under Linux (jdk1.7ea)

ERROR MESSAGES/STACK TRACES THAT OCCUR :
Exception in thread "main" java.lang.NullPointerException
        at sun.awt.PlatformFont.makeMultiCharsetString(PlatformFont.java:154)
        at sun.awt.PlatformFont.makeMultiCharsetString(PlatformFont.java:114)
        at sun.print.PSPrinterJob.textOut(PSPrinterJob.java:1201)
        at sun.print.PSPathGraphics.drawString(PSPathGraphics.java:228)
        at sun.print.PSPathGraphics.drawString(PSPathGraphics.java:140)
        at sun.print.PSPathGraphics.drawString(PSPathGraphics.java:114)
        at Print2DGraphics.print(Print2DGraphics.java:73)
        at sun.print.RasterPrinterJob.printPage(RasterPrinterJob.java:2008)
        at sun.print.RasterPrinterJob.print(RasterPrinterJob.java:1457)
        at sun.print.UnixPrintJob.printableJob(UnixPrintJob.java:636)
        at sun.print.UnixPrintJob.print(UnixPrintJob.java:493)
        at Print2DGraphics.<init>(Print2DGraphics.java:51)
        at Print2DGraphics.main(Print2DGraphics.java:82)


REPRODUCIBILITY :
This bug can be reproduced always.

---------- BEGIN SOURCE ----------
import java.awt.Color;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.print.PageFormat;
import java.awt.print.Printable;

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.Copies;
import javax.print.attribute.standard.JobName;
import javax.print.attribute.standard.OrientationRequested;

public class Print2DGraphics implements Printable {

	public Print2DGraphics() {

		/* Construct the print request specification.
		* The print data is a Printable object.
		* the request additonally specifies a job name, 2 copies, and
		* landscape orientation of the media.
		*/
		DocFlavor flavor = DocFlavor.SERVICE_FORMATTED.PRINTABLE;
		PrintRequestAttributeSet aset = new HashPrintRequestAttributeSet();
		aset.add(OrientationRequested.LANDSCAPE);
		aset.add(new Copies(2));
		aset.add(new JobName("My job", null));

		/* locate a print service that can handle the request */
		PrintService service = PrintServiceLookup.lookupDefaultPrintService();

		if (service != null) {
			System.out.println("Selected printer: " + service.getName());

			/* create a print job for the chosen service */
			DocPrintJob pj = service.createPrintJob();

			try {
				/*
				* Create a Doc object to hold the print data.
				*/
				Doc doc = new SimpleDoc(this, flavor, null);

				/* print the doc as specified */
				pj.print(doc, aset);

				/*
				* Do not explicitly call System.exit() when print returns.
				* Printing can be asynchronous so may be executing in a
				* separate thread.
				* If you want to explicitly exit the VM, use a print job
				* listener to be notified when it is safe to do so.
				*/

			} catch (PrintException e) {
				System.err.println(e);
			}
		}
	}

	public int print(Graphics g,PageFormat pf,int pageIndex) {

		if (pageIndex == 0) {
			Graphics2D g2d= (Graphics2D)g;
			g2d.translate(pf.getImageableX(), pf.getImageableY());
			g2d.setColor(Color.black);
			g2d.drawString("example string", 250, 250);
			g2d.fillRect(0, 0, 200, 200);
			return Printable.PAGE_EXISTS;
		} else {
			return Printable.NO_SUCH_PAGE;
		}
	}

	public static void main(String arg[]) {
		Print2DGraphics sp = new Print2DGraphics();
	}
}

---------- END SOURCE ----------
adding case name for qare linking:
java/awt/print/PageFormat/SetOrient.html
java/awt/print/PrinterJob/InitToBlack.html
java/awt/PrintJob/Text/PrintText.java
java/awt/PrintJob/Text/PrintText2.java
java/awt/PrintJob/Text/StringWidth.java
java/awt/print/PageFormat/Orient.java
java/awt/print/PrinterJob/CustomFont/CustomFont.java
java/awt/print/PrinterJob/DrawStringMethods.java
java/awt/print/PrinterJob/PrintDialogCancel.java
java/awt/print/PrinterJob/PrintTextLayout.java
java/awt/print/PrinterJob/ThinLines.java
sun/java2d/GdiRendering/GdiBlitOffscreenTest.java
java/awt/print/PrinterJob/ScaledText/ScaledText.java
java/awt/print/PrinterJob/Cancel/PrinterJobCancel.java

Comments
Will not fix for 5.0 or 6; use >= JDK 7,
24-10-2014

EVALUATION I'm not adding a new regression test for this as its caught by a significant percentage of the printing regression and sqe tests in existence.
28-06-2010

EVALUATION This is caused by "6795908: ReFactor FontManager" which removed "implements FontSupport" from SunGraphicsEnvironment and moved it to a different class. I think this has actually broken almost all text printing on Solaris and Linux. Headful and Headless. Actually headless has another problem that the HeadlessGraphicsEnvironment also still things that its wrapped GraphicsEnvironment implements FontSupport. Need to remove that code, and find all references to FontSupport and direct them to the object returned by sun.font.FontManager().getInstance().
19-06-2010