Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.

Bug 230279

Summary: Bundles marked as x-friends should (optionally) not be flagged with API Usage errors
Product: [Eclipse Project] PDE Reporter: Martin Oberhuber <mober.at+eclipse>
Component: API ToolsAssignee: PDE API Tools Inbox <pde-apitools-inbox>
Status: CLOSED WONTFIX QA Contact:
Severity: enhancement    
Priority: P3 CC: curtis.windatt.public, darin.eclipse, john.cortell, Michael_Rennie, stepper
Version: 3.4   
Target Milestone: ---   
Hardware: PC   
OS: Windows XP   
Whiteboard:

Description Martin Oberhuber CLA 2008-05-05 15:11:36 EDT
Build Id: I20080502-0100 (3.4M7)

OSGi encourages the use of an x-friends:="foo" markup in Manifest.mf in order to mark bundles that are meant to work closely together -- such as the UI and the non-UI part of a component, which must be separate bundles but are developed together.

Given that API Tooling does not flag API Usage Errors inside one and the same bundle, the ranged of "allowed non-API use" should be extended to those bundles declared as x-friends.

In order to allow checking API boundaries, it might make sense to make that lifting of limitation optional via a Preference.
Comment 1 Darin Wright CLA 2009-03-20 11:45:04 EDT
Being a friend allows one to reference internals without warnings - i.e. one can use internal implementations. It's nore clear that this should allow one to break API rules of engagement. I think they could be different things.
Comment 2 John Cortell CLA 2009-11-21 17:02:55 EST
I agree with Darin. I think an example makes it obvious that a separate mechanism is needed:

- I have a plugin com.acme.recorder.core that exports package com.acme.recorder.core.interfaces.
- The package isn't internal. I.e., it's visible to all downstream plugins
- In the package is interface com.acme.recorder.IRecord
- IRecord is meant to be used by clients but not implemented by them. It's marked with @noextend and @noimplement.
- I also have a plugin com.acme.recorder.digital. That plugin has implementations of IRecord. Currently that results in an API tooling violation.

I can't use the existing the OSGi x-friends mechanism to allow the recorder.digital plugin to be excluded from the IRecord API restriction for the simple reason that IRecord is in a public package. You can't associate x-friends to a package that is visible to all downstream plugins. Everyone is automatically a friend of that package.
Comment 3 John Cortell CLA 2010-01-20 18:03:23 EST
I'm seeing in Eclipse 3.6M4 that API Usage restrictions warnings are being silenced by x-friends settings, which is troubling, as its hiding warnings that I don't want hidden. Before I explain, can someone tell me if the behavior has intentionally changed?
Comment 4 John Cortell CLA 2010-01-20 18:06:59 EST
Nevermind. Looks like a misdiagnosis.
Comment 5 Eike Stepper CLA 2010-07-26 03:13:56 EDT
I *understand* the arguments from Darin in comment #1 and from John in comment #2 but I think we should be a bit more pragmatic as the current situation is really annoying.

If someone is really insisting on x-friends being ignored can't we make that configurable?
Comment 6 Darin Wright CLA 2010-07-26 09:23:47 EDT
It would be possible to make this configurable. By default x-friends should be flagged with illegal API use - but there could be an option to allow illegal use between x-friends.
Comment 7 Eike Stepper CLA 2010-07-26 11:20:58 EDT
Darin, do you have an idea on when it could be available?
Comment 8 Darin Wright CLA 2010-07-26 15:15:20 EDT
(In reply to comment #7)
> Darin, do you have an idea on when it could be available?

I'm not sure this will make the 3.7 plan based on available resources/priorities. It's possible that someone will get to implementing this (I don't think it's that large of a work item), but a patch is always welcome.
Comment 9 Eike Stepper CLA 2011-07-04 05:48:26 EDT
I'm still very keen on this new optional setting/functionality. Would it be possible to get it soon in this new cycle?
Comment 10 Curtis Windatt CLA 2011-07-05 10:00:36 EDT
There are currently no plans to work on this in the 3.8 cycle
Comment 11 Michael Rennie CLA 2013-03-20 17:40:20 EDT
I am inclined to mark this wontfix, the reason being that consumers of restricted API can simply add a filter for the illegal usage. To me it makes more sense to add filters as it forces consumers to explicitly acknowledge that they are breaking the rules, rather than all current and future illegal use not being reported at all because of x-friends use.
Comment 12 Eike Stepper CLA 2013-03-21 03:22:16 EDT
(In reply to comment #11)
> I am inclined to mark this wontfix, the reason being that consumers of
> restricted API can simply add a filter for the illegal usage. To me it makes
> more sense to add filters as it forces consumers to explicitly acknowledge
> that they are breaking the rules, rather than all current and future illegal
> use not being reported at all because of x-friends use.

That's clearly the way with less (no) effort in API Tools. But I hoped that we could get something as cool as http://bndtools.org/whatsnew2-0-0.html#enhanced-semantic-versioning ;-(
Comment 13 Michael Rennie CLA 2013-03-21 13:12:52 EDT
(In reply to comment #12)

> That's clearly the way with less (no) effort in API Tools. But I hoped that
> we could get something as cool as
> http://bndtools.org/whatsnew2-0-0.html#enhanced-semantic-versioning ;-(

The more I think about this, perhaps we could add this support in, but have it off by default. I ran into a very good use case for this working on the new platform UI APIs where one bundle provides the restricted interfaces and then many more provide the default implementations of those interfaces - in that use case it is time-consuming to add a pile of filters for each use, when all of them would be allowed (and the illegal access restrictions are also removed via the x-friends directive).

We already have all of the framework hooks in API tools to support this, see:

1. IApiAccess
2. IApiDescription#resolveAccessLevel

I would envision the solution being as simple as adding a check in our problem detectors' #considerReference callbacks.
Comment 14 Curtis Windatt CLA 2013-03-22 14:54:43 EDT
(In reply to comment #13)
> The more I think about this, perhaps we could add this support in, but have
> it off by default. I ran into a very good use case for this working on the
> new platform UI APIs where one bundle provides the restricted interfaces and
> then many more provide the default implementations of those interfaces - in
> that use case it is time-consuming to add a pile of filters for each use,
> when all of them would be allowed (and the illegal access restrictions are
> also removed via the x-friends directive).

In all the examples I can find in Platform UI we run into the case described by John in comment #2.  The package declaring the interface is public API (exported with no restrictions).  Adding the x-friend setting treats the package as internal.

For example 
org.eclipse.ui.internal.themes.CascadingColorRegistry
illegally extends 
org.eclipse.jface.resource.ColorRegistry

We would need an entirely new mechanism to support this so I am not in support of this for Kepler.

Two more possible solutions that I wouldn't recommend:
1) Reverse the x-friend lookup.  In the example, org.eclipse.ui.internal.themese would x-friend jface.  This would look very wrong in the manifest though because you are stating that cannot depend on you is allowed to use your internal code.
2) Look for other x-friend directives.  If another package declares your bundle as an x-friend ignore all illegal api use from that bundle.  I think this is a poor idea because it is opaque to the user, x-friending a single package would turn off all illegal use checks.
Comment 15 Michael Rennie CLA 2013-04-02 14:32:56 EDT
(In reply to comment #14)

> We would need an entirely new mechanism to support this so I am not in
> support of this for Kepler.
 
Have to agree with this. I'm not in favor of creating our own way to handle this.

> Two more possible solutions that I wouldn't recommend:
> 1) Reverse the x-friend lookup.  In the example,
> org.eclipse.ui.internal.themese would x-friend jface.  This would look very
> wrong in the manifest though because you are stating that cannot depend on
> you is allowed to use your internal code.
> 2) Look for other x-friend directives.  If another package declares your
> bundle as an x-friend ignore all illegal api use from that bundle.  I think
> this is a poor idea because it is opaque to the user, x-friending a single
> package would turn off all illegal use checks.

Agree again. Neither of those sound good.

Since we have a perfectly good system of using filters (and commented filters), I am going to close this wontfix.