"Access restriction" error in Eclipse plugins

I spent quite a lot of time today trying to debug “Access restriction” error in one of my Eclipse plugins. In the last four years of Eclipse plugin development, I don’t recall ever facing this issue, but today suddenly some of the imports in one of the classes in my Eclipse plugin were flagged off as errors –

Access restriction: The type ISelection is not accessible due to restriction on required library <eclipse-path>\eclipse\plugins\org.eclipse.jface_3.6.1.M20100825-0800.jar

I had seen warnings about ‘restricted access’ for some of the imports earlier, but those were for classes that Eclipse discouraged to use e,g, for internal Eclipse classes. But today I was seeing errors.

The error does not tell much about what could have gone wrong. ISelection is exported from jface plugin and it is a public interface. And I had used this class without any error in other plugins.

A quick search on the net and I found a couple of suggestions – one most common suggestion was to remove and add JRE lib again from the project build properties (in Project Properties->Java Build Path->Libraries). Though the solution was suggested for the same error, the class in the error was JDK built-in class, so I guess this suggestion might work for such cases.

Another solution was to turn-off this error. You can do so by going to Preferences->Java->Compiler->Errors/Warnings/Deprecated and restricted API->Forbidden reference (access rule) and changing its value from ‘Error’ to ‘Warning’. I did this and the error was gone and was replaced by warning. I executed my application and this warning did not seem to cause any problem.

However I was curious to find solution for this and did not want to see warnings too. It was obvious that the error was related to plugins I had listed in dependencies (required plugins for my plugin). I removed all dependencies and added them back in different order. To my surprise, this fixed the problem. I had required plugins in following order in my MANIFEST.MF –

Require-Bundle: org.eclipse.core.runtime,
org.eclipse.debug.core,
my-plugin1,
my.plugin2,
my.plugin2,
org.eclipse.ui

I changed this to –

Require-Bundle: my.plugin1,
my.plugin2,
org.eclipse.debug.core,
org.eclipse.core.runtime,
org.eclipse.ui,
my.plugin3

I don’t know how to figure out the correct order for required plugins. As far as I know, OSGi does not require you to specify required bundles in any particular order. So this could be a limitation of Eclipse implementation.

-Ram Kulkarni

2 Replies to “"Access restriction" error in Eclipse plugins”

Leave a Reply

Social