Fix Generic Wildcards for Maven Publishing Repository #30
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
The Generic wildcard signatures for getPublishingMaven() and version are incorrect.
Remember the PECS shorthand from Effective Java... Producer Extends, Consumer Super. Paired with returning concrete types instead of wildcard types.
The Action passed to
versionconsumes a VersionSpec and since it consumes it, the wildcard should be super. Reason: An action that consumes an Object is compatible, an action that only consumes specific subclasses of VersionSpec is not compatible (but our current signature simply ignores that).The Action returned by
getPublishingMavencannot legally be used from Java code, since it's actually unknown what specific subtype of MavenRepository it supports. It has to either returnAction<? super MavenRepository>or preferrably return the concrete type it supports.This fixes this for consumers of the library:
Since this is clearly a bug for consumers of the library, take that into consideration for deciding whether this is a breaking change ;-)
Anyone passing an
Action<MySubclassOfVersionSpec>will already crash at runtime. And anyone respecting the Java type system cannot make use ofgetPublishingMaven.