Project: Eclipse_Platform_UI
Bug 28785 [Font] NPE on JFaceResources.getTextFont()
Reported: 2002-12-21 06:31:18 | Status: closed fixed

affected Build: M4 I get a NPE when executing the following code line: Font font = JFaceResources.getTextFont(); I havn't had this NPE in a previous run. I assume it has something to do with initialisiation beacaus this line of code is executed when initializing the default values of the preference store of the affected plugin. It seems that JFaceResources.getTextFont() can't determine a valid Display. The cause may be a wrong thread. I'm not sure so I will give you a small abstract description what is going on before this NPE. I started a fresh debugging sessions for my plugins. I'm creating a development toolset for the Harbour(Clipper) programming languange. The core plugin provides a build. The process is similar to the new CDT plugin. I invoked the builder with right-click and "Rebuild Project" because I'm currently developing the builder. The builder uses a console for its output. This console is registered via an extension point from my ui plugin. You can see the next steps from the stack trace. - builder was invoked - builder tries to get the console from the core plugin class - console is tried to be instanciated - console constructor tries to get the console manager from the ui plugin class - because manager is lazily initialized, ui plugin class starts the console manager - console manager needs preference store to read some console preferences - because preference store is lazily initialized, too, ui plugin tries to apply default values to preference store - one default value is the console font -> NPE Any ideas? Probably JFaceResources.getTextFont() has a bug or it can't be invoked in this thread context or anything else. But I have no idea how to resolve this. I hope you guys have one. BUT! I know there is a way because it worked without getting a NPE on my first tries. But on the first tries I didn't have a newly started workbench. It was already running and I performed some actions which might have initialized something before so that JFaceResources.getTextFont() worked correclty. ----------- Stack Trace ----------- java.lang.NullPointerException at org.eclipse.jface.resource.FontRegistry.bestData (FontRegistry.java:257) at org.eclipse.jface.resource.FontRegistry.bestDataArray (FontRegistry.java:284) at org.eclipse.jface.resource.FontRegistry.createFont (FontRegistry.java:300) at org.eclipse.jface.resource.FontRegistry.get(FontRegistry.java:387) at org.eclipse.jface.resource.JFaceResources.getTextFont (JFaceResources.java:278) at org.harbour.ide.internal.ui.preferences.HarbourPreferences.initializeDefaultValu es(HarbourPreferences.java:144) at org.harbour.ide.internal.ui.HarbourUIPlugin.initializeDefaultPreferences (HarbourUIPlugin.java:251) at org.eclipse.ui.plugin.AbstractUIPlugin.initializeDefaultPluginPreferences (AbstractUIPlugin.java:623) at org.eclipse.core.runtime.Plugin.getPluginPreferences(Plugin.java:347) at org.eclipse.ui.plugin.AbstractUIPlugin$CompatibilityPreferenceStore.initialize (AbstractUIPlugin.java:175) at org.eclipse.ui.plugin.AbstractUIPlugin.getPreferenceStore (AbstractUIPlugin.java:560) at org.harbour.ide.internal.ui.views.buildview.BuildConsoleManager.startup (BuildConsoleManager.java:286) at org.harbour.ide.internal.ui.HarbourUIPlugin.getConsoleManager (HarbourUIPlugin.java:300) at org.harbour.ide.internal.ui.views.buildview.BuildConsole.<init> (BuildConsole.java:43) at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method) at sun.reflect.NativeConstructorAccessorImpl.newInstance (NativeConstructorAccessorImpl.java:39) at sun.reflect.DelegatingConstructorAccessorImpl.newInstance (DelegatingConstructorAccessorImpl.java:27) at java.lang.reflect.Constructor.newInstance(Constructor.java:274) at java.lang.Class.newInstance0(Class.java:306) at java.lang.Class.newInstance(Class.java:259) at org.eclipse.core.internal.plugins.PluginDescriptor.createExecutableExtension (PluginDescriptor.java:138) at org.eclipse.core.internal.plugins.PluginDescriptor.createExecutableExtension (PluginDescriptor.java:167) at org.eclipse.core.internal.plugins.ConfigurationElement.createExecutableExtension (ConfigurationElement.java:103) at org.harbour.ide.core.builder.HarbourBuildManager.getBuildConsole (HarbourBuildManager.java:744) at org.harbour.ide.internal.core.builder.HarbourBuilder.invokeBuild (HarbourBuilder.java:281) at org.harbour.ide.internal.core.builder.HarbourBuilder.build (HarbourBuilder.java:111) at org.eclipse.core.internal.events.BuildManager$2.run (BuildManager.java:384) at org.eclipse.core.internal.runtime.InternalPlatform.run (InternalPlatform.java:852) at org.eclipse.core.runtime.Platform.run(Platform.java:413) at org.eclipse.core.internal.events.BuildManager.basicBuild (BuildManager.java:120) at org.eclipse.core.internal.events.BuildManager.basicBuild (BuildManager.java:176) at org.eclipse.core.internal.events.BuildManager.basicBuild (BuildManager.java:186) at org.eclipse.core.internal.events.BuildManager$1.run (BuildManager.java:146) at org.eclipse.core.internal.runtime.InternalPlatform.run (InternalPlatform.java:852) at org.eclipse.core.runtime.Platform.run(Platform.java:413) at org.eclipse.core.internal.events.BuildManager.basicBuild (BuildManager.java:160) at org.eclipse.core.internal.events.BuildManager.build (BuildManager.java:232) at org.eclipse.core.internal.resources.Project.build(Project.java:87) at org.eclipse.ui.actions.BuildAction.invokeOperation (BuildAction.java:156) at org.eclipse.ui.actions.WorkspaceAction.execute (WorkspaceAction.java:111) at org.eclipse.ui.actions.WorkspaceAction$1.execute (WorkspaceAction.java:268) at org.eclipse.ui.actions.WorkspaceModifyOperation$1.run (WorkspaceModifyOperation.java:65) at org.eclipse.core.internal.resources.Workspace.run (Workspace.java:1564) at org.eclipse.ui.actions.WorkspaceModifyOperation.run (WorkspaceModifyOperation.java:79) at org.eclipse.jface.operation.ModalContext$ModalContextThread.run (ModalContext.java:95)

Files changed in fix:
bundles/org.eclipse.jface/src/org/eclipse/jface/resource/FontRegistry.java