Colin P. Hill
Colin P. Hill

Reputation: 422

OSGi `uses` constraint violation, even though compatible exporters exist

I'm seeing this error when I try to install a bundle in my OSGi container:

Error executing command: Uses constraint violation. Unable to resolve resource com.example.myproject [com.example.myproject/5.0.0.SNAPSHOT] because it is exposed to package 'javax.jms' from resources com.example.resource1 [com.example.resource1/2.0.1] and com.example.resource2 [com.example.resource2/1.1.1] via two dependency chains.

Chain 1:
  com.example.myproject [com.example.myproject/5.0.0.SNAPSHOT]
    import: (&(osgi.wiring.package=javax.jms)(version>=2.0.0)(!(version>=3.0.0)))
     |
    export: osgi.wiring.package: javax.jms
  com.example.resource1 [com.example.resource1/2.0.1]

Chain 2:
  com.example.myproject [com.example.myproject/5.0.0.SNAPSHOT]
    import: (&(osgi.wiring.package=com.example.intermediary)(version>=7.2.0)(!(version>=8.0.0)))
     |
    export: osgi.wiring.package=com.example.intermediary; uses:=javax.jms
  com.example.intermediary [com.example.intermediary/7.2.0]
    import: (&(osgi.wiring.package=javax.jms)(version>=1.1.0)(!(version>=3.0.0)))
     |
    export: osgi.wiring.package: javax.jms
  com.example.resource2 [com.example.resource2/1.1.1]

As far as I can tell, the package version exported by com.example.resource1 can satisfy both chains. So why wouldn't it just use resource1 in both places?

Upvotes: 0

Views: 172

Answers (1)

Ancoron
Ancoron

Reputation: 2733

This will not work because there is no guarantee that loading a class from javax.jms it will end up only at bundle com.example.resource1 (which exports the only valid version of the package). So within a certain "wiring" state of a bundle (every resolved package it imports at runtime, transitively), there should never be packages in different versions.

This is called Class space consistency and is defined in OSGi Core 7 - 3.7.6 Package Constraints.

Once the core JVM has learned to differentiate classes in different versions, this restriction might not be needed anymore - as long as the consequences are made clear there is control over it.

Upvotes: 1

Related Questions