Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » EMF » [EMF] ClassCastException: $Proxy cannot be cast...
[EMF] ClassCastException: $Proxy cannot be cast... [message #1007906] Fri, 08 February 2013 06:42 Go to next message
Bastian Wagenfeld is currently offline Bastian WagenfeldFriend
Messages: 183
Registered: January 2013
Senior Member
Hi,

I have five EMF models that should be initialized during the RCP's startup. Therefore I call IdentifiablePackage.eINSTANCE.getClass();. This triggers the following error:

!ENTRY org.eclipse.emf.ecore 2 0 2013-02-08 07:24:22.715
!MESSAGE $Proxy10 cannot be cast to de.test.model.identifiable.IdentifiableFactory
!STACK 0
java.lang.ClassCastException: $Proxy10 cannot be cast to de.test.model.identifiable.IdentifiableFactory
	at de.test.model.identifiable.impl.IdentifiableFactoryImpl.init(IdentifiableFactoryImpl.java:34)
	at de.test.model.identifiable.IdentifiableFactory.<clinit>(IdentifiableFactory.java:26)
	at de.test.model.identifiable.impl.IdentifiablePackageImpl.<init>(IdentifiablePackageImpl.java:63)
	at de.test.model.identifiable.impl.IdentifiablePackageImpl.init(IdentifiablePackageImpl.java:89)
	at de.test.model.identifiable.IdentifiablePackage.<clinit>(IdentifiablePackage.java:59)
	at de.test.e4.editor.addons.ResourceProvider.initializePackages(ResourceProvider.java:82)
	at de.test.e4.editor.addons.ResourceProvider.initializeResources(ResourceProvider.java:43)
	at de.test.e4.editor.login.LoginForm.login(LoginForm.java:216)
	at de.test.e4.editor.login.LoginForm.access$5(LoginForm.java:210)
	at de.test.e4.editor.login.LoginForm$6.keyPressed(LoginForm.java:186)
	at org.eclipse.swt.widgets.TypedListener.handleEvent(TypedListener.java:167)
	at org.eclipse.swt.widgets.EventTable.sendEvent(EventTable.java:84)
	at org.eclipse.swt.widgets.Widget.sendEvent(Widget.java:1053)
	at org.eclipse.swt.widgets.Widget.sendEvent(Widget.java:1077)
	at org.eclipse.swt.widgets.Widget.sendEvent(Widget.java:1062)
	at org.eclipse.swt.widgets.Widget.sendKeyEvent(Widget.java:1104)
	at org.eclipse.swt.widgets.Text.sendKeyEvent(Text.java:1704)
	at org.eclipse.swt.widgets.Widget.sendKeyEvent(Widget.java:1100)
	at org.eclipse.swt.widgets.Widget.wmChar(Widget.java:1521)
	at org.eclipse.swt.widgets.Control.WM_CHAR(Control.java:4640)
	at org.eclipse.swt.widgets.Text.WM_CHAR(Text.java:2584)
	at org.eclipse.swt.widgets.Control.windowProc(Control.java:4528)
	at org.eclipse.swt.widgets.Text.windowProc(Text.java:2570)
	at org.eclipse.swt.widgets.Display.windowProc(Display.java:4976)
	at org.eclipse.swt.internal.win32.OS.DispatchMessageW(Native Method)
	at org.eclipse.swt.internal.win32.OS.DispatchMessage(OS.java:2546)
	at org.eclipse.swt.widgets.Display.readAndDispatch(Display.java:3756)
	at de.test.e4.editor.login.LoginForm$7.run(LoginForm.java:202)
	at org.eclipse.core.databinding.observable.Realm.runWithDefault(Realm.java:332)
	at de.test.e4.editor.login.LoginForm.createContents(LoginForm.java:197)
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
	at java.lang.reflect.Method.invoke(Method.java:601)
	at org.eclipse.e4.core.internal.di.MethodRequestor.execute(MethodRequestor.java:56)
	at org.eclipse.e4.core.internal.di.InjectorImpl.invokeUsingClass(InjectorImpl.java:229)
	at org.eclipse.e4.core.internal.di.InjectorImpl.invoke(InjectorImpl.java:206)
	at org.eclipse.e4.core.contexts.ContextInjectionFactory.invoke(ContextInjectionFactory.java:106)
	at org.eclipse.e4.ui.internal.workbench.swt.E4Application.createE4Workbench(E4Application.java:215)
	at org.eclipse.e4.ui.internal.workbench.swt.E4Application.start(E4Application.java:132)
	at org.eclipse.equinox.internal.app.EclipseAppHandle.run(EclipseAppHandle.java:196)
	at org.eclipse.core.runtime.internal.adaptor.EclipseAppLauncher.runApplication(EclipseAppLauncher.java:110)
	at org.eclipse.core.runtime.internal.adaptor.EclipseAppLauncher.start(EclipseAppLauncher.java:79)
	at org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseStarter.java:353)
	at org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseStarter.java:180)
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
	at java.lang.reflect.Method.invoke(Method.java:601)
	at org.eclipse.equinox.launcher.Main.invokeFramework(Main.java:629)
	at org.eclipse.equinox.launcher.Main.basicRun(Main.java:584)
	at org.eclipse.equinox.launcher.Main.run(Main.java:1438)
	at org.eclipse.equinox.launcher.Main.main(Main.java:1414)


This is not the only exception. These exceptions are thrown for each package that should be initialized.

The point is: This code worked for an RCP in Eclipse 3.7.2. Now, I started to create an RCP in Eclipse 4.2.1 using the existing model that was created under 3.7.2. (Creating the model with 4.2.1 does not make a difference).
Does anbody have an idea what could be wrong? Maybe it is an EMF version issue or something (the current version is 2.8.1 I think). I would be very thankful for any help.

Best regards
Bastian
icon14.gif  Re: [EMF] ClassCastException: $Proxy cannot be cast... [message #1007930 is a reply to message #1007906] Fri, 08 February 2013 09:32 Go to previous messageGo to next message
Bastian Wagenfeld is currently offline Bastian WagenfeldFriend
Messages: 183
Registered: January 2013
Senior Member
Hi,

the problem is solved. If I initialize the EMF packages before the RCP itself starts, everything works fine. They are now initialized in the start method of the Activator.

Bastian
Re: [EMF] ClassCastException: $Proxy cannot be cast... [message #1007991 is a reply to message #1007906] Fri, 08 February 2013 07:23 Go to previous messageGo to next message
Ed Merks is currently offline Ed MerksFriend
Messages: 33141
Registered: July 2009
Senior Member
Bastian,

Comments below.

On 08/02/2013 7:42 AM, Bastian Wagenfeld wrote:
> Hi,
>
> I have five EMF models that should be initialized during the RCP's
> startup. Therefore I call IdentifiablePackage.eINSTANCE.getClass();.
It shouldn't generally be necessary to do that when running in an
Eclipse environment where registrations in the plugin.xml ensure that
packages are known to the package registry.
> This triggers the following error:
>
> !ENTRY org.eclipse.emf.ecore 2 0 2013-02-08 07:24:22.715
> !MESSAGE $Proxy10 cannot be cast to
> de.test.model.identifiable.IdentifiableFactory
> !STACK 0
> java.lang.ClassCastException: $Proxy10 cannot be cast to
> de.test.model.identifiable.IdentifiableFactory
That looks very strange. Have you tried setting a breakpoint here?
What's a $Poxy10 I wonder? It looks like some kind of Java dynamic
proxy perhaps? EMF doesn't ever create Java dynamic proxies.

Presumably that line looks like this

public static ChangeFactory init()
{
try
{
ChangeFactory theChangeFactory =
(ChangeFactory)EPackage.Registry.INSTANCE.getEFactory("http://www.eclipse.org/emf/2003/Change");

if (theChangeFactory != null)
{
return theChangeFactory;
}
}
catch (Exception exception)
{
EcorePlugin.INSTANCE.log(exception);
}
return new ChangeFactoryImpl();
}

So, for some reason (that I can't know from what you've explained),
something other than your IdentifiableFactoryImpl is registered for your
package's namespace. You might try debugging

org.eclipse.emf.ecore.plugin.GeneratedPackageRegistryReader.readElement(IConfigurationElement,
boolean)

To see what registrations are taking place. Or perhaps there's even
some type of factory override involved:

org.eclipse.emf.ecore.plugin.FactoryOverrideRegistryReader.readElement(IConfigurationElement,
boolean)


> at
> de.test.model.identifiable.impl.IdentifiableFactoryImpl.init(IdentifiableFactoryImpl.java:34)
>
> at
> de.test.model.identifiable.IdentifiableFactory.<clinit>(IdentifiableFactory.java:26)
> at
> de.test.model.identifiable.impl.IdentifiablePackageImpl.<init>(IdentifiablePackageImpl.java:63)
> at
> de.test.model.identifiable.impl.IdentifiablePackageImpl.init(IdentifiablePackageImpl.java:89)
> at
> de.test.model.identifiable.IdentifiablePackage.<clinit>(IdentifiablePackage.java:59)
> at
> de.test.e4.editor.addons.ResourceProvider.initializePackages(ResourceProvider.java:82)
> at
> de.test.e4.editor.addons.ResourceProvider.initializeResources(ResourceProvider.java:43)
> at de.test.e4.editor.login.LoginForm.login(LoginForm.java:216)
> at de.test.e4.editor.login.LoginForm.access$5(LoginForm.java:210)
> at de.test.e4.editor.login.LoginForm$6.keyPressed(LoginForm.java:186)
> at
> org.eclipse.swt.widgets.TypedListener.handleEvent(TypedListener.java:167)
> at org.eclipse.swt.widgets.EventTable.sendEvent(EventTable.java:84)
> at org.eclipse.swt.widgets.Widget.sendEvent(Widget.java:1053)
> at org.eclipse.swt.widgets.Widget.sendEvent(Widget.java:1077)
> at org.eclipse.swt.widgets.Widget.sendEvent(Widget.java:1062)
> at org.eclipse.swt.widgets.Widget.sendKeyEvent(Widget.java:1104)
> at org.eclipse.swt.widgets.Text.sendKeyEvent(Text.java:1704)
> at org.eclipse.swt.widgets.Widget.sendKeyEvent(Widget.java:1100)
> at org.eclipse.swt.widgets.Widget.wmChar(Widget.java:1521)
> at org.eclipse.swt.widgets.Control.WM_CHAR(Control.java:4640)
> at org.eclipse.swt.widgets.Text.WM_CHAR(Text.java:2584)
> at org.eclipse.swt.widgets.Control.windowProc(Control.java:4528)
> at org.eclipse.swt.widgets.Text.windowProc(Text.java:2570)
> at org.eclipse.swt.widgets.Display.windowProc(Display.java:4976)
> at org.eclipse.swt.internal.win32.OS.DispatchMessageW(Native Method)
> at org.eclipse.swt.internal.win32.OS.DispatchMessage(OS.java:2546)
> at org.eclipse.swt.widgets.Display.readAndDispatch(Display.java:3756)
> at de.test.e4.editor.login.LoginForm$7.run(LoginForm.java:202)
> at
> org.eclipse.core.databinding.observable.Realm.runWithDefault(Realm.java:332)
> at
> de.test.e4.editor.login.LoginForm.createContents(LoginForm.java:197)
> at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
> at
> sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
> at
> sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
> at java.lang.reflect.Method.invoke(Method.java:601)
> at
> org.eclipse.e4.core.internal.di.MethodRequestor.execute(MethodRequestor.java:56)
> at
> org.eclipse.e4.core.internal.di.InjectorImpl.invokeUsingClass(InjectorImpl.java:229)
> at
> org.eclipse.e4.core.internal.di.InjectorImpl.invoke(InjectorImpl.java:206)
> at
> org.eclipse.e4.core.contexts.ContextInjectionFactory.invoke(ContextInjectionFactory.java:106)
> at
> org.eclipse.e4.ui.internal.workbench.swt.E4Application.createE4Workbench(E4Application.java:215)
> at
> org.eclipse.e4.ui.internal.workbench.swt.E4Application.start(E4Application.java:132)
> at
> org.eclipse.equinox.internal.app.EclipseAppHandle.run(EclipseAppHandle.java:196)
> at
> org.eclipse.core.runtime.internal.adaptor.EclipseAppLauncher.runApplication(EclipseAppLauncher.java:110)
> at
> org.eclipse.core.runtime.internal.adaptor.EclipseAppLauncher.start(EclipseAppLauncher.java:79)
> at
> org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseStarter.java:353)
> at
> org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseStarter.java:180)
> at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
> at
> sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
> at
> sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
> at java.lang.reflect.Method.invoke(Method.java:601)
> at org.eclipse.equinox.launcher.Main.invokeFramework(Main.java:629)
> at org.eclipse.equinox.launcher.Main.basicRun(Main.java:584)
> at org.eclipse.equinox.launcher.Main.run(Main.java:1438)
> at org.eclipse.equinox.launcher.Main.main(Main.java:1414)
>
> This is not the only exception. These exceptions are thrown for each
> package that should be initialized.
>
> The point is: This code worked for an RCP in Eclipse 3.7.2. Now, I
> started to create an RCP in Eclipse 4.2.1 using the existing model
> that was created under 3.7.2. (Creating the model with 4.2.1 does not
> make a difference).
> Does anbody have an idea what could be wrong? Maybe it is an EMF
> version issue or something (the current version is 2.8.1 I think). I
> would be very thankful for any help.
EMF 2.8 should be binary compatible with anything you've generated with
older versions. The best I can suggest is trying to determine what
object is coming back on the line
EPackage.Registry.INSTANCE.getEFactory(<your-ns-URI>) in the init
method. Who is creating that class? What is it? Also, you can look at
what's being registered? Is something registering conflicting
registrations for your package's nsURIs?
>
> Best regards
> Bastian


Ed Merks
Professional Support: https://www.macromodeling.com/
Re: [EMF] ClassCastException: $Proxy cannot be cast... [message #1008155 is a reply to message #1007991] Mon, 11 February 2013 06:45 Go to previous message
Bastian Wagenfeld is currently offline Bastian WagenfeldFriend
Messages: 183
Registered: January 2013
Senior Member
Hi,

thanks for your reply. The namespaces are set correctly, I checked that. The error only occurres, if I call the initialization when the RCP itself is running. The initilization was no problem in the 3.7.2 Eclipse at a very similar point. Now, I initialize it in the RCP's Activator class and it works. I'll try and investigate, what makes the error show up. I'll post it, if I have any further information.

Best regards
Bastian
Previous Topic:EMF-to-XSD Model Transformation
Next Topic:[CDO] ObjectCommitHistory get N last commits/items
Goto Forum:
  


Current Time: Thu Apr 25 22:47:25 GMT 2024

Powered by FUDForum. Page generated in 0.03608 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top