Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[OSGi] Multibindings and AssistedInject JARs need version property for fragment host #1049

Closed
kenwenzel opened this issue Sep 29, 2016 · 0 comments · Fixed by #1701
Closed

Comments

@kenwenzel
Copy link
Contributor

kenwenzel commented Sep 29, 2016

The libraries "guice-multibindings" and "guice-assistedinject" are implemented as OSGi fragements for the "com.google.inject" bundle.
If two versions (e.g. 3.0.0 and 4.0.0) of Guice are used within the same OSGi container (Eclipse Equinox) then the following exception occurs:

java.lang.LinkageError: loader constraint violation: loader (instance of org/eclipse/osgi/internal/loader/EquinoxClassLoader) previously initiated loading for a different type with name "com/google/inject/Binder"
at java.lang.ClassLoader.defineClass1(Native Method)
at java.lang.ClassLoader.defineClass(Unknown Source)
at org.eclipse.osgi.internal.loader.ModuleClassLoader.defineClass(ModuleClassLoader.java:273)
at org.eclipse.osgi.internal.loader.classpath.ClasspathManager.defineClass(ClasspathManager.java:632)
at org.eclipse.osgi.internal.loader.classpath.ClasspathManager.findClassImpl(ClasspathManager.java:586)
at org.eclipse.osgi.internal.loader.classpath.ClasspathManager.findLocalClassImpl(ClasspathManager.java:538)
at org.eclipse.osgi.internal.loader.classpath.ClasspathManager.findLocalClass(ClasspathManager.java:525)
at org.eclipse.osgi.internal.loader.ModuleClassLoader.findLocalClass(ModuleClassLoader.java:325)
at org.eclipse.osgi.internal.loader.BundleLoader.findLocalClass(BundleLoader.java:334)
at org.eclipse.osgi.internal.loader.BundleLoader.findClassInternal(BundleLoader.java:411)
at org.eclipse.osgi.internal.loader.BundleLoader.findClass(BundleLoader.java:361)
at org.eclipse.osgi.internal.loader.BundleLoader.findClass(BundleLoader.java:353)
at org.eclipse.osgi.internal.loader.ModuleClassLoader.loadClass(ModuleClassLoader.java:161)
at java.lang.ClassLoader.loadClass(Unknown Source)
at com.google.inject.multibindings.Multibinder.newRealSetBinder(Multibinder.java:176)
at com.google.inject.multibindings.Multibinder.newSetBinder(Multibinder.java:132)

I think this is due to the following line within the MANIFEST.MF of each bundle:

Fragment-Host: com.google.inject

The Fragment-Host should not only specify the host bundle but also its version:

Fragment-Host: com.google.inject;bundle-version=4.0.0

enilink-git pushed a commit to komma/komma that referenced this issue Sep 29, 2016
kenwenzel added a commit to kenwenzel/guice that referenced this issue Sep 30, 2016
* Fixes google#1049
* Ensures that extensions are only applied to a specific version of com.google.inject
copybara-service bot pushed a commit that referenced this issue Apr 20, 2023
copybara-service bot pushed a commit that referenced this issue Apr 22, 2023
… Much thanks to @kenwenzel and @mcculls for their help figuring out the right incantation for this.

PiperOrigin-RevId: 525810926
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment