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

Bug 319127

Summary: [Forms] ExpandableComposite NPE with focusGained|focusLost when using NO_TITLE
Product: [Eclipse Project] Platform Reporter: Michelle Crane <craneml>
Component: User AssistanceAssignee: Chris Goldthorpe <cgold>
Status: RESOLVED FIXED QA Contact:
Severity: normal    
Priority: P3 CC: cgold, david.perez.ingeniero, remy.suen
Version: 3.5   
Target Milestone: 3.7 M1   
Hardware: PC   
OS: Windows XP   
Whiteboard:
Attachments:
Description Flags
Patch none

Description Michelle Crane CLA 2010-07-07 10:05:04 EDT
Build Identifier: org.eclipse.ui.forms_3.5.0.v20100427

I'm using an ExpandableComposite inside of a property sheet.  When I don't use NO_TITLE as a style, I have no problems with the composite (i.e., expanding it, contracting it, clicking away from the properties, clicking back, etc.)  However, when I use NO_TITLE, I eventually start having problems - usually after expanding the section, clicking away (to the diagram) and back again.

I'm including the trace below.  The NPE is being thrown in both the focusGained() and focusLost() methods inside an inner ExpandableComposite class.  It makes sense that these methods would throw an NPE, since they're calling on the textLabel, which hasn't been set because I'm using NO_TITLE.

Searching through old bugs, I see bugzilla 171265, which is similar - the fix there including a null check.  I suggest just adding a quick check for null in the focusGained() and focusLost() methods, e.g.,

				toggle.addFocusListener(new FocusListener() {
					public void focusGained(FocusEvent e) {
						if (textLabel != null) { //new
							textLabel.redraw();
						} //new
					}

					public void focusLost(FocusEvent e) {
						if (textLabel != null) { //new
							textLabel.redraw();
						} //new
					}
				});

Note: my current workaround is to use the title, i.e., remove the NO_TITLE style, but set the title to "".  

Trace of one of the NPEs:

!ENTRY org.eclipse.ui 4 0 2010-07-07 09:44:07.312
!MESSAGE Unhandled event loop exception
!STACK 0
java.lang.NullPointerException
	at org.eclipse.ui.forms.widgets.ExpandableComposite$5.focusLost(ExpandableComposite.java:601)
	at org.eclipse.swt.widgets.TypedListener.handleEvent(TypedListener.java:143)
	at org.eclipse.swt.widgets.EventTable.sendEvent(EventTable.java:84)
	at org.eclipse.swt.widgets.Widget.sendEvent(Widget.java:1053)
	at org.eclipse.swt.widgets.Widget.sendEvent(Widget.java:1077)
	at org.eclipse.swt.widgets.Widget.sendEvent(Widget.java:1058)
	at org.eclipse.swt.widgets.Control.sendFocusEvent(Control.java:2618)
	at org.eclipse.swt.widgets.Widget.wmKillFocus(Widget.java:1920)
	at org.eclipse.swt.widgets.Control.WM_KILLFOCUS(Control.java:4504)
	at org.eclipse.swt.widgets.Canvas.WM_KILLFOCUS(Canvas.java:434)
	at org.eclipse.swt.widgets.Control.windowProc(Control.java:4193)
	at org.eclipse.swt.widgets.Canvas.windowProc(Canvas.java:341)
	at org.eclipse.swt.widgets.Display.windowProc(Display.java:4886)
	at org.eclipse.swt.internal.win32.OS.PeekMessageW(Native Method)
	at org.eclipse.swt.internal.win32.OS.PeekMessage(OS.java:3024)
	at org.eclipse.swt.widgets.Display.readAndDispatch(Display.java:3652)
	at org.eclipse.ui.internal.Workbench.runEventLoop(Workbench.java:2629)
	at org.eclipse.ui.internal.Workbench.runUI(Workbench.java:2593)
	at org.eclipse.ui.internal.Workbench.access$4(Workbench.java:2427)
	at org.eclipse.ui.internal.Workbench$7.run(Workbench.java:670)
	at org.eclipse.core.databinding.observable.Realm.runWithDefault(Realm.java:332)
	at org.eclipse.ui.internal.Workbench.createAndRunWorkbench(Workbench.java:663)
	at org.eclipse.ui.PlatformUI.createAndRunWorkbench(PlatformUI.java:149)
	at org.eclipse.ui.internal.ide.application.IDEApplication.start(IDEApplication.java:115)
	at org.eclipse.equinox.internal.app.EclipseAppHandle.run(EclipseAppHandle.java:196)
	at org.eclipse.core.runtime.internal.adaptor.EclipseAppLauncher.runApplication(EclipseAppLauncher.java:110)
	at org.eclipse.core.runtime.internal.adaptor.EclipseAppLauncher.start(EclipseAppLauncher.java:79)
	at org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseStarter.java:369)
	at org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseStarter.java:179)
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:48)
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
	at java.lang.reflect.Method.invoke(Method.java:600)
	at org.eclipse.equinox.launcher.Main.invokeFramework(Main.java:619)
	at org.eclipse.equinox.launcher.Main.basicRun(Main.java:574)
	at org.eclipse.equinox.launcher.Main.run(Main.java:1407)
	at org.eclipse.equinox.launcher.Main.main(Main.java:1383)


Reproducible: Always

Steps to Reproduce:
I can't give easy steps to reproduce - this is deep within a set of property sheets, where the expandable composite is used to show the attributes of a referenced item.
Comment 1 Remy Suen CLA 2010-07-07 10:10:48 EDT
Forms bugs go to UA.
Comment 2 Chris Goldthorpe CLA 2010-07-07 19:24:04 EDT
Adding a null pointer test makes sense, targeting Eclipse 3.7.
Comment 3 Chris Goldthorpe CLA 2010-07-08 12:44:55 EDT
Created attachment 173788 [details]
Patch
Comment 4 Chris Goldthorpe CLA 2010-07-08 12:46:13 EDT
Patch applied to HEAD, Fixed
Comment 5 Chris Goldthorpe CLA 2011-03-23 12:42:18 EDT
*** Bug 340727 has been marked as a duplicate of this bug. ***