pjfanning opened a new pull request, #1380:
URL: https://github.com/apache/pekko-http/pull/1380
### Motivation
Java generics are invariant, so Java callers cannot pass collections or
optionals of subtypes to the Java API rejection factories. For example:
- `RouteResults.rejected(List.of(Rejections.method(HttpMethods.GET)))`: the
argument is a `List<MethodRejection>`
- `Rejections.unsupportedRequestContentType(List.of(MediaTypes.IMAGE_PNG),
Optional.of(ContentTypes.APPLICATION_JSON))`: the arguments are a
`List<MediaType.Binary>` and an `Optional<ContentType.WithFixedCharset>`
This is suggested PR 2 of #1378. It also covers the `Optional<ContentType>`
item that #1378 lists under "Smaller items", since it's on the same method.
### Modification
- `RouteResults.rejected`: `Iterable<? extends Rejection>`
- `Rejections.unsupportedRequestContentType` (both overloads): `Iterable<?
extends MediaType>`, plus `Optional<? extends ContentType>` on the two-argument
overload
- `Rejections.unsatisfiableRange`: `Iterable<? extends ByteRange>`. This one
matters less: the javadsl `ByteRange` factories return `ByteRange`, so only
callers holding scaladsl `ByteRange.Slice` etc. benefit. It's included for
consistency.
Where the existing code goes through `Util.convertIterable` (which takes an
invariant `Iterable<T>`), the wildcard `Iterable` is upcast first.
`java.lang.Iterable` is read-only, so this is safe. The other conversions
already go through `scala.jdk` converters with typed lambdas, and work
unchanged.
MiMa reports `IncompatibleSignatureProblem` for the 4 methods because the
generic signature changed. The erased JVM signatures are unchanged, so existing
compiled callers still link and existing Java sources still compile. The
excludes are in a new `java-iterable-rejection-wildcard.excludes`. None of
these are methods a user would override (`Rejections` and `RouteResults` are
objects).
No docs change: the methods behave the same, they just accept more argument
types.
### Result
Java callers can pass collections and optionals of subtypes to these
factories.
### Tests
- `sbt "http-tests/Test/testOnly
org.apache.pekko.http.javadsl.server.RejectionsTest"`: passed on Scala 2.13 and
3.3.8
- new `RejectionsTest` (Java): `RouteResults.rejected` with a
`List<MethodRejection>`; both `unsupportedRequestContentType` overloads with a
`List<MediaType.Binary>` and an `Optional<ContentType.WithFixedCharset>`;
`unsatisfiableRange` with a `List<scaladsl ByteRange.Slice>`. Each test checks
the values come through in the resulting rejection.
- all three tests fail to compile against the old signatures
- `sbt http/mimaReportBinaryIssues`: passed with the new excludes
- `sbt docs/Test/compile`: passed (`BasicDirectivesExamplesTest` calls
`RouteResults.rejected`)
- `http/scalafmtCheckAll`, `http-tests/Test/javafmtCheck` (JDK 17) and
header checks: passed
### References
Refs #1378
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]