Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.

Bug 126747

Summary: NPE on shrinking a Thumbnail
Product: [Tools] GEF Reporter: Johannes Quast <johannes.quast>
Component: GEF-Legacy Draw2dAssignee: Alexander Nyßen <nyssen>
Status: RESOLVED FIXED QA Contact:
Severity: normal    
Priority: P3 CC: nyssen
Version: 3.1.1   
Target Milestone: 3.6.0 (Helios) M7   
Hardware: PC   
OS: Windows XP   
Whiteboard:

Description Johannes Quast CLA 2006-02-07 11:45:28 EST
In our editor we use a Thumbnail in the Outline view like in the logic example.
In addition we have some documentation figures using a TextLayout to draw their content.

If you resize the outline view until the thumbnail is nearly zero in it's size,
the following error occurs:

Caused by: java.lang.NullPointerException
	at org.eclipse.draw2d.SWTGraphics.drawTextLayout(SWTGraphics.java:494)
	at org.eclipse.draw2d.ScaledGraphics.drawTextLayout(ScaledGraphics.java:294)
	at org.eclipse.draw2d.Graphics.drawTextLayout(Graphics.java:353)

The zoomTextLayout(layout) call in ScaledGraphics:293 returns null because zoomWidth == 0 (see line 736).
This null is passed to SWTGraphics.drawTextLayout which causes the NPE.

Possible solutions:
- no return of null in zoomTextLayout(..) (but what instead?)
- check the return value in ScaledGraphics.drawTextLayout and do not call underlying Graphics in case of null
Comment 1 Alexander Nyßen CLA 2010-04-13 15:09:36 EDT
zoomTextLayout may legally return null in case the computed zoomWidth is 0, as this is no valid size for TextLayout. I thus added a null check to drawTextLayout and have it directly return in case the result of zoomTextLayout evaluates to null. 

Changes are committed to HEAD.