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

Bug 308964

Summary: NullPointerException in org.eclipse.draw2d.FigureUtilities.setFont
Product: [Tools] GEF Reporter: Heiko Böttger <heiko.boettger>
Component: GEF-Legacy Draw2dAssignee: gef-inbox <gef-inbox>
Status: RESOLVED DUPLICATE QA Contact:
Severity: normal    
Priority: P3 CC: nyssen, willem.duminy
Version: unspecified   
Target Milestone: ---   
Hardware: PC   
OS: Windows 7   
Whiteboard:
Attachments:
Description Flags
Proposed patch for the problem willem.duminy: review?

Description Heiko Böttger CLA 2010-04-13 05:01:50 EDT
Build Identifier: 20100218-1602

    at org.eclipse.draw2d.FigureUtilities.setFont(FigureUtilities.java:327)
    at org.eclipse.draw2d.FigureUtilities.getTextDimension(FigureUtilities.java:87)
    at org.eclipse.draw2d.FigureUtilities.getTextExtents(FigureUtilities.java:125)
    at org.eclipse.draw2d.TextUtilities.getTextExtents(TextUtilities.java:57)
    at org.eclipse.draw2d.Label.calculateTextSize(Label.java:244)
    at org.eclipse.draw2d.Label.getTextSize(Label.java:457)
    at org.eclipse.draw2d.Label.getPreferredSize(Label.java:329)
    at org.eclipse.draw2d.Figure.getPreferredSize(Figure.java:725)


Reproducible: Always

Steps to Reproduce:
1. Create a Label
2. call label.getPreferredSize()
3. call invalidate the label by calling label.revalidate() or label.invalidate()  
4. call label.getPreferredSize() to recalculate preferredSize

This will always throw a NullPointerException if there isn't a font returned from a parent. Since there is no information that calling getPreferredSize() is not allowed for detached figure, I think this is a bug. 

Testcase:

  public void test_getPreferredSizeDetached() {

    IFigure figure1 = new Label("Hello, World1");
    
    figure1.getPreferredSize();
    figure1.invalidate();
    figure1.getPreferredSize();
  }
Comment 1 Willem Duminy CLA 2012-12-11 12:45:12 EST
Created attachment 224586 [details]
Proposed patch for the problem

This patch assumes that:

a. The solution can be localised to Label
b. It is OK to return a zero dimension if the Label's font is null
Comment 2 Alexander Nyßen CLA 2014-03-23 20:17:09 EDT
The root cause for this was the missing null check in FigureUtilities#setFont(), which has been fixed as part of #430392.

Resolving as duplicate.

*** This bug has been marked as a duplicate of bug 430392 ***