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

Bug 546205

Summary: SWTException in ColorManager.initializeDefaults()
Product: [Eclipse Project] PDE Reporter: Patrick Tasse <patrick.tasse>
Component: UIAssignee: Patrick Tasse <patrick.tasse>
Status: VERIFIED FIXED QA Contact:
Severity: normal    
Priority: P3 CC: akurtakov, loskutov, Vikas.Chandra
Version: 3.8.2   
Target Milestone: 4.12 M3   
Hardware: PC   
OS: All   
See Also: https://bugs.eclipse.org/bugs/show_bug.cgi?id=220641
https://git.eclipse.org/r/141586
https://git.eclipse.org/c/pde/eclipse.pde.ui.git/commit/?id=f87325e48037e9397c047548c8f80c6cbb789b47
https://git.eclipse.org/r/142206
https://git.eclipse.org/r/142226
https://git.eclipse.org/c/pde/eclipse.pde.ui.git/commit/?id=0470f4612faa0ca366c94ccdb40e1bd94bb9618d
Whiteboard:

Description Patrick Tasse CLA 2019-04-08 11:56:11 EDT
I'm running in Debug with a breakpoint on SWTException.

This happened when trying to rename a resource in the Project Explorer. I see the Rename Resource dialog, with the status bar showing "Checking preconditions...". 

It appears this activates the PDEPlugin, and PDEPlugin.start() is called from a ModalContext thread, not the main UI thread.

ColorManager swallows the exception and keeps highContrast = false, but either ColorManager or the caller of the method should probably try to get it from the main UI thread.

Thread [ModalContext] (Suspended (exception SWTException))	
	SWT.error(int, Throwable, String) line: 4701	
	SWT.error(int, Throwable) line: 4614	
	SWT.error(int) line: 4585	
	Display.error(int) line: 1369	
	Display.checkDevice() line: 900	
	Display.getHighContrast() line: 2599	
	ColorManager.initializeDefaults(IPreferenceStore) line: 50	
	PreferenceInitializer.initializeDefaultPreferences() line: 28	
	PreferenceServiceRegistryHelper$1.run() line: 301	
	SafeRunner.run(ISafeRunnable) line: 45	
	PreferenceServiceRegistryHelper.runInitializer(IConfigurationElement) line: 304	
	PreferenceServiceRegistryHelper.applyRuntimeDefaults(String, WeakReference<Object>) line: 134	
	PreferencesService.applyRuntimeDefaults(String, WeakReference<Object>) line: 375	
	DefaultPreferences.applyRuntimeDefaults() line: 225	
	DefaultPreferences.load() line: 279	
	DefaultPreferences(EclipsePreferences).create(EclipsePreferences, String, Object) line: 370	
	DefaultPreferences(EclipsePreferences).internalNode(String, boolean, Object) line: 623	
	DefaultPreferences(EclipsePreferences).node(String) line: 766	
	DefaultScope(AbstractScope).getNode(String) line: 41	
	DefaultScope.getNode(String) line: 77	
	PDEPreferencesManager.<init>(String) line: 39	
	PDEPlugin.getPreferenceManager() line: 69	
	TargetStatus.initializeTargetStatus() line: 188	
	PDEPlugin.start(BundleContext) line: 210	
	BundleContextImpl$3.run() line: 815	
	BundleContextImpl$3.run() line: 1	
	AccessController.doPrivileged(PrivilegedExceptionAction<T>) line: not available [native method]	
	BundleContextImpl.startActivator(BundleActivator) line: 808	
	BundleContextImpl.start() line: 765	
	EquinoxBundle.startWorker0() line: 1005	
	EquinoxBundle$EquinoxModule.startWorker() line: 357	
	EquinoxBundle$EquinoxModule(Module).doStart(Module$StartOptions...) line: 589	
	EquinoxBundle$EquinoxModule(Module).start(Module$StartOptions...) line: 457	
	SecureAction.start(Module, Module$StartOptions...) line: 471	
	EclipseLazyStarter.postFindLocalClass(String, Class<?>, ClasspathManager) line: 117	
	ClasspathManager.findLocalClass(String) line: 570	
	EquinoxClassLoader(ModuleClassLoader).findLocalClass(String) line: 331	
	BundleLoader.findLocalClass(String) line: 395	
	BundleLoader.findClassInternal(String, boolean) line: 473	
	BundleLoader.findClass(String, boolean) line: 422	
	BundleLoader.findClass(String) line: 414	
	EquinoxClassLoader(ModuleClassLoader).loadClass(String, boolean) line: 153	
	EquinoxClassLoader(ClassLoader).loadClass(String) line: 496	
	EquinoxBundle.loadClass(String) line: 612	
	EquinoxRegistryStrategy(RegistryStrategyOSGI).createExecutableExtension(RegistryContributor, String, String) line: 196	
	ExtensionRegistry.createExecutableExtension(RegistryContributor, String, String) line: 934	
	ConfigurationElement.createExecutableExtension(String) line: 246	
	ConfigurationElementHandle.createExecutableExtension(String) line: 63	
	ParticipantDescriptor.createParticipant() line: 88	
	ParticipantExtensionPoint.getParticipants(RefactoringStatus, RefactoringProcessor, Object, RefactoringArguments, IParticipantDescriptorFilter, String[], SharableParticipants) line: 101	
	ParticipantManager.loadRenameParticipants(RefactoringStatus, RefactoringProcessor, Object, RenameArguments, IParticipantDescriptorFilter, String[], SharableParticipants) line: 77	
	RenameResourceProcessor.loadParticipants(RefactoringStatus, SharableParticipants) line: 236	
	RenameRefactoring(ProcessorBasedRefactoring).checkFinalConditions(IProgressMonitor) line: 234	
	CheckConditionsOperation.run(IProgressMonitor) line: 86	
	CreateChangeOperation.run(IProgressMonitor) line: 122	
	UIPerformChangeOperation(PerformChangeOperation).run(IProgressMonitor) line: 210	
	Workspace.run(ICoreRunnable, ISchedulingRule, int, IProgressMonitor) line: 2295	
	Workspace.run(IWorkspaceRunnable, ISchedulingRule, int, IProgressMonitor) line: 2322	
	WorkbenchRunnableAdapter.run(IProgressMonitor) line: 89	
	ModalContext$ModalContextThread.run() line: 122
Comment 1 Andrey Loskutov CLA 2019-05-01 17:46:58 EDT
(In reply to Patrick Tasse from comment #0)
> ColorManager swallows the exception and keeps highContrast = false, but
> either ColorManager or the caller of the method should probably try to get
> it from the main UI thread.

Patch?
Comment 2 Eclipse Genie CLA 2019-05-03 09:51:18 EDT
New Gerrit change created: https://git.eclipse.org/r/141586
Comment 4 Andrey Loskutov CLA 2019-05-15 12:00:24 EDT
I see this now in the headless build:

!ENTRY org.eclipse.equinox.preferences 4 2 2019-05-15 17:57:41.919
!MESSAGE Problems occurred when invoking code from plug-in: "org.eclipse.equinox.preferences".
!STACK 0
java.lang.IllegalStateException: Workbench has not been created yet.
	at org.eclipse.ui.PlatformUI.getWorkbench(PlatformUI.java:95)
	at org.eclipse.pde.internal.ui.editor.text.ColorManager.initializeDefaults(ColorManager.java:63)
	at org.eclipse.pde.internal.ui.preferences.PreferenceInitializer.initializeDefaultPreferences(PreferenceInitializer.java:28)
	at org.eclipse.core.internal.preferences.PreferenceServiceRegistryHelper$1.run(PreferenceServiceRegistryHelper.java:301)
	at org.eclipse.core.runtime.SafeRunner.run(SafeRunner.java:45)
	at org.eclipse.core.internal.preferences.PreferenceServiceRegistryHelper.runInitializer(PreferenceServiceRegistryHelper.java:304)
	at org.eclipse.core.internal.preferences.PreferenceServiceRegistryHelper.applyRuntimeDefaults(PreferenceServiceRegistryHelper.java:134)
	at org.eclipse.core.internal.preferences.PreferencesService.applyRuntimeDefaults(PreferencesService.java:375)
	at org.eclipse.core.internal.preferences.DefaultPreferences.applyRuntimeDefaults(DefaultPreferences.java:225)
	at org.eclipse.core.internal.preferences.DefaultPreferences.load(DefaultPreferences.java:279)
	at org.eclipse.core.internal.preferences.EclipsePreferences.create(EclipsePreferences.java:370)
	at org.eclipse.core.internal.preferences.EclipsePreferences.internalNode(EclipsePreferences.java:623)
	at org.eclipse.core.internal.preferences.EclipsePreferences.node(EclipsePreferences.java:766)
	at org.eclipse.core.internal.preferences.AbstractScope.getNode(AbstractScope.java:41)
	at org.eclipse.core.runtime.preferences.DefaultScope.getNode(DefaultScope.java:77)
	at org.eclipse.pde.internal.core.PDEPreferencesManager.<init>(PDEPreferencesManager.java:39)
	at org.eclipse.pde.internal.ui.PDEPlugin.getPreferenceManager(PDEPlugin.java:69)
	at org.eclipse.pde.internal.ui.shared.target.TargetStatus.initializeTargetStatus(TargetStatus.java:188)
	at org.eclipse.pde.internal.ui.PDEPlugin.start(PDEPlugin.java:210)
	at org.eclipse.osgi.internal.framework.BundleContextImpl$3.run(BundleContextImpl.java:815)
	at org.eclipse.osgi.internal.framework.BundleContextImpl$3.run(BundleContextImpl.java:1)
	at java.base/java.security.AccessController.doPrivileged(Native Method)
	at org.eclipse.osgi.internal.framework.BundleContextImpl.startActivator(BundleContextImpl.java:808)
	at org.eclipse.osgi.internal.framework.BundleContextImpl.start(BundleContextImpl.java:765)
	at org.eclipse.osgi.internal.framework.EquinoxBundle.startWorker0(EquinoxBundle.java:1005)
	at org.eclipse.osgi.internal.framework.EquinoxBundle$EquinoxModule.startWorker(EquinoxBundle.java:357)
	at org.eclipse.osgi.container.Module.doStart(Module.java:598)
	at org.eclipse.osgi.container.Module.start(Module.java:462)
	at org.eclipse.osgi.framework.util.SecureAction.start(SecureAction.java:471)
	at org.eclipse.osgi.internal.hooks.EclipseLazyStarter.postFindLocalClass(EclipseLazyStarter.java:117)
	at org.eclipse.osgi.internal.loader.classpath.ClasspathManager.findLocalClass(ClasspathManager.java:570)
	at org.eclipse.osgi.internal.loader.ModuleClassLoader.findLocalClass(ModuleClassLoader.java:325)
	at org.eclipse.osgi.internal.loader.BundleLoader.findLocalClass(BundleLoader.java:395)
	at org.eclipse.osgi.internal.loader.sources.SingleSourcePackage.loadClass(SingleSourcePackage.java:39)
	at org.eclipse.osgi.internal.loader.BundleLoader.findClassInternal(BundleLoader.java:469)
	at org.eclipse.osgi.internal.loader.BundleLoader.findClass(BundleLoader.java:422)
	at org.eclipse.osgi.internal.loader.BundleLoader.findClass(BundleLoader.java:414)
	at org.eclipse.osgi.internal.loader.ModuleClassLoader.loadClass(ModuleClassLoader.java:153)
	at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:521)
	at java.base/java.lang.Class.getDeclaredConstructors0(Native Method)
	at java.base/java.lang.Class.privateGetDeclaredConstructors(Class.java:3138)
	at java.base/java.lang.Class.getConstructor0(Class.java:3343)
	at java.base/java.lang.Class.getDeclaredConstructor(Class.java:2554)
	at org.eclipse.core.internal.registry.osgi.RegistryStrategyOSGI.createExecutableExtension(RegistryStrategyOSGI.java:206)
	at org.eclipse.core.internal.registry.ExtensionRegistry.createExecutableExtension(ExtensionRegistry.java:934)
	at org.eclipse.core.internal.registry.ConfigurationElement.createExecutableExtension(ConfigurationElement.java:246)
	at org.eclipse.core.internal.registry.ConfigurationElementHandle.createExecutableExtension(ConfigurationElementHandle.java:63)
	at org.eclipse.jdt.internal.core.JavaModelManager$CompilationParticipants$1.run(JavaModelManager.java:466)
	at org.eclipse.core.runtime.SafeRunner.run(SafeRunner.java:45)
	at org.eclipse.jdt.internal.core.JavaModelManager$CompilationParticipants.getCompilationParticipants(JavaModelManager.java:459)
	at org.eclipse.jdt.internal.core.builder.JavaBuilder.initializeBuilder(JavaBuilder.java:614)
	at org.eclipse.jdt.internal.core.builder.JavaBuilder.build(JavaBuilder.java:174)
	at org.eclipse.core.internal.events.BuildManager$2.run(BuildManager.java:833)
	at org.eclipse.core.runtime.SafeRunner.run(SafeRunner.java:45)
	at org.eclipse.core.internal.events.BuildManager.basicBuild(BuildManager.java:220)
	at org.eclipse.core.internal.events.BuildManager.basicBuild(BuildManager.java:263)
	at org.eclipse.core.internal.events.BuildManager$1.run(BuildManager.java:316)
	at org.eclipse.core.runtime.SafeRunner.run(SafeRunner.java:45)
	at org.eclipse.core.internal.events.BuildManager.basicBuild(BuildManager.java:319)
	at org.eclipse.core.internal.events.BuildManager.basicBuildLoop(BuildManager.java:371)
	at org.eclipse.core.internal.events.BuildManager.build(BuildManager.java:392)
	at org.eclipse.core.internal.resources.Workspace.buildInternal(Workspace.java:504)
	at org.eclipse.core.internal.resources.Workspace.build(Workspace.java:404)
	at org.eclipse.jdt.core.tests.model.ModuleBuilderTests.test_no_conflicting_packages_for_debugger(ModuleBuilderTests.java:3344)
	at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
	at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
	at java.base/java.lang.reflect.Method.invoke(Method.java:566)
	at junit.framework.TestCase.runTest(TestCase.java:176)
	at org.eclipse.jdt.core.tests.junit.extension.TestCase.runTest(TestCase.java:964)
	at junit.framework.TestCase.runBare(TestCase.java:141)
	at junit.framework.TestResult$1.protect(TestResult.java:122)
	at junit.framework.TestResult.runProtected(TestResult.java:142)
	at junit.framework.TestResult.run(TestResult.java:125)
	at junit.framework.TestCase.run(TestCase.java:129)
Comment 5 Patrick Tasse CLA 2019-05-15 12:41:53 EDT
Go back to Display.getDefault()? Or will that fail too in headless build?
Comment 6 Eclipse Genie CLA 2019-05-15 12:48:20 EDT
New Gerrit change created: https://git.eclipse.org/r/142206
Comment 7 Andrey Loskutov CLA 2019-05-15 13:53:46 EDT
(In reply to Patrick Tasse from comment #5)
> Go back to Display.getDefault()? Or will that fail too in headless build?

I wonder if we should check if workbench is running. The problem with Display. getDefault() is that it can create a new Display and it is definitely not what we wanted achieve :)
Comment 8 Eclipse Genie CLA 2019-05-16 02:59:44 EDT
New Gerrit change created: https://git.eclipse.org/r/142226
Comment 9 Andrey Loskutov CLA 2019-05-16 03:01:52 EDT
(In reply to Eclipse Genie from comment #8)
> New Gerrit change created: https://git.eclipse.org/r/142226

This is what I meant before.
Comment 11 Alexander Kurtakov CLA 2019-05-16 05:37:49 EDT
Should this one be marked resolved now?
Comment 12 Andrey Loskutov CLA 2019-05-16 06:32:16 EDT
(In reply to Alexander Kurtakov from comment #11)
> Should this one be marked resolved now?

Yes, I just usually wait for the next build to verify the patch.

Offtopic: Alex, our "eca" badges are red in bugzilla: I believe we can't contribute to Eclipse anymore. Is this known?
Comment 13 Alexander Kurtakov CLA 2019-05-16 06:38:26 EDT
(In reply to Andrey Loskutov from comment #12)
> (In reply to Alexander Kurtakov from comment #11)
> > Should this one be marked resolved now?
> 
> Yes, I just usually wait for the next build to verify the patch.
> 
> Offtopic: Alex, our "eca" badges are red in bugzilla: I believe we can't
> contribute to Eclipse anymore. Is this known?

I went and resigned mine and its fine now. I see yours green too.
Comment 14 Vikas Chandra CLA 2019-05-21 02:54:58 EDT
Can the bug submitter/bug assignee please verify this defect for 4.12 M3?
Comment 15 Andrey Loskutov CLA 2019-05-21 03:09:32 EDT
Verified in I20190519-1800.
Comment 16 Andrey Loskutov CLA 2020-11-05 03:46:38 EST
*** Bug 541149 has been marked as a duplicate of this bug. ***