Bug 544946 - Warn about usage of optional dependencies in Java code
Summary: Warn about usage of optional dependencies in Java code
Status: NEW
Alias: None
Product: PDE
Classification: Eclipse Project
Component: UI (show other bugs)
Version: 4.11   Edit
Hardware: All All
: P3 enhancement (vote)
Target Milestone: ---   Edit
Assignee: PDE-UI-Inbox CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2019-03-01 06:59 EST by Stephan Herrmann CLA
Modified: 2019-08-12 07:28 EDT (History)
2 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Stephan Herrmann CLA 2019-03-01 06:59:09 EST
In previous bugs regarding optional dependencies focus was on tolerating of those that are missing in the target platform, good.
At the other end of the spectrum there's a risk of (unexpected) runtime failures if those optional dependencies are accidentally used in non-optional parts of my Java code.

I suggest that PDE should define access rules to flag optionally accessible packages as discouraged. This gives users a chance to make an informed decision between avoiding the possibly-missing package or guarding that code section with error handling / fall back solutions.

Ideally the resulting "discouraged" warnings should mention optionality as the root cause, but I haven't checked if such information can be transported via access rules.

To make this a premium feature, optionality should be traced all the way through transitive (re-exported) dependencies, i.e., if any segment in the transitive dep path is optional, the target package should be discouraged.
Comment 1 Stephan Herrmann CLA 2019-03-01 07:02:14 EST
If people agree on the idea, I might try to implement this during the 4.12 time frame.
Comment 2 Vikas Chandra CLA 2019-05-17 00:07:45 EDT
>> a risk of (unexpected) runtime failures if those optional dependencies are >> accidentally used in non-optional parts of my Java code.

Can you please attach a sample project/s demonstrating this problem?
Comment 3 Julian Honnen CLA 2019-05-20 10:05:53 EDT
Optional dependencies are also used for compile-time dependencies like Nullability or OSGi annotations. Implementing this feature via access rules would falsely flag those.
Comment 4 Stephan Herrmann CLA 2019-05-20 11:33:09 EDT
(In reply to Julian Honnen from comment #3)
> Optional dependencies are also used for compile-time dependencies like
> Nullability or OSGi annotations. Implementing this feature via access rules
> would falsely flag those.

We could possibly exempt annotations from this validation, OK?
Unless those are retention=RUNTIME which makes them mandatory :)