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

Include sun.misc to Import-Package #1518

Closed
amitjoy opened this issue Apr 24, 2019 · 2 comments
Closed

Include sun.misc to Import-Package #1518

amitjoy opened this issue Apr 24, 2019 · 2 comments

Comments

@amitjoy
Copy link

amitjoy commented Apr 24, 2019

Due to the usage of sun.misc package in com.google.gson.internal.UnsafeAllocator, we should explicitly specify sun.misc package in Import-Package. This applies to most of the OSGi runtimes since sun.misc is provided as a system package. Without sun.misc package in Import-Package, it can only work in runtimes where sun.misc is provided as part of boot delegation.

The boot delegation feature in OSGi is really intended as a workaround for some assumptions made in JRE implementations. Certain internal classes are expected to be visible from any classloader, which would not normally be the case in OSGi, and so they have to be added to boot delegation. You may also need to use boot delegation when you have a bytecode instrumentation tool, e.g. a code coverage or performance measurement tool that adds a little bit of code to every class. The instrumented code usually has dependencies, but you wouldn’t want to explicitly add to the Import-Package statement of every bundle because you will probably remove the instrumentation before the bundle goes into production.

The risks associated with boot delegation are quite severe. The first is that a bundle might seem to be working, but only accidentally due to the boot delegation setting of the platform you are running it on. When you move it to another OSGi application it suddenly throws NoClassDefFoundError. You should have imported the package because then it’s clear to everybody what needs to be done to make the bundle work.

The second problem is that boot delegation overrides the choices of every bundle. When you put a package in boot delegation, it’s not just that every bundle can use that package… in fact, every bundle must use that package, even if they had their own copy or if they wanted to import a different version, etc. In other words, it breaks the foundation of OSGi’s modularity.

@amitjoy amitjoy changed the title Add sun.misc to Import-Package Include sun.misc to Import-Package Apr 25, 2019
@Marcono1234
Copy link
Collaborator

Marcono1234 commented Jul 26, 2022

Apparently at some point the Import-Package was added implicitly during build, but caused issues (#1981), so it was made explicitly optional in #1993. Hopefully that was the correct approach; thanks a lot for this detailed explanation!

@eamonnmcmanus
Copy link
Member

I don't think there's anything further to do here. Feel free to comment further otherwise.

@eamonnmcmanus eamonnmcmanus closed this as not planned Won't fix, can't repro, duplicate, stale Jul 27, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants