Bug 561712 - Add constructors to Status and MultiStatus to accept Class<?> as identifier
Summary: Add constructors to Status and MultiStatus to accept Class<?> as identifier
Status: RESOLVED FIXED
Alias: None
Product: Equinox
Classification: Eclipse Project
Component: Components (show other bugs)
Version: 4.16   Edit
Hardware: All All
: P3 normal (vote)
Target Milestone: 4.16 M1   Edit
Assignee: Alexander Fedorov CLA
QA Contact:
URL:
Whiteboard:
Keywords: noteworthy
Depends on:
Blocks:
 
Reported: 2020-04-02 11:35 EDT by Alexander Fedorov CLA
Modified: 2021-04-22 16:57 EDT (History)
5 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Alexander Fedorov CLA 2020-04-02 11:35:02 EDT
There is a lot of code around storing/retrieving pluginId spread through bundles.

Let's add convinient constructors that can retrieve Bundle Symbolic Context for the given class. The fallback without OSGi running will be to get Class FQN.

```
	private String identifier(Class<?> caller) {
		return Optional.ofNullable(FrameworkUtil.getBundle(caller))//
				.map(b -> b.getSymbolicName())//
				.orElse(Optional.ofNullable(caller)//
						.map(c -> c.getName())//
						.orElse(Status.class.getName()));
	}

```
Comment 1 Eclipse Genie CLA 2020-04-02 12:02:01 EDT
New Gerrit change created: https://git.eclipse.org/r/160386
Comment 2 Alexander Fedorov CLA 2020-04-02 12:04:46 EDT
@Lars please have a look, it can help to remove a lot of code around logging
Comment 4 Lars Vogel CLA 2020-04-03 12:38:02 EDT
Cool. Alexander, please add to N&N and provide a few Gerrits for using the new API in platform.
Comment 5 Alexander Kurtakov CLA 2020-04-04 02:49:45 EDT
This made tonight I-build fail.
Comment 6 Eclipse Genie CLA 2020-04-04 03:05:03 EDT
New Gerrit change created: https://git.eclipse.org/r/160466
Comment 8 Sebastian Ratz CLA 2020-04-06 11:48:16 EDT
We also got build failures in our code now:


 	IStatus status = new Status(IStatus.ERROR, null, null);
 	                 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
 The constructor Status(int, Class<?>, String) is ambiguous


Isn't this an incompatible change?
Comment 9 Alexander Fedorov CLA 2020-04-06 12:22:25 EDT
(In reply to Sebastian Ratz from comment #8)
> We also got build failures in our code now:
> 
> 
>  	IStatus status = new Status(IStatus.ERROR, null, null);
>  	                 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
>  The constructor Status(int, Class<?>, String) is ambiguous
> 
> 
> Isn't this an incompatible change?

Using `null` makes it incompatible. I would say this is an API misuse and it should fail with IllegalArgumentException on runtime.
Comment 10 Thomas Watson CLA 2020-04-06 14:19:37 EDT
(In reply to Sebastian Ratz from comment #8)
> We also got build failures in our code now:
> 
> 
>  	IStatus status = new Status(IStatus.ERROR, null, null);
>  	                 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
>  The constructor Status(int, Class<?>, String) is ambiguous
> 
> 
> Isn't this an incompatible change?

It is a source code compilation incompatible change, but not a binary incompatible change.  Methods get added all the time that introduce compile time ambiguity.  If you compile against a new version of a library this is always possible.  But your binary compiled against the old library will continue to work with a new version of the library.