Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
Re: [imp-dev] Re: Houston, we have a problem in PreferenceInitializer

FWIW, I tried the patch below out on Mac OS 10.5 Leopard, Linux (Fedora 8) and Windows XP, and it worked fine, both with sync() and async() calls.

So, Jurgen, if you're still ok with this, I'll commit the change with sync(), since that seemed to work better for you on Snow Leopard.

=======================================================================================

### Eclipse Workspace Patch 1.0
#P org.eclipse.imp.runtime
Index: src/org/eclipse/imp/preferences/PreferenceInitializer.java
===================================================================
--- src/org/eclipse/imp/preferences/PreferenceInitializer.java (revision 22383)
+++ src/org/eclipse/imp/preferences/PreferenceInitializer.java (working copy)
@@ -19,6 +19,7 @@
 import org.eclipse.jface.resource.JFaceResources;
 import org.eclipse.swt.graphics.FontData;
 import org.eclipse.swt.graphics.RGB;
+import org.eclipse.swt.widgets.Display;
 import org.eclipse.ui.PlatformUI;
 
 /**
@@ -26,9 +27,16 @@
  */
 public class PreferenceInitializer extends AbstractPreferenceInitializer {
+    private Display getDisplay() {
+        Display display= Display.getCurrent();
+        if (display == null) {
+            display = Display.getDefault();
+        }
+        return display;
+    }
     public void initializeDefaultPreferences() {
         // Run the following code on the UI thread - JFaceResources.getFontDescriptor() requires it
-        PlatformUI.getWorkbench().getDisplay().asyncExec(new Runnable() {
+        getDisplay().asyncExec(new Runnable() {
             public void run() {
                 ColorRegistry registry= null;
                 if (PlatformUI.isWorkbenchRunning())

=======================================================================================

On Mar 9, 2010, at 12:04 PM, Robert M. Fuhrer wrote:

So far, after a bunch of googling, I've yet to find a way to (a) run the initialization after the workbench is up.

So I'm going to try (b) find another way of accessing the Display. The following FAQ from the Eclipsepedia page seems to be as good an answer as any to that question:

 http://wiki.eclipse.org/FAQ_How_do_I_get_a_Display_instance%3F

We'll see how well that works...

Hopefully some Display will already exist by the time this code gets run, otherwise we'll have another race on our hands...

On Mar 9, 2010, at 11:40 AM, Robert M. Fuhrer wrote:

Hmmm... Sorry, and good catch! Naturally this didn't show up in my testing. Gotta love race conditions.

Obviously, bypassing the initialization altogether doesn't make sense (but you probably knew that).

Also, unfortunately, your work-around may not work: apparently isWorkbenchRunning() can return true even when the workbench is still initializing, and in that case, it's not yet safe to call workbench API methods. See the JavaDoc for PlatformUI.isWorkbenchRunning().

Guess I'll have to look around to find a way to either (a) run the initialization only after the workbench is really up, or (b) get the Display some other way (thereby avoiding the use of getWorkbench()).

On Mar 9, 2010, at 10:33 AM, Jurgen Vinju wrote:

Hi Bob,

The last change you made that put the initialization on the UI thread
is breaking IMP IDE's.
The problem is that there is a race condition. We are accessing the
workbench before it may have been created:

PlatformUI.getWorkbench().getDisplay().asyncExec(new Runnable() { ... });

This causes an exception, of which the root exception is:
Caused by: java.lang.IllegalStateException: Workbench has not been created yet.
at org.eclipse.ui.PlatformUI.getWorkbench(PlatformUI.java:92)
at org.eclipse.imp.preferences.PreferenceInitializer.initializeDefaultPreferences(PreferenceInitializer.java:34)
at org.eclipse.core.internal.preferences.PreferenceServiceRegistryHelper.runInitializer(PreferenceServiceRegistryHelper.java:276)
at org.eclipse.core.internal.preferences.PreferenceServiceRegistryHelper.applyRuntimeDefaults(PreferenceServiceRegistryHelper.java:130)
at org.eclipse.core.internal.preferences.PreferencesService.applyRuntimeDefaults(PreferencesService.java:367)
at org.eclipse.core.internal.preferences.DefaultPreferences.applyRuntimeDefaults(DefaultPreferences.java:163)
at org.eclipse.core.internal.preferences.DefaultPreferences.loadDefaults(DefaultPreferences.java:236)
at org.eclipse.core.internal.preferences.DefaultPreferences.load(DefaultPreferences.java:232)
at org.eclipse.core.internal.preferences.EclipsePreferences.create(EclipsePreferences.java:307)
at org.eclipse.core.internal.preferences.EclipsePreferences.internalNode(EclipsePreferences.java:543)
at org.eclipse.core.internal.preferences.EclipsePreferences.node(EclipsePreferences.java:669)
at org.eclipse.core.internal.preferences.AbstractScope.getNode(AbstractScope.java:38)
at org.eclipse.core.runtime.preferences.DefaultScope.getNode(DefaultScope.java:68)
at org.eclipse.ui.preferences.ScopedPreferenceStore.getDefaultPreferences(ScopedPreferenceStore.java:250)
at org.eclipse.ui.preferences.ScopedPreferenceStore.getPreferenceNodes(ScopedPreferenceStore.java:285)
at org.eclipse.ui.preferences.ScopedPreferenceStore.internalGet(ScopedPreferenceStore.java:475)
at org.eclipse.ui.preferences.ScopedPreferenceStore.getBoolean(ScopedPreferenceStore.java:387)
at org.eclipse.imp.runtime.RuntimePlugin.start(RuntimePlugin.java:126)
at org.eclipse.osgi.framework.internal.core.BundleContextImpl$1.run(BundleContextImpl.java:783)
at java.security.AccessController.doPrivileged(Native Method)
at org.eclipse.osgi.framework.internal.core.BundleContextImpl.startActivator(BundleContextImpl.java:774)
... 94 more

If I add the following to the beginning of
initializeDefaultPreferences, everything works fine again:
if (!PlatformUI.isWorkbenchRunning())
  return;

There must be a better fix though. I'm not sure.

--
Cheers,
  - Bob
-------------------------------------------------
Robert M. Fuhrer
Research Staff Member
Programming Technologies Dept.
IBM T.J. Watson Research Center

IMP Project Lead (http://www.eclipse.org/imp)
X10: Productivity for High-Performance Parallel Programming (http://x10-lang.org)


Back to the top