[
Date Prev][
Date Next][
Thread Prev][
Thread Next][
Date Index][
Thread Index]
[
List Home]
| 
[imp-dev] Re: Houston, we have a problem in PreferenceInitializer
 | 
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,
Jurgen
Cheers,
 - Bob