1

I have a plugin A which exports the package foo.bar. In the package foo.bar there is a abstract class FooBar with default scope members. In a plugin B I like to extend the FooBar within the same package and access the default scoped fields.

Plugin A manifest:

.
Bundle-SymbolicName: A    
Export-Package: foo.bar
.

Plugin B manifest:

.
Bundle-SymbolicName: B    
Require-Bundle: A
.

Class FooBar in Plugin A:

package foo.bar;

public abstract class FooBar{
  int min = -1;
}

Class MyFooBar in Plugin B:

package foo.bar;

public class MyFooBar extends FooBar{
  public void setMin(int min){
   this.min = min;
  }
}

The result:
..Caused by: java.lang.IllegalAccessError: tried to access field foo.bar.FooBar.min from class foo.bar.MyFooBar

In a normal java environment I can access package-scoped members if I define my class in the same package. Apparently this is not so in OSGI-Environment, is it??

Michael K.
  • 1,738
  • 2
  • 17
  • 35
  • Is the Bundle-SymbolicName for Plugin B really "A"? Duplicate names can cause odd behaviour – Simon Aug 07 '12 at 13:24
  • Thanks for the information to Simon and Fredrik. My problem is I extended the log4j-Framework about a pattern-class which extends the the PatternConverter few years ago. And now I have to port it to eclipse-bundles. – Michael K. Aug 07 '12 at 13:58

3 Answers3

0

You are correct, OSGI plugins aren't the same as java packages. If you truly want to share the same min value in both plugins, the best option is to share it through extension points. Extension points are the OSGI way to share data and code between plugins. This leads to a solution that doesnt cause a tight coupling between the plugins.

If plugin B truly must access the min value in plugin A that might be an indication that those two classes should be in the same plugin.

Also see this question

More information about extension points can be found here

Community
  • 1
  • 1
Fredrik
  • 10,626
  • 6
  • 45
  • 81
0

Eclipse plug-ins / OSGi bundles each have their own separate classloaders (and thus namespaces). Package private means same package and classloader.

Simon
  • 720
  • 4
  • 12
0

Try to make the bundle B a fragment for A (if it is possible in your case). Than B can access package-private classes because there is the same package name and class loader.

Read the following article Split Packages – An OSGi nightmare - it explains the problem in clear way.

Qinto
  • 205
  • 2
  • 12