felix-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Neil Bartlett <njbartl...@gmail.com>
Subject Re: Embedded Dependencies
Date Mon, 15 Oct 2012 22:10:24 GMT
As your question states, both bundles contain the class 
"SoapSerializationEnvelope". This is incorrect. They should both import 
it from the same provider (or one could export it and the other import 
it). The goal is to ensure that each class is only loaded once, i.e. by 
one bundle, and imported by all the others that need to use it.

It does not matter that both copies of the class are identical in each 
bundle. If a class is loaded two times by two different class loaders 
then Java considers these to be two *different* classes, and they cannot 
be used interchangeably.

Usually LinkageError happens when exported packages refer from their 
public signatures to types in private packages. Incidentally if you 
build your bundle with a recent version of bnd then you will get a 
warning about this. As rule, the public methods of an exported package 
must only ever refer to types in exported packages.

Regards,
Neil

lessonz wrote:
>
> So, I have what I imagine cannot be a unique situation. I have a project
> consisting of multiple bundles. Some of these bundles have dependencies
> that are not themselves bundles. For example:
>
> <parent>
> <groupId>com.google.code.ksoap2-android</groupId>
> <artifactId>ksoap2-android</artifactId>
> <version>2.6.5</version>
> </parent>
>
> (If there is in fact a bundled version of this, I'm happy to hear 
> about it,
> but there are other dependencies that are also not bundles, so the 
> question
> remains.) So, I have an implementation class in BundleA and the interface
> it implements in BundleB. One of the overridden methods takes as an
> argument an instance of a class provided by the non-bundled 
> dependency. So,
> I tried to embed this dependency in both bundles. These bundles build and
> launch just fine, but when the method is called, there's a linkage error:
>
> [Restlet-18769836] ERROR com.sample.example.communications - [ERROR] :
> [com.sample.example.communications.RemoteCommSessionImpl-0] createInstance
> -> The POJO construct
> or invocation failed : loader constraint violation in interface itable
> initialization: when resolving method
> "com.sample.example.communications.RemoteCommSessionImp
> l.submitSoapRequest(Ljava/net/URL;Ljava/lang/String;Lorg/ksoap2/serialization/SoapSerializationEnvelope;)Lorg/ksoap2/serialization/SoapSerializationEnvelope;"
> t
> he class loader (instance of
> org/apache/felix/framework/BundleWiringImpl$BundleClassLoaderJava5) of the
> current class, com/sample/example/communications/RemoteCommS
> essionImpl, and the class loader (instance of
> org/apache/felix/framework/BundleWiringImpl$BundleClassLoaderJava5) for
> interface com/sample/example/interfaces/commun
> ications/RemoteCommSession have different Class objects for the type
> org/ksoap2/serialization/SoapSerializationEnvelope used in the signature
> java.lang.LinkageError: loader constraint violation in interface itable
> initialization: when resolving method
> "com.sample.example.communications.RemoteCommSessionIm
> pl.submitSoapRequest(Ljava/net/URL;Ljava/lang/String;Lorg/ksoap2/serialization/SoapSerializationEnvelope;)Lorg/ksoap2/serialization/SoapSerializationEnvelope;"
> the class loader (instance of
> org/apache/felix/framework/BundleWiringImpl$BundleClassLoaderJava5) of the
> current class, com/sample/example/communications/RemoteComm
> SessionImpl, and the class loader (instance of
> org/apache/felix/framework/BundleWiringImpl$BundleClassLoaderJava5) for
> interface com/sample/example/interfaces/commu
> nications/RemoteCommSession have different Class objects for the type
> org/ksoap2/serialization/SoapSerializationEnvelope used in the signature
> at java.lang.Class.getDeclaredConstructors0(Native Method)
> at java.lang.Class.privateGetDeclaredConstructors(Class.java:2389)
> at java.lang.Class.getConstructor0(Class.java:2699)
> at java.lang.Class.getDeclaredConstructor(Class.java:1985)
> at
> org.apache.felix.ipojo.InstanceManager.createObject(InstanceManager.java:651)
> at
> org.apache.felix.ipojo.InstanceManager.getPojoObject(InstanceManager.java:859)
> at
> org.apache.felix.ipojo.handlers.providedservice.ProvidedService$SingletonStrategy.getService(ProvidedService.java:786)
> at
> org.apache.felix.ipojo.handlers.providedservice.ProvidedService.getService(ProvidedService.java:318)
> at
> org.apache.felix.framework.ServiceRegistrationImpl.getFactoryUnchecked(ServiceRegistrationImpl.java:308)
> at
> org.apache.felix.framework.ServiceRegistrationImpl.getService(ServiceRegistrationImpl.java:219)
> at
> org.apache.felix.framework.ServiceRegistry.getService(ServiceRegistry.java:310)
> at org.apache.felix.framework.Felix.getService(Felix.java:3420)
> at
> org.apache.felix.framework.BundleContextImpl.getService(BundleContextImpl.java:468)
> at
> org.apache.felix.ipojo.IPojoContext.getService(IPojoContext.java:270)
> at org.apache.felix.ipojo.util.Tracker.getService(Tracker.java:441)
> at
> org.apache.felix.ipojo.util.DependencyModel.getService(DependencyModel.java:911)
> at
> org.apache.felix.ipojo.handlers.dependency.Dependency.createServiceObject(Dependency.java:662)
> at
> org.apache.felix.ipojo.handlers.dependency.Dependency.onGet(Dependency.java:633)
> at
> org.apache.felix.ipojo.InstanceManager.onGet(InstanceManager.java:1050)
> at ...
>
> Both depend on the same version of the dependency. I've cracked open both
> bundles and verified the embedded dependencies are the same exact size.
>
> So, I believe I can take these third party dependencies, turn them into
> bundles, and then everything is good to go. I think that is an option that
> will resolve this issue. Beyond that, is there some other way? Is there a
> better way? A more accepted approach to this?
>
> Thanks.

Mime
  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message