Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update HttpRules API to not have varargs with generics #7687

Conversation

romain-grecourt
Copy link
Contributor

@romain-grecourt romain-grecourt commented Sep 28, 2023

Description

  • Update HttpService interface to not be a Supplier<HttpService> to remove ambiguity

  • Replace register(Supplier<? extends HttpService>... service) with register(HttpService... service)

  • Overload it with 5 variants to accept up to 5 suppliers of services (@SafeVarags is not usable on interfaces)

  • Add register(List<HttpService> services) for more than 5 services

  • Replace register(String pathPattern, Supplier<? extends HttpService>... service) with register(String pathPattern, HttpService... service)

  • Overload it with 5 variants to accept up to 5 suppliers of services (@SafeVarags is not usable on interfaces)

  • Add register(String pathPattern, List<HttpService> services) for more than 5 services

Fixes #7656

Documentation

The changes are mostly compile compatible.
It's incompatible if an application was using an array of suppliers explicitly or if it was using more than 5 suppliers.

I.e.

// the method with var-arg of supplier has been removed
rules.register((Supplier<HttpService>[]) svcs);
rules.register("/foo", (Supplier<HttpService>[]) svcs);

// the method with var-arg of supplier has been removed
// it is replaced with overloaded methods with up to 5 arguments
// using more than 5 won't compile
rules.register(Svc1::new, Svc2::new, Svc3::new, Svc4::new, Svc5::new, Svc6::new);
rules.register("/foo", Svc1::new, Svc2::new, Svc3::new, Svc4::new, Svc5::new, Svc6::new);

- Update HttpService interface to not be a Supplier<HttpService> to remove ambiguity

- Replace `register(Supplier<? extends HttpService>... service)` with register(HttpService... service)`
- Overload it with 5 variants to accept up to 5 suppliers of services (@SafeVarags is not usable on interfaces)
- Add `register(List<HttpService> services)` for more than 5 services

- Replace `register(String pathPattern, Supplier<? extends HttpService>... service)` with register(String pathPattern, HttpService... service)`
- Overload it with 5 variants to accept up to 5 suppliers of services (@SafeVarags is not usable on interfaces)
- Add `register(String pathPattern, List<HttpService> services)` for more than 5 services

Fixes helidon-io#7656
@romain-grecourt romain-grecourt added this to the 4.0.0-RC2 milestone Sep 28, 2023
@romain-grecourt romain-grecourt self-assigned this Sep 28, 2023
@oracle-contributor-agreement oracle-contributor-agreement bot added the OCA Verified All contributors have signed the Oracle Contributor Agreement. label Sep 28, 2023
@romain-grecourt
Copy link
Contributor Author

@tomas-langer I'm not sure if there is much value in exposing methods that take Supplier<HttpService> ; I used the pattern of List.of, Map.of, Set.of and overloaded the methods to simulate a var-arg with up to 5 arguments. We may decide to drop the convenience around Supplier and simply remove all of the overloads.

@romain-grecourt romain-grecourt merged commit d61541f into helidon-io:main Sep 29, 2023
12 checks passed
@romain-grecourt romain-grecourt deleted the http-rules-vararg-generic-array-fix branch September 29, 2023 09:35
dalexandrov pushed a commit to dalexandrov/helidon that referenced this pull request Oct 17, 2023
* Update HttpRules API to not have method with vararg with generics

- Update HttpService interface to not be a Supplier<HttpService> to remove ambiguity

- Replace `register(Supplier<? extends HttpService>... service)` with register(HttpService... service)`
- Overload it with 5 variants to accept up to 5 suppliers of services (@SafeVarags is not usable on interfaces)
- Add `register(List<HttpService> services)` for more than 5 services

- Replace `register(String pathPattern, Supplier<? extends HttpService>... service)` with register(String pathPattern, HttpService... service)`
- Overload it with 5 variants to accept up to 5 suppliers of services (@SafeVarags is not usable on interfaces)
- Add `register(String pathPattern, List<HttpService> services)` for more than 5 services

Fixes helidon-io#7656

* Fix javadoc references to the old  method `register(java.util.function.Supplier[])`
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
OCA Verified All contributors have signed the Oracle Contributor Agreement.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Pesky compiler warnings due to vararg generic arrays - Helidon 4.0.0-M2
2 participants