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

Bug 336746

Summary: NullPointerException in org.eclipse.swt.widgets.Control.updateFont
Product: [Eclipse Project] Platform Reporter: Daniel Migowski <dmigowski>
Component: SWTAssignee: Platform-SWT-Inbox <platform-swt-inbox>
Status: CLOSED INVALID QA Contact:
Severity: normal    
Priority: P3 CC: eclipse.felipe
Version: 4.1   
Target Milestone: ---   
Hardware: PC   
OS: Windows 7   
Whiteboard:

Description Daniel Migowski CLA 2011-02-09 13:45:32 EST
Build Identifier: SWT 3.5.2

Today a got a stack trace from one of our dev clients. I don't believe they did something special... maybe they changed the system font.

Reproducible: Didn't try
Comment 1 Daniel Migowski CLA 2011-02-09 13:46:02 EST
Sorry, I forgot the stack trace. Here is it:

java.lang.NullPointerException
	at org.eclipse.swt.widgets.Control.updateFont(Unknown Source)
	at org.eclipse.swt.widgets.Composite.updateFont(Unknown Source)
	at org.eclipse.swt.widgets.Composite.updateFont(Unknown Source)
	at org.eclipse.swt.widgets.Composite.updateFont(Unknown Source)
	at org.eclipse.swt.widgets.Composite.updateFont(Unknown Source)
	at org.eclipse.swt.widgets.Composite.updateFont(Unknown Source)
	at org.eclipse.swt.widgets.Display.runSettings(Unknown Source)
	at org.eclipse.swt.widgets.Display.messageProc(Unknown Source)
	at org.eclipse.swt.internal.win32.OS.DispatchMessageW(Native Method)
	at org.eclipse.swt.internal.win32.OS.DispatchMessage(Unknown Source)
	at org.eclipse.swt.widgets.Display.readAndDispatch(Unknown Source)
	at de.ikoffice.gui.MainWindow.open(MainWindow.java:1274)
	at de.ikoffice.client.IKOfficeClient.run(IKOfficeClient.java:213)
	at java.lang.Thread.run(Unknown Source)
Comment 2 Daniel Migowski CLA 2011-02-09 13:50:11 EST
Just got the following info: The bug occured while the user was changing the desktop background. 

I believe this sends some update message to all processes, and SWT has some problems in their handling.
Comment 3 Daniel Migowski CLA 2011-02-14 05:45:51 EST
The function is this:

void updateFont (Font oldFont, Font newFont) {
	if (getFont ().equals (oldFont)) setFont (newFont);
}

Obviously, if getFont() returns null, this will result in a null pointer exception. Please add an additional check here!
Comment 4 Felipe Heidrich CLA 2011-02-14 09:53:26 EST
(In reply to comment #3)
> The function is this:
> void updateFont (Font oldFont, Font newFont) {
>     if (getFont ().equals (oldFont)) setFont (newFont);
> }
> Obviously, if getFont() returns null, this will result in a null pointer
> exception. Please add an additional check here!

This is not correct, getFont() should not return null. Putting a check to this one method will fix the case you are running into, but all other callers of getFont() will still have the bug.

Does the problem happen to 3.7 ? (we are not fixing bugs in 3.5.x any more)

What control is the problem happening to ? (a Text, a Button, etc)

Do you have a reproducible test case ?
- Can you attach it here ? If not, can you debug the problem and find out why getFont() is returning NULL ?

Thank you.
Comment 5 Daniel Migowski CLA 2011-02-16 11:43:52 EST
Sorry, it was my fault. It was a custom component that had its own getFont() and setFont() functions. I didn't know they always have to return a non-null value, and thought null ~ some default font. 

Thanks for your time anyway.

Regards,
Daniel Migowski