Project: Eclipse_Platform_UI
Bug 30610 [Preferences] FontFieldEditor constructor with preview text param causes NullPointerException when rendering
Reported: 2003-01-30 10:26:29 | Status: closed fixed

This constructor works fine: public FontFieldEditor(String name, String labelText, Composite parent) but this one: public FontFieldEditor(String name, String labelText, String previewText, Composite parent) will cause a NullPointerException when the preference page with it opens later on. The problem will be here: protected void adjustForNumColumns(int numColumns) { ((GridData)valueControl.getLayoutData()).horizontalSpan = numColumns - 2; Control control = getPreviewControl(); if (control != null) { ((GridData)control.getLayoutData()).horizontalSpan = numColumns; } } this will cause the NullPointerException because getLayoutData() returns null. Workaround: Use the constructor without the preview text parameter. Here's the stack trace: !ENTRY org.eclipse.ui 4 4 Jan 30, 2003 10:12:21.546 !MESSAGE *** Stack trace of contained exception *** !ENTRY org.eclipse.ui 4 0 Jan 30, 2003 10:12:21.546 !MESSAGE java.lang.NullPointerException !STACK 0 java.lang.NullPointerException at org.eclipse.jface.preference.FontFieldEditor.adjustForNumColumns (FontFieldEditor.java:123) at org.eclipse.jface.preference.FieldEditorPreferencePage.adjustGridLayout (FieldEditorPreferencePage.java:131) at org.eclipse.jface.preference.FieldEditorPreferencePage.createContents (FieldEditorPreferencePage.java:201) at org.eclipse.jface.preference.PreferencePage.createControl (PreferencePage.java:209) at org.eclipse.jface.preference.PreferenceDialog.showPage (PreferenceDialog.java:963) at org.eclipse.jface.preference.PreferenceDialog$7.run (PreferenceDialog.java:456) at org.eclipse.swt.custom.BusyIndicator.showWhile (BusyIndicator.java:65) at org.eclipse.jface.preference.PreferenceDialog$6.widgetSelected (PreferenceDialog.java:449) at org.eclipse.jface.util.OpenStrategy.firePostSelectionEvent (OpenStrategy.java:192) at org.eclipse.jface.util.OpenStrategy.access$4(OpenStrategy.java:187) at org.eclipse.jface.util.OpenStrategy$3.run(OpenStrategy.java:327) at org.eclipse.swt.widgets.RunnableLock.run(RunnableLock.java:31) at org.eclipse.swt.widgets.Synchronizer.runAsyncMessages (Synchronizer.java:94) at org.eclipse.swt.widgets.Display.runAsyncMessages(Display.java:1669) at org.eclipse.swt.widgets.Display.readAndDispatch(Display.java:1414) at org.eclipse.jface.window.Window.runEventLoop(Window.java:561) at org.eclipse.jface.window.Window.open(Window.java:541) at org.eclipse.ui.internal.OpenPreferencesAction.run (OpenPreferencesAction.java:47) at org.eclipse.jface.action.Action.runWithEvent(Action.java:769) at org.eclipse.jface.action.ActionContributionItem.handleWidgetSelection (ActionContributionItem.java:411) at org.eclipse.jface.action.ActionContributionItem.handleWidgetEvent (ActionContributionItem.java:365) at org.eclipse.jface.action.ActionContributionItem.access$0 (ActionContributionItem.java:356) at org.eclipse.jface.action.ActionContributionItem$ActionListener.handleEvent (ActionContributionItem.java:48) at org.eclipse.swt.widgets.EventTable.sendEvent(EventTable.java:77) at org.eclipse.swt.widgets.Widget.sendEvent(Widget.java:825) at org.eclipse.swt.widgets.Display.runDeferredEvents(Display.java:1692) at org.eclipse.swt.widgets.Display.readAndDispatch(Display.java:1410) at org.eclipse.ui.internal.Workbench.runEventLoop(Workbench.java:1446) at org.eclipse.ui.internal.Workbench.run(Workbench.java:1429) at org.eclipse.core.internal.boot.InternalBootLoader.run (InternalBootLoader.java:845) at org.eclipse.core.boot.BootLoader.run(BootLoader.java:462) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke (NativeMethodAccessorImpl.java:39) at sun.reflect.DelegatingMethodAccessorImpl.invoke (DelegatingMethodAccessorImpl.java:25) at java.lang.reflect.Method.invoke(Method.java:324) at org.eclipse.core.launcher.Main.basicRun(Main.java:247) at org.eclipse.core.launcher.Main.run(Main.java:703) at org.eclipse.core.launcher.Main.main(Main.java:539)

Files changed in fix:
bundles/org.eclipse.jface/src/org/eclipse/jface/preference/FontFieldEditor.java