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.