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

Bug 344756

Summary: ClassCastException on 2nd start
Product: [Eclipse Project] e4 Reporter: DJ Houghton <dj.houghton>
Component: UIAssignee: Project Inbox <e4.ui-inbox>
Status: RESOLVED INVALID QA Contact:
Severity: normal    
Priority: P3 CC: Ed.Merks, emoffatt, pwebster, remy.suen, roza_ghamari, tjwatson, tom.schindl
Version: unspecified   
Target Milestone: ---   
Hardware: PC   
OS: Windows 7   
Whiteboard:
Attachments:
Description Flags
log file
none
Classloading trace for org.eclipse.emf.ecore package
none
debug output none

Description DJ Houghton CLA 2011-05-04 15:18:23 EDT
I20110429-0945

I am running a large product (originally built against Eclipse 3.6.2) on Eclipse 4.1. I start up the first time ok but subsequent starts give me the attached ClassCastExceptions and DI exceptions. I'll attach the full log.

java.lang.ClassCastException: org.eclipse.e4.ui.model.application.ui.basic.impl.PartImpl incompatible with org.eclipse.emf.ecore.EObject
	at org.eclipse.ui.internal.Workbench.getWindowContext(Workbench.java:1736)
	at org.eclipse.ui.internal.Workbench.getWorkbenchPage(Workbench.java:1654)
	at org.eclipse.ui.internal.Workbench.setReference(Workbench.java:1678)
	at org.eclipse.ui.internal.Workbench.access$19(Workbench.java:1675)
	at org.eclipse.ui.internal.Workbench$30.handleEvent(Workbench.java:1626)
	at org.eclipse.e4.ui.services.internal.events.UIEventHandler$1.run(UIEventHandler.java:41)


org.eclipse.e4.core.di.InjectionException: Could not find satisfiable constructor in org.eclipse.ui.internal.e4.compatibility.CompatibilityView
	at org.eclipse.e4.core.internal.di.InjectorImpl.internalMake(InjectorImpl.java:319)
	at org.eclipse.e4.core.internal.di.InjectorImpl.make(InjectorImpl.java:237)
	at org.eclipse.e4.core.contexts.ContextInjectionFactory.make(ContextInjectionFactory.java:153)
	at org.eclipse.e4.ui.internal.workbench.ReflectionContributionFactory.createFromBundle(ReflectionContributionFactory.java:90)
	at org.eclipse.e4.ui.internal.workbench.ReflectionContributionFactory.doCreate(ReflectionContributionFactory.java:64)
	at org.eclipse.e4.ui.internal.workbench.ReflectionContributionFactory.create(ReflectionContributionFactory.java:53)
	at org.eclipse.e4.ui.workbench.renderers.swt.ContributedPartRenderer.createWidget(ContributedPartRenderer.java:141)
Comment 1 DJ Houghton CLA 2011-05-04 15:19:23 EDT
Created attachment 194757 [details]
log file

This is the log for the 2nd start. 
It is for an empty (but not new) workspace.
Comment 2 Paul Webster CLA 2011-05-04 16:03:28 EDT
(In reply to comment #0)
> I20110429-0945
> 
> I am running a large product (originally built against Eclipse 3.6.2) on
> Eclipse 4.1. I start up the first time ok but subsequent starts give me the
> attached ClassCastExceptions and DI exceptions. I'll attach the full log.
> 
> java.lang.ClassCastException:
> org.eclipse.e4.ui.model.application.ui.basic.impl.PartImpl incompatible with
> org.eclipse.emf.ecore.EObject

Hmmm.  Doesn't this look like EMF is not using our model, but has fallen back to EObjects when it loaded our model?

PW
Comment 3 Paul Webster CLA 2011-05-05 07:23:21 EDT
DJ, in the second startup, can you check that our model plugins are installed and activated?  org.eclipse.e4.ui.model.workbench

PW
Comment 4 Paul Webster CLA 2011-05-05 07:27:33 EDT
DJ, isn't there a way to trace class loading?  The line in question takes an MPart:
MElementContainer<?> parent = (MElementContainer<?>) ((EObject) part).eContainer();

But PartImpl definitely has EObject in its part hierarchy.  That implies that the EObject used in this method is not the same one that our bundle loaded, right?

So maybe we're looking for 2 different loadings of EObject?

PW
Comment 5 DJ Houghton CLA 2011-05-09 11:17:41 EDT
Created attachment 195085 [details]
Classloading trace for org.eclipse.emf.ecore package

Paul and I looked at this and there is only 1 version of EMF available and loaded. (the most recent one)

I have attached the class loading trace file resulting from the monitoring of all the classes in the org.eclipse.emf.ecore package.
Comment 6 Thomas Schindl CLA 2011-05-09 11:24:41 EDT
adding Ed, maybe he's an idea what's going on. 

I remember having seeing this sometimes when i launched an inner and PDE has cached some strange things and it went away by checking "Clear the configuration area before launching".
Comment 7 Paul Webster CLA 2011-05-09 15:23:07 EDT
(In reply to comment #5)
> Created attachment 195085 [details]
> Classloading trace for org.eclipse.emf.ecore package

Thanx for the class loading, DJ.

I see 2 different places that say: 
Loading class: org.eclipse.emf.ecore.EObject

The next thing we probably need to see is the resolver? trace.  I know there's a way to ask OSGi to print up which bundles is providing which class for each classloading call.  I'm just not sure of the debug magic.  Tom?

PW
Comment 8 Thomas Watson CLA 2011-05-09 16:50:17 EDT
Could you try running with the following trace option set:

org.eclipse.osgi/debug/loader=true

This is a rather verbose trace to use, but it should show entries like this for each class that is read from disk

BundleClassLoader[org.eclipse.ui.ide_3.7.0.I20110425-1800].loadClass(org.eclipse.jface.viewers.TextCellEditor)
BundleLoader[org.eclipse.ui.ide_3.7.0.I20110425-1800].loadBundleClass(org.eclipse.jface.viewers.TextCellEditor)
BundleLoader[org.eclipse.jface_3.7.0.I20110504-0800].findLocalClass(org.eclipse.jface.viewers.TextCellEditor)
BundleClassLoader[/develop/install/current/eclipse/plugins/org.eclipse.jface_3.7.0.I20110504-0800.jar].findClass(org.eclipse.jface.viewers.TextCellEditor)
  about to read 7865 bytes from org/eclipse/jface/viewers/TextCellEditor.class
  read 7865 bytes from /develop/install/current/eclipse/plugins/org.eclipse.jface_3.7.0.I20110504-0800.jar/org/eclipse/jface/viewers/TextCellEditor.class
  defining class org.eclipse.jface.viewers.TextCellEditor
BundleLoader[org.eclipse.jface_3.7.0.I20110504-0800] found local class org.eclipse.jface.viewers.TextCellEditor

Here the trace is indicting that org.eclipse.ui.ide bundle class loader is attempting to load org.eclipse.jface.viewers.TextCellEditor which in turn delegates to org.eclipse.jface which finally finds the class file on the bundle class path of org.eclipse.jface.
Comment 9 DJ Houghton CLA 2011-05-10 09:02:37 EDT
This seems to put all debug info into the console. Is there a way to 1) direct it to a log and 2) filter based on class/package?
Comment 10 Paul Webster CLA 2011-05-10 09:48:01 EDT
(In reply to comment #9)
> This seems to put all debug info into the console. Is there a way to 1) direct
> it to a log and 2) filter based on class/package?

From a cmd shell, you can redirect console output to a file (even on windows :-)

C:\development> eclipse33\eclipsec.exe -debug debug.options -data workspaces\pw_workspace >debug.log 2>&1

PW
Comment 11 Thomas Watson CLA 2011-05-10 09:59:14 EDT
(In reply to comment #9)
> This seems to put all debug info into the console. Is there a way to 1) direct
> it to a log and 2) filter based on class/package?

You would have to do something like Paul suggests, there is no way to filter.
Comment 12 DJ Houghton CLA 2011-05-10 10:05:13 EDT
Created attachment 195216 [details]
debug output
Comment 13 Ed Merks CLA 2011-05-10 10:44:43 EDT
The only time I've ever seen an exception like this is when two versions of the class are loaded.  In that case it was two versions of DOM.  I've never seen it happen with EMF because the bundles are singletons so it should be quite hard to load two versions of the core runtime...
Comment 14 Paul Webster CLA 2011-05-10 11:31:01 EDT
(In reply to comment #13)
> The only time I've ever seen an exception like this is when two versions of the
> class are loaded.  In that case it was two versions of DOM.  I've never seen it
> happen with EMF because the bundles are singletons so it should be quite hard

But not impossible for IBM:

BundleClassLoader[C:\rad803\plugins\com.ibm.websphere.v7_7.0.101.v20110111_1854\wasJars\org.eclipse.emf.ecore.jar].findClass(org.eclipse.emf.ecore.EObject)

  about to read 1030 bytes from org/eclipse/emf/ecore/EObject.class

  read 1030 bytes from C:\rad803\plugins\com.ibm.websphere.v7_7.0.101.v20110111_1854\wasJars\org.eclipse.emf.ecore.jar/org/eclipse/emf/ecore/EObject.class

  defining class org.eclipse.emf.ecore.EObject

PW
Comment 15 DJ Houghton CLA 2011-05-10 11:45:12 EDT
Awesome. This appears to be a problem with the adopting product including its own version of Eclipse JARs (including v3.2 of core.runtime and osgi!) and re-exporting all packages. Then later different versions of the same package are getting wired in a way that results in the ClassCastExceptions that we're seeing.

This isn't a 4.1 problem. 
Closing.
Comment 16 Roza Ghamari CLA 2015-04-13 17:11:02 EDT
I have the same exception in my  product file in Kepler.Actually th eproduct file is from an example from EMF Client Platform, and it works file when I first import the examole. But as soon as I rename the plugin it stops working. i have tried setting the cleaning configuration area but that didn't help. Could you please explain how I can figure out a solution for this?