Twitter github

OSGi (Equinox) and Strict Mode

Do you recall seeing all those access restriction warnings in your workspace because you’re using some internal API from another plug-in? Well, those can come back and bite you if your plug-in is running an in environment where osgi.resolverMode=strict is turned on. What is ‘strict mode’ mean in this context? It basically means that Equinox’s resolver will throw ClassNotFoundException’s when it comes across a class that is in a package marked internal.

There was an issue recently where the RCP stack had trouble running in strict mode. There were a few naughty RCP-related extensions that were referencing internal classes in other RCP plug-ins. These extensions are frustratingly hard to find if there’s no tooling. For example, when launching the RCP ‘Hello World’ example in strict mode, you come across this exception:

You think to your self, well pffft, I can fix that, I’ll just x-friend that package to my plug-in and be done with:

Then you go to launch the RCP ‘Hello World’ example and you get this frustrating exception again:

This is when the game of finding the offenders doesn’t become fun anymore. Actually, the feeling is very similar to when that stupid dog was laughing at you in Duck Hunt because you couldn’t shoot all the ducks:

However, never fear, PDE completed an enhancement that will make it easier for you to find these offenders:

The solution to this problem is to use x-friends or as a better best practice, don’t refer to internal classes outside your plug-in in your extensions as this is brittle.

Happy hunting.

  • kartben

    I love the comparison with “Duck Hunt” :)

    Great enhancement anyway :)

  • kartben

    I love the comparison with “Duck Hunt” :)Great enhancement anyway :)

  • Neil Bartlett

    To avoid confusion, it should be pointed out that what you’re talking about here is an Eclipse-specific extension to OSGi, rather than standard OSGi functionality.

    In OSGi, non-exported packages are always internal, and there’s no “strict” or “non-strict” mode you can use to change that. The packages you’re referring to are actually exported!… but they are marked as “internal” using a special directive that is only understood by Equinox.

    In my opinion, exporting packages and then saying they’re internal doesn’t make a lot of sense. Maybe it’s necessary to do this in Eclipse for legacy reasons, but I believe x-internal and x-friend shouldn’t be avoided wherever possible.

  • Neil Bartlett

    To avoid confusion, it should be pointed out that what you’re talking about here is an Eclipse-specific extension to OSGi, rather than standard OSGi functionality.In OSGi, non-exported packages are always internal, and there’s no “strict” or “non-strict” mode you can use to change that. The packages you’re referring to are actually exported!… but they are marked as “internal” using a special directive that is only understood by Equinox.In my opinion, exporting packages and then saying they’re internal doesn’t make a lot of sense. Maybe it’s necessary to do this in Eclipse for legacy reasons, but I believe x-internal and x-friend shouldn’t be avoided wherever possible.

  • Chris Aniszczyk (zx)

    Thanks Neil, I made the correction. I’m general sometimes ;)

  • Chris Aniszczyk (zx)

    Thanks Neil, I made the correction. I’m general sometimes ;)