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

Add uses constraints to Export-Package header #735

Open
sewe opened this issue Nov 11, 2015 · 2 comments
Open

Add uses constraints to Export-Package header #735

sewe opened this issue Nov 11, 2015 · 2 comments

Comments

@sewe
Copy link

sewe commented Nov 11, 2015

Issue #120 requested OSGi headers. Unfortunately, the Export-Package headers lack uses directives, which can be very important to avoid ClassCastExceptions and other wiring-related issue. Here’s an issue I recently came across (see Eclipse Bug 481923 for the real scenario):

  • User installs bundle com.google.gson in version X.
  • User installs bundle org.example.one, which has an Import-Package on com.google.gson;version="[X,X+1)" and an Export-Package of org.example.one;uses="com.google.gson".
    • Bundle org.example.one is wired to bundle com.google.gson, version X.
  • User installs bundle com.google.gson in version Y > X. The wiring of bundle org.example.one remains unchanged due to the version constraint on org.example.one’s Import-Package.
  • User installs bundle org.example.two, which has an Import-Package on com.google.gson;version="[X,Y+1)", com.google.gson.annotations;version="[X,Y+1)", and on org.example.one.
    • Bundle org.example.two is wired to package com.google.gson in version X, as the uses constraints of org.example.one force org.example.two to use the same version, and to com.google.gson.annotations in version Y, as it is the newest available.
    • When org.example.two uses com.google.gson, version X, to deserialize JSON, its @SerializedName annotations won’t be honored, as they are loaded with the classloader of com.google.gson, version Y.

You should probably consider using the maven-bundle-plugin, as it can compute uses directives automatically; maintaining them manually is IMHO far to error-prone.

@swankjesse
Copy link
Collaborator

Pull requests welcome on this. I don't think any of us understand, or are eager to understand OSGi.

@sewe
Copy link
Author

sewe commented Nov 11, 2015

Pull requests welcome on this. I don't think any of us understand, or are eager to understand OSGi.

Fair enough. I’ll try to come up with something that leaves the existing headers unchanged and only adds the uses directives.

Anyway: For you understanding, all that

Export-Package: com.google.gson;uses:="com.google.gson.annotations"

means is “If you import com.google.gson and com.google.gson.annotations, you must do so from the same bundle (so that they will be loaded with the same classloader).”

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants