|
Re: [CDO] Loading JAVA_CLASS CdoType -> ClassNotFoundException [message #1826662 is a reply to message #1826650] |
Tue, 28 April 2020 13:15 |
Linuxhippy Mising name Messages: 71 Registered: July 2009 |
Member |
|
|
Are there any downsides in changing CDOs implementation to using the ContextClassLoader instead of what ObjectInputStream does?
Something like (CDOTypeImpl):
ObjectInputStream in = new ObjectInputStream(new ByteArrayInputStream((byte[])value))
{
protected Class<?> resolveClass(ObjectStreamClass desc) throws IOException, ClassNotFoundException
{
String name = desc.getName();
try {
return Class.forName(name, false, Thread.currentThread().getContextClassLoader());
} catch (ClassNotFoundException ex) {
return super.resolveClass(desc);
}
}
};
[Updated on: Tue, 28 April 2020 13:15] Report message to a moderator
|
|
|
Re: [CDO] Loading JAVA_CLASS CdoType -> ClassNotFoundException [message #1826665 is a reply to message #1826662] |
Tue, 28 April 2020 13:38 |
|
All your conclusions seem to be correct. I suspect that in the past 15 years nobody has tried to use org.eclipse.emf.cdo.common.model.CDOType.JAVA_CLASS. I'd have to study to implications of changing the ObjectInputStream's classloader. Perhaps it's just simpler to use an existing Equinox mechanism, e.g., "Eclipse-BuddyPolicy". If you have the sources of CDO available you can prototype it. Just two changes are needed:
1) In /org.eclipse.emf.cdo.common/META-INF/MANIFEST.MF add the following line:
Eclipse-BuddyPolicy: registered
2) In your application bundle's manifest add the following line:
Eclipse-RegisterBuddy: org.eclipse.emf.cdo.common
If you confirm that this solves the problem I will change the org.eclipse.emf.cdo.common bundle accordingly...
Cheers
/Eike
----
http://www.esc-net.de
http://thegordian.blogspot.com
http://twitter.com/eikestepper
|
|
|
Re: [CDO] Loading JAVA_CLASS CdoType -> ClassNotFoundException [message #1826675 is a reply to message #1826665] |
Tue, 28 April 2020 16:29 |
Linuxhippy Mising name Messages: 71 Registered: July 2009 |
Member |
|
|
Hi Eike,
Thanks a lot for taking a look at this.
I gave your suggestion a try, however I was not successful unfortunately - I still get the ClassNotFoundExceptions - even when trying to use the context class loader.
However ObjectInputStream seems to do a good job finding an appropriate class loader - it seems the BundleLoader is queried for the serialized class - still it seems not to be able to locate the class in question.
I wonder - are there other cases where CDO bundles have to load application-specific classes?
In case the Buddy-approach doesn't work (maybe it was just a mistake on my side), would an optional Classloader (system property or thread local) be an option? In this case the default behavour would stay unchanged.
Caused by: java.lang.ClassNotFoundException: some.proprietary.package.EnumClass cannot be found by org.eclipse.emf.cdo.common_4.9.1 //increased version to be sure the plugin hasn't been cached somewhere / I am really running with the new manifest
at org.eclipse.osgi.internal.loader.BundleLoader.findClassInternal(BundleLoader.java:514)
at org.eclipse.osgi.internal.loader.BundleLoader.findClass(BundleLoader.java:425)
at org.eclipse.osgi.internal.loader.BundleLoader.findClass(BundleLoader.java:417)
at org.eclipse.osgi.internal.loader.ModuleClassLoader.loadClass(ModuleClassLoader.java:171)
at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:522)
at java.base/java.lang.Class.forName0(Native Method)
at java.base/java.lang.Class.forName(Class.java:398)
at java.base/java.io.ObjectInputStream.resolveClass(ObjectInputStream.java:727)
at org.eclipse.emf.cdo.internal.common.model.CDOTypeImpl$25$1.resolveClass(CDOTypeImpl.java:609) // Left over from experiments
at java.base/java.io.ObjectInputStream.readNonProxyDesc(ObjectInputStream.java:1943)
at java.base/java.io.ObjectInputStream.readClassDesc(ObjectInputStream.java:1829)
at java.base/java.io.ObjectInputStream.readEnum(ObjectInputStream.java:2069)
at java.base/java.io.ObjectInputStream.readObject0(ObjectInputStream.java:1640)
at java.base/java.io.ObjectInputStream.readObject(ObjectInputStream.java:464)
at java.base/java.io.ObjectInputStream.readObject(ObjectInputStream.java:422)
at org.eclipse.emf.cdo.internal.common.model.CDOTypeImpl$25.convertToEMF(CDOTypeImpl.java:614)
[Updated on: Tue, 28 April 2020 16:40] Report message to a moderator
|
|
|
|
|
|
|
|
Powered by
FUDForum. Page generated in 0.03993 seconds