Bug 160377 - NullPointerException printing a diagram
Summary: NullPointerException printing a diagram
Status: RESOLVED FIXED
Alias: None
Product: GMF-Runtime
Classification: Modeling
Component: General (show other bugs)
Version: 1.0.1   Edit
Hardware: PC Windows XP
: P3 normal
Target Milestone: 2.0   Edit
Assignee: David Cummings CLA
QA Contact:
URL:
Whiteboard:
Keywords: contributed
Depends on:
Blocks:
 
Reported: 2006-10-10 16:56 EDT by Anthony Hunter CLA
Modified: 2010-07-19 21:59 EDT (History)
2 users (show)

See Also:


Attachments
patch (1.14 KB, patch)
2006-11-07 11:05 EST, David Cummings CLA
no flags Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Anthony Hunter CLA 2006-10-10 16:56:33 EDT
java.lang.NullPointerException
  at org.eclipse.gmf.runtime.draw2d.ui.internal.graphics.PrinterGraphics.dispose(PrinterGraphics.java:73)
  at org.eclipse.gmf.runtime.diagram.ui.printing.internal.util.DiagramPrinter.dispose(DiagramPrinter.java:533)
  at org.eclipse.gmf.runtime.diagram.ui.printing.internal.util.DiagramPrinter.run(DiagramPrinter.java:213)
  at org.eclipse.gmf.runtime.diagram.ui.printing.util.DiagramPrinterUtil.printDiagrams(DiagramPrinterUtil.java:66)
etc....

you won't see an exception in the log, but the exception does occur.

The problem can contribute to a SWT handle leak. In org.eclipse.gmf.runtime.draw2d.ui.internal.graphics.PrinterGraphics#dispose the code tries to dispose all the images in collapseImageCache, but if any are already disposed there hashCode has changed and HashMap#get will return null. A better approach is to iterate over the values which will never be null. An image can safely be disposed twice. The suggested code below is similar to that found in the base class.

	public void dispose() {

		for (Iterator it = collapseImageCache.values().iterator(); it.hasNext();) {
			Image img = (Image) it.next();
			img.dispose();
		}

		collapseImageCache.clear();

		super.dispose();
	}
Comment 1 Keith W. Campbell CLA 2006-10-11 08:03:18 EDT
This issue is not specific to PC hardware or the Windows OS:
both should be 'all' but I can't change those fields.
Comment 2 David Cummings CLA 2006-11-07 11:05:25 EST
Created attachment 53376 [details]
patch

Attached patch.

Verified that exception no longer occurs in dispose method.
Comment 3 Linda Damus CLA 2006-11-21 17:56:16 EST
Reviewed and committed the patch.
Comment 4 Linda Damus CLA 2006-11-21 17:57:01 EST
Reviewed and committed the patch.
Comment 5 Richard Gronback CLA 2008-08-13 13:10:47 EDT
[target cleanup] 2.0 M4 was the original target milestone for this bug
Comment 6 Eclipse Webmaster CLA 2010-07-19 21:59:32 EDT
[GMF Restructure] Bug 319140 : product GMF and component
Runtime was the original product and component for this bug